Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #include <limits.h> | 1 #include <limits.h> |
| 2 #include "libm.h" | 2 #include "libm.h" |
| 3 | 3 |
| 4 int ilogbf(float x) | 4 int ilogbf(float x) |
| 5 { | 5 { |
| 6 » #pragma STDC FENV_ACCESS ON | 6 » PRAGMA_STDC_FENV_ACCESS_ON |
| 7 union {float f; uint32_t i;} u = {x}; | 7 union {float f; uint32_t i;} u = {x}; |
| 8 uint32_t i = u.i; | 8 uint32_t i = u.i; |
| 9 int e = i>>23 & 0xff; | 9 int e = i>>23 & 0xff; |
| 10 | 10 |
| 11 if (!e) { | 11 if (!e) { |
| 12 i <<= 9; | 12 i <<= 9; |
| 13 if (i == 0) { | 13 if (i == 0) { |
| 14 FORCE_EVAL(0/0.0f); | 14 FORCE_EVAL(0/0.0f); |
| 15 return FP_ILOGB0; | 15 return FP_ILOGB0; |
| 16 } | 16 } |
| 17 /* subnormal x */ | 17 /* subnormal x */ |
| 18 for (e = -0x7f; i>>31 == 0; e--, i<<=1); | 18 for (e = -0x7f; i>>31 == 0; e--, i<<=1); |
| 19 return e; | 19 return e; |
| 20 } | 20 } |
| 21 if (e == 0xff) { | 21 if (e == 0xff) { |
| 22 FORCE_EVAL(0/0.0f); | 22 FORCE_EVAL(0/0.0f); |
| 23 return i<<9 ? FP_ILOGBNAN : INT_MAX; | 23 return i<<9 ? FP_ILOGBNAN : INT_MAX; |
| 24 } | 24 } |
| 25 return e - 0x7f; | 25 return e - 0x7f; |
| 26 } | 26 } |
| OLD | NEW |