Print this page




 106 /* Lp4 */       2.222219843214978396e-01,       /* 3FCC71C5 1D8E78AF */
 107 /* Lp5 */       1.818357216161805012e-01,       /* 3FC74664 96CB03DE */
 108 /* Lp6 */       1.531383769920937332e-01,       /* 3FC39A09 D078C69F */
 109 /* Lp7 */       1.479819860511658591e-01,       /* 3FC2F112 DF3E5244 */
 110 /* zero */      0.0
 111 };
 112 #define ln2_hi  xxx[0]
 113 #define ln2_lo  xxx[1]
 114 #define two54   xxx[2]
 115 #define Lp1     xxx[3]
 116 #define Lp2     xxx[4]
 117 #define Lp3     xxx[5]
 118 #define Lp4     xxx[6]
 119 #define Lp5     xxx[7]
 120 #define Lp6     xxx[8]
 121 #define Lp7     xxx[9]
 122 #define zero    xxx[10]
 123 
 124 double
 125 log1p(double x) {
 126         double  hfsq, f, c, s, z, R, u;
 127         int     k, hx, hu, ax;
 128 
 129         hx = ((int *)&x)[HIWORD];           /* high word of x */
 130         ax = hx & 0x7fffffff;
 131 
 132         if (ax >= 0x7ff00000) { /* x is inf or nan */
 133                 if (((hx - 0xfff00000) | ((int *)&x)[LOWORD]) == 0) /* -inf */
 134                         return (_SVID_libm_err(x, x, 44));
 135                 return (x * x);
 136         }
 137 
 138         k = 1;
 139         if (hx < 0x3FDA827A) {       /* x < 0.41422  */
 140                 if (ax >= 0x3ff00000)        /* x <= -1.0 */
 141                         return (_SVID_libm_err(x, x, x == -1.0 ? 43 : 44));
 142                 if (ax < 0x3e200000) {       /* |x| < 2**-29 */
 143                         if (two54 + x > zero &&      /* raise inexact */
 144                             ax < 0x3c900000) /* |x| < 2**-54 */
 145                                 return (x);
 146                         else
 147                                 return (x - x * x * 0.5);
 148                 }
 149                 if (hx > 0 || hx <= (int)0xbfd2bec3) {    /* -0.2929<x<0.41422 */
 150                         k = 0;
 151                         f = x;
 152                         hu = 1;
 153                 }
 154         }

 155         if (k != 0) {
 156                 if (hx < 0x43400000) {
 157                         u = 1.0 + x;
 158                         hu = ((int *)&u)[HIWORD];   /* high word of u */
 159                         k = (hu >> 20) - 1023;
 160                         /*
 161                          * correction term
 162                          */
 163                         c = k > 0 ? 1.0 - (u - x) : x - (u - 1.0);
 164                         c /= u;
 165                 } else {
 166                         u = x;
 167                         hu = ((int *)&u)[HIWORD];   /* high word of u */
 168                         k = (hu >> 20) - 1023;
 169                         c = 0;
 170                 }
 171                 hu &= 0x000fffff;
 172                 if (hu < 0x6a09e) {  /* normalize u */
 173                         ((int *)&u)[HIWORD] = hu | 0x3ff00000;
 174                 } else {                        /* normalize u/2 */
 175                         k += 1;
 176                         ((int *)&u)[HIWORD] = hu | 0x3fe00000;
 177                         hu = (0x00100000 - hu) >> 2;
 178                 }
 179                 f = u - 1.0;
 180         }
 181         hfsq = 0.5 * f * f;
 182         if (hu == 0) {          /* |f| < 2**-20 */
 183                 if (f == zero) {
 184                         if (k == 0)
 185                                 return (zero);

 186                         c += k * ln2_lo;
 187                         return (k * ln2_hi + c);
 188                 }
 189                 R = hfsq * (1.0 - 0.66666666666666666 * f);
 190                 if (k == 0)
 191                         return (f - R);
 192                 return (k * ln2_hi - ((R - (k * ln2_lo + c)) - f));
 193         }
 194         s = f / (2.0 + f);
 195         z = s * s;
 196         R = z * (Lp1 + z * (Lp2 + z * (Lp3 + z * (Lp4 + z * (Lp5 +
 197                 z * (Lp6 + z * Lp7))))));
 198         if (k == 0)
 199                 return (f - (hfsq - s * (hfsq + R)));
 200         return (k * ln2_hi - ((hfsq - (s * (hfsq + R) +
 201                 (k * ln2_lo + c))) - f));
 202 }


 106 /* Lp4 */       2.222219843214978396e-01,       /* 3FCC71C5 1D8E78AF */
 107 /* Lp5 */       1.818357216161805012e-01,       /* 3FC74664 96CB03DE */
 108 /* Lp6 */       1.531383769920937332e-01,       /* 3FC39A09 D078C69F */
 109 /* Lp7 */       1.479819860511658591e-01,       /* 3FC2F112 DF3E5244 */
 110 /* zero */      0.0
 111 };
 112 #define ln2_hi  xxx[0]
 113 #define ln2_lo  xxx[1]
 114 #define two54   xxx[2]
 115 #define Lp1     xxx[3]
 116 #define Lp2     xxx[4]
 117 #define Lp3     xxx[5]
 118 #define Lp4     xxx[6]
 119 #define Lp5     xxx[7]
 120 #define Lp6     xxx[8]
 121 #define Lp7     xxx[9]
 122 #define zero    xxx[10]
 123 
 124 double
 125 log1p(double x) {
 126         double  hfsq, f, c = 0.0, s, z, R, u;
 127         int     k, hx, hu, ax;
 128 
 129         hx = ((int *)&x)[HIWORD];           /* high word of x */
 130         ax = hx & 0x7fffffff;
 131 
 132         if (ax >= 0x7ff00000) { /* x is inf or nan */
 133                 if (((hx - 0xfff00000) | ((int *)&x)[LOWORD]) == 0) /* -inf */
 134                         return (_SVID_libm_err(x, x, 44));
 135                 return (x * x);
 136         }
 137 
 138         k = 1;
 139         if (hx < 0x3FDA827A) {       /* x < 0.41422  */
 140                 if (ax >= 0x3ff00000)        /* x <= -1.0 */
 141                         return (_SVID_libm_err(x, x, x == -1.0 ? 43 : 44));
 142                 if (ax < 0x3e200000) {       /* |x| < 2**-29 */
 143                         if (two54 + x > zero &&      /* raise inexact */
 144                             ax < 0x3c900000) /* |x| < 2**-54 */
 145                                 return (x);
 146                         else
 147                                 return (x - x * x * 0.5);
 148                 }
 149                 if (hx > 0 || hx <= (int)0xbfd2bec3) {    /* -0.2929<x<0.41422 */
 150                         k = 0;
 151                         f = x;
 152                         hu = 1;
 153                 }
 154         }
 155         /* We will initialize 'c' here. */
 156         if (k != 0) {
 157                 if (hx < 0x43400000) {
 158                         u = 1.0 + x;
 159                         hu = ((int *)&u)[HIWORD];   /* high word of u */
 160                         k = (hu >> 20) - 1023;
 161                         /*
 162                          * correction term
 163                          */
 164                         c = k > 0 ? 1.0 - (u - x) : x - (u - 1.0);
 165                         c /= u;
 166                 } else {
 167                         u = x;
 168                         hu = ((int *)&u)[HIWORD];   /* high word of u */
 169                         k = (hu >> 20) - 1023;
 170                         c = 0;
 171                 }
 172                 hu &= 0x000fffff;
 173                 if (hu < 0x6a09e) {  /* normalize u */
 174                         ((int *)&u)[HIWORD] = hu | 0x3ff00000;
 175                 } else {                        /* normalize u/2 */
 176                         k += 1;
 177                         ((int *)&u)[HIWORD] = hu | 0x3fe00000;
 178                         hu = (0x00100000 - hu) >> 2;
 179                 }
 180                 f = u - 1.0;
 181         }
 182         hfsq = 0.5 * f * f;
 183         if (hu == 0) {          /* |f| < 2**-20 */
 184                 if (f == zero) {
 185                         if (k == 0)
 186                                 return (zero);
 187                         /* We already initialized 'c' before, when (k != 0) */
 188                         c += k * ln2_lo;
 189                         return (k * ln2_hi + c);
 190                 }
 191                 R = hfsq * (1.0 - 0.66666666666666666 * f);
 192                 if (k == 0)
 193                         return (f - R);
 194                 return (k * ln2_hi - ((R - (k * ln2_lo + c)) - f));
 195         }
 196         s = f / (2.0 + f);
 197         z = s * s;
 198         R = z * (Lp1 + z * (Lp2 + z * (Lp3 + z * (Lp4 + z * (Lp5 +
 199                 z * (Lp6 + z * Lp7))))));
 200         if (k == 0)
 201                 return (f - (hfsq - s * (hfsq + R)));
 202         return (k * ln2_hi - ((hfsq - (s * (hfsq + R) +
 203                 (k * ln2_lo + c))) - f));
 204 }