code cleanup of named constants
[musl] / src / math / log10f.c
1 /* origin: FreeBSD /usr/src/lib/msun/src/e_log10f.c */
2 /*
3  * ====================================================
4  * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
5  *
6  * Developed at SunPro, a Sun Microsystems, Inc. business.
7  * Permission to use, copy, modify, and distribute this
8  * software is freely granted, provided that this notice
9  * is preserved.
10  * ====================================================
11  */
12 /*
13  * See comments in log10.c.
14  */
15
16 #include "libm.h"
17 #include "__log1pf.h"
18
19 static const float
20 two25     =  3.3554432000e+07, /* 0x4c000000 */
21 ivln10hi  =  4.3432617188e-01, /* 0x3ede6000 */
22 ivln10lo  = -3.1689971365e-05, /* 0xb804ead9 */
23 log10_2hi =  3.0102920532e-01, /* 0x3e9a2080 */
24 log10_2lo =  7.9034151668e-07; /* 0x355427db */
25
26 float log10f(float x)
27 {
28         float f,hfsq,hi,lo,r,y;
29         int32_t i,k,hx;
30
31         GET_FLOAT_WORD(hx, x);
32
33         k = 0;
34         if (hx < 0x00800000) {  /* x < 2**-126  */
35                 if ((hx&0x7fffffff) == 0)
36                         return -two25/0.0f;  /* log(+-0)=-inf */
37                 if (hx < 0)
38                         return (x-x)/0.0f;   /* log(-#) = NaN */
39                 /* subnormal number, scale up x */
40                 k -= 25;
41                 x *= two25;
42                 GET_FLOAT_WORD(hx, x);
43         }
44         if (hx >= 0x7f800000)
45                 return x+x;
46         if (hx == 0x3f800000)
47                 return 0.0f;  /* log(1) = +0 */
48         k += (hx>>23) - 127;
49         hx &= 0x007fffff;
50         i = (hx+(0x4afb0d))&0x800000;
51         SET_FLOAT_WORD(x, hx|(i^0x3f800000));  /* normalize x or x/2 */
52         k += i>>23;
53         y = (float)k;
54         f = x - 1.0f;
55         hfsq = 0.5f * f * f;
56         r = __log1pf(f);
57
58 // FIXME
59 //      /* See log2f.c and log2.c for details. */
60 //      if (sizeof(float_t) > sizeof(float))
61 //              return (r - hfsq + f) * ((float_t)ivln10lo + ivln10hi) +
62 //                  y * ((float_t)log10_2lo + log10_2hi);
63         hi = f - hfsq;
64         GET_FLOAT_WORD(hx, hi);
65         SET_FLOAT_WORD(hi, hx&0xfffff000);
66         lo = (f - hi) - hfsq + r;
67         return y*log10_2lo + (lo+hi)*ivln10lo + lo*ivln10hi +
68                 hi*ivln10hi + y*log10_2hi;
69 }