Rich Felker | b69f695 | 2012-03-13 01:17:53 -0400 | [diff] [blame] | 1 | #include <limits.h> |
| 2 | #include "libm.h" |
| 3 | |
| 4 | #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 |
| 5 | int ilogbl(long double x) |
| 6 | { |
| 7 | return ilogb(x); |
| 8 | } |
| 9 | #elif LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384 |
| 10 | int ilogbl(long double x) |
| 11 | { |
Szabolcs Nagy | 4cec31f | 2013-09-02 23:33:20 +0000 | [diff] [blame] | 12 | #pragma STDC FENV_ACCESS ON |
Rich Felker | b69f695 | 2012-03-13 01:17:53 -0400 | [diff] [blame] | 13 | union ldshape u = {x}; |
Szabolcs Nagy | af5f6d9 | 2013-09-02 00:38:51 +0000 | [diff] [blame] | 14 | uint64_t m = u.i.m; |
| 15 | int e = u.i.se & 0x7fff; |
Rich Felker | b69f695 | 2012-03-13 01:17:53 -0400 | [diff] [blame] | 16 | |
| 17 | if (!e) { |
Szabolcs Nagy | be81f51 | 2012-11-12 23:58:18 +0100 | [diff] [blame] | 18 | if (m == 0) { |
Szabolcs Nagy | 4cec31f | 2013-09-02 23:33:20 +0000 | [diff] [blame] | 19 | FORCE_EVAL(0/0.0f); |
Rich Felker | b69f695 | 2012-03-13 01:17:53 -0400 | [diff] [blame] | 20 | return FP_ILOGB0; |
Szabolcs Nagy | be81f51 | 2012-11-12 23:58:18 +0100 | [diff] [blame] | 21 | } |
Rich Felker | b69f695 | 2012-03-13 01:17:53 -0400 | [diff] [blame] | 22 | /* subnormal x */ |
Szabolcs Nagy | 4cec31f | 2013-09-02 23:33:20 +0000 | [diff] [blame] | 23 | for (e = -0x3fff+1; m>>63 == 0; e--, m<<=1); |
Rich Felker | b69f695 | 2012-03-13 01:17:53 -0400 | [diff] [blame] | 24 | return e; |
| 25 | } |
Szabolcs Nagy | be81f51 | 2012-11-12 23:58:18 +0100 | [diff] [blame] | 26 | if (e == 0x7fff) { |
| 27 | FORCE_EVAL(0/0.0f); |
Szabolcs Nagy | 4cec31f | 2013-09-02 23:33:20 +0000 | [diff] [blame] | 28 | return m<<1 ? FP_ILOGBNAN : INT_MAX; |
| 29 | } |
| 30 | return e - 0x3fff; |
| 31 | } |
| 32 | #elif LDBL_MANT_DIG == 113 && LDBL_MAX_EXP == 16384 |
| 33 | int ilogbl(long double x) |
| 34 | { |
| 35 | #pragma STDC FENV_ACCESS ON |
| 36 | union ldshape u = {x}; |
| 37 | int e = u.i.se & 0x7fff; |
| 38 | |
| 39 | if (!e) { |
| 40 | if (x == 0) { |
| 41 | FORCE_EVAL(0/0.0f); |
| 42 | return FP_ILOGB0; |
| 43 | } |
| 44 | /* subnormal x */ |
| 45 | x *= 0x1p120; |
| 46 | return ilogbl(x) - 120; |
| 47 | } |
| 48 | if (e == 0x7fff) { |
| 49 | FORCE_EVAL(0/0.0f); |
| 50 | u.i.se = 0; |
| 51 | return u.f ? FP_ILOGBNAN : INT_MAX; |
Szabolcs Nagy | be81f51 | 2012-11-12 23:58:18 +0100 | [diff] [blame] | 52 | } |
Rich Felker | b69f695 | 2012-03-13 01:17:53 -0400 | [diff] [blame] | 53 | return e - 0x3fff; |
| 54 | } |
| 55 | #endif |