use #if LDBL_MANT_DIG == ... instead of custom LD80 etc macros
[libm] / src / math / logb.c
1 #include <limits.h>
2 #include "libm.h"
3
4 /*
5 special cases:
6         logb(+-0) = -inf
7         logb(+-inf) = +inf
8         logb(nan) = nan
9 these are calculated at runtime to raise fp exceptions
10 */
11
12 double logb(double x) {
13         int i = ilogb(x);
14
15         if (i == FP_ILOGB0)
16                 return -1.0/fabs(x);
17         if (i == FP_ILOGBNAN || i == INT_MAX)
18                 return x * x;
19         return i;
20 }