| 1 | #include <math.h> |
| 2 | #include <errno.h> |
| 3 | #include <limits.h> |
| 4 | #include <math_private.h> |
| 5 | #include <fenv.h> |
| 6 | |
| 7 | #if _GL_HAS_BUILTIN_ILOGB |
| 8 | int |
| 9 | M_DECL_FUNC (__ilogb) (FLOAT x) |
| 10 | { |
| 11 | int r; |
| 12 | /* Check for exceptional cases. */ |
| 13 | if (! M_SUF(__builtin_test_dc_ilogb) (x, 0x7f)) |
| 14 | r = M_SUF (__builtin_ilogb) (x); |
| 15 | else |
| 16 | /* Fallback to the generic ilogb if x is NaN, Inf or subnormal. */ |
| 17 | r = M_SUF (__ieee754_ilogb) (x); |
| 18 | if (__builtin_expect (r == FP_ILOGB0, 0) |
| 19 | || __builtin_expect (r == FP_ILOGBNAN, 0) |
| 20 | || __builtin_expect (r == INT_MAX, 0)) |
| 21 | { |
| 22 | __set_errno (EDOM); |
| 23 | __feraiseexcept (FE_INVALID); |
| 24 | } |
| 25 | return r; |
| 26 | } |
| 27 | declare_mgen_alias (__ilogb, ilogb) |
| 28 | #else |
| 29 | #include <math/w_ilogb_template.c> |
| 30 | #endif |
| 31 | |