Print this page
11210 libm should be cstyle(1ONBLD) clean

*** 20,37 **** */ /* * Copyright 2011 Nexenta Systems, Inc. All rights reserved. */ /* * Copyright 2006 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ #pragma weak __log2 = log2 ! /* INDENT OFF */ /* * log2(x) = log(x)/log2 * * Base on Table look-up algorithm with product polynomial * approximation for log(x). --- 20,38 ---- */ /* * Copyright 2011 Nexenta Systems, Inc. All rights reserved. */ + /* * Copyright 2006 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ #pragma weak __log2 = log2 ! /* * log2(x) = log(x)/log2 * * Base on Table look-up algorithm with product polynomial * approximation for log(x).
*** 83,101 **** * The hexadecimal values are the intended ones for the following constants. * The decimal values may be used, provided that the compiler will convert * from decimal to binary accurately enough to produce the hexadecimal values * shown. */ - /* INDENT ON */ #include "libm.h" #include "libm_protos.h" extern const double _TBL_log[]; static const double P[] = { ! /* ONE */ 1.0, /* TWO52 */ 4503599627370496.0, /* LN10V */ 1.4426950408889634073599246810018920433347, /* 1/log10 */ /* ZERO */ 0.0, /* A1 */ -9.6809362455249638217841932228967194640116e-02, /* A2 */ 1.99628461483039965074226529395673424005508422852e+0000, --- 84,102 ---- * The hexadecimal values are the intended ones for the following constants. * The decimal values may be used, provided that the compiler will convert * from decimal to binary accurately enough to produce the hexadecimal values * shown. */ #include "libm.h" #include "libm_protos.h" extern const double _TBL_log[]; static const double P[] = { ! /* ONE */ ! 1.0, /* TWO52 */ 4503599627370496.0, /* LN10V */ 1.4426950408889634073599246810018920433347, /* 1/log10 */ /* ZERO */ 0.0, /* A1 */ -9.6809362455249638217841932228967194640116e-02, /* A2 */ 1.99628461483039965074226529395673424005508422852e+0000,
*** 147,226 **** #define B8 P[23] #define LGH P[24] #define LGL P[25] double ! log2(double x) { int i, hx, ix, n, lx; n = 0; ! hx = ((int *) &x)[HIWORD]; ix = hx & 0x7fffffff; ! lx = ((int *) &x)[LOWORD]; /* subnormal,0,negative,inf,nan */ if ((hx + 0x100000) < 0x200000) { #if defined(FPADD_TRAPS_INCOMPLETE_ON_NAN) if (ix >= 0x7ff80000) /* assumes sparc-like QNaN */ return (x); /* for Cheetah when x is QNaN */ #endif if (((hx << 1) | lx) == 0) /* log(0.0) = -inf */ return (A5 / fabs(x)); if (hx < 0) { /* x < 0 */ if (ix >= 0x7ff00000) return (x - x); /* x is -inf or NaN */ else return (ZERO / (x - x)); } if (((hx - 0x7ff00000) | lx) == 0) /* log(inf) = inf */ return (x); if (ix >= 0x7ff00000) /* log(NaN) = NaN */ return (x - x); x *= TWO52; n = -52; ! hx = ((int *) &x)[HIWORD]; ix = hx & 0x7fffffff; ! lx = ((int *) &x)[LOWORD]; } /* 0.09375 (0x3fb80000) <= x < 24 (0x40380000) */ i = ix >> 19; if (i >= 0x7f7 && i <= 0x806) { /* 0.875 <= x < 1.125 */ if (ix >= 0x3fec0000 && ix < 0x3ff20000) { double s, z, r, w; ! s = x - ONE; z = s * s; r = (A10 * s) * (A11 + s); w = z * s; ! if (((ix << 12) | lx) == 0) return (z); ! else ! return (LGH * s - (LGL * s - ((A1 * z) * ! ((A2 + (A3 * s) * (A4 + s)) + w * (A5 + s))) * (((A6 + s * (A7 + s)) + w * (A8 + s)) * ((A9 + r) + w * (A12 + s))))); } else { double *tb, s; i = (ix - 0x3fb80000) >> 15; ! tb = (double *) _TBL_log + (i + i + i); if (((ix << 12) | lx) == 0) /* 2's power */ ! return ((double) ((ix >> 20) - 0x3ff)); s = (x - tb[0]) * tb[1]; return (LGH * tb[2] - (LGL * tb[2] - ((B1 * s) * ! (B2 + s * (B3 + s))) * ! (((B4 + s * B5) + (s * s) * (B6 + s)) * ! (B7 + s * (B8 + s))))); } } else { double *tb, dn, s; ! dn = (double) (n + ((ix >> 20) - 0x3ff)); ix <<= 12; if ((ix | lx) == 0) return (dn); ! i = ((unsigned) ix >> 12) | 0x3ff00000; /* scale x to [1,2) */ ! ((int *) &x)[HIWORD] = i; i = (i - 0x3fb80000) >> 15; ! tb = (double *) _TBL_log + (i + i + i); s = (x - tb[0]) * tb[1]; ! return (dn + (tb[2] * LN10V + ((B1 * s) * ! (B2 + s * (B3 + s))) * (((B4 + s * B5) + (s * s) * (B6 + s)) * (B7 + s * (B8 + s))))); } } --- 148,245 ---- #define B8 P[23] #define LGH P[24] #define LGL P[25] double ! log2(double x) ! { int i, hx, ix, n, lx; n = 0; ! hx = ((int *)&x)[HIWORD]; ! ix = hx & 0x7fffffff; ! lx = ((int *)&x)[LOWORD]; /* subnormal,0,negative,inf,nan */ if ((hx + 0x100000) < 0x200000) { #if defined(FPADD_TRAPS_INCOMPLETE_ON_NAN) if (ix >= 0x7ff80000) /* assumes sparc-like QNaN */ return (x); /* for Cheetah when x is QNaN */ #endif + if (((hx << 1) | lx) == 0) /* log(0.0) = -inf */ return (A5 / fabs(x)); + if (hx < 0) { /* x < 0 */ if (ix >= 0x7ff00000) return (x - x); /* x is -inf or NaN */ else return (ZERO / (x - x)); } + if (((hx - 0x7ff00000) | lx) == 0) /* log(inf) = inf */ return (x); + if (ix >= 0x7ff00000) /* log(NaN) = NaN */ return (x - x); + x *= TWO52; n = -52; ! hx = ((int *)&x)[HIWORD]; ! ix = hx & 0x7fffffff; ! lx = ((int *)&x)[LOWORD]; } /* 0.09375 (0x3fb80000) <= x < 24 (0x40380000) */ i = ix >> 19; + if (i >= 0x7f7 && i <= 0x806) { /* 0.875 <= x < 1.125 */ if (ix >= 0x3fec0000 && ix < 0x3ff20000) { double s, z, r, w; ! ! s = x - ONE; ! z = s * s; ! r = (A10 * s) * (A11 + s); w = z * s; ! ! if (((ix << 12) | lx) == 0) { return (z); ! } else { ! return (LGH * s - (LGL * s - ((A1 * z) * ((A2 + ! (A3 * s) * (A4 + s)) + w * (A5 + s))) * (((A6 + s * (A7 + s)) + w * (A8 + s)) * ((A9 + r) + w * (A12 + s))))); + } } else { double *tb, s; + i = (ix - 0x3fb80000) >> 15; ! tb = (double *)_TBL_log + (i + i + i); ! if (((ix << 12) | lx) == 0) /* 2's power */ ! return ((double)((ix >> 20) - 0x3ff)); ! s = (x - tb[0]) * tb[1]; return (LGH * tb[2] - (LGL * tb[2] - ((B1 * s) * ! (B2 + s * (B3 + s))) * (((B4 + s * B5) + (s * s) * ! (B6 + s)) * (B7 + s * (B8 + s))))); } } else { double *tb, dn, s; ! ! dn = (double)(n + ((ix >> 20) - 0x3ff)); ix <<= 12; + if ((ix | lx) == 0) return (dn); ! ! i = ((unsigned)ix >> 12) | 0x3ff00000; /* scale x to [1,2) */ ! ((int *)&x)[HIWORD] = i; i = (i - 0x3fb80000) >> 15; ! tb = (double *)_TBL_log + (i + i + i); s = (x - tb[0]) * tb[1]; ! return (dn + (tb[2] * LN10V + ((B1 * s) * (B2 + s * (B3 + s))) * (((B4 + s * B5) + (s * s) * (B6 + s)) * (B7 + s * (B8 + s))))); } }