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

Split Close
Expand all
Collapse all
          --- old/usr/src/lib/libm/common/C/exp.c
          +++ new/usr/src/lib/libm/common/C/exp.c
↓ open down ↓ 10 lines elided ↑ open up ↑
  11   11   * and limitations under the License.
  12   12   *
  13   13   * When distributing Covered Code, include this CDDL HEADER in each
  14   14   * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15   15   * If applicable, add the following below this CDDL HEADER, with the
  16   16   * fields enclosed by brackets "[]" replaced with your own identifying
  17   17   * information: Portions Copyright [yyyy] [name of copyright owner]
  18   18   *
  19   19   * CDDL HEADER END
  20   20   */
       21 +
  21   22  /*
  22   23   * Copyright 2011 Nexenta Systems, Inc.  All rights reserved.
  23   24   */
       25 +
  24   26  /*
  25   27   * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
  26   28   * Use is subject to license terms.
  27   29   */
  28   30  
  29   31  #pragma weak __exp = exp
  30   32  
  31   33  /*
  32   34   * exp(x)
  33   35   * Hybrid algorithm of Peter Tang's Table driven method (for large
↓ open down ↓ 29 lines elided ↑ open up ↑
  63   65   *
  64   66   * Misc. info.
  65   67   *      For IEEE double
  66   68   *              if x >  7.09782712893383973096e+02 then exp(x) overflow
  67   69   *              if x < -7.45133219101941108420e+02 then exp(x) underflow
  68   70   */
  69   71  
  70   72  #include "libm.h"
  71   73  
  72   74  static const double TBL[] = {
  73      -        1.00000000000000000000e+00,  0.00000000000000000000e+00,
  74      -        1.02189714865411662714e+00,  5.10922502897344389359e-17,
  75      -        1.04427378242741375480e+00,  8.55188970553796365958e-17,
       75 +        1.00000000000000000000e+00, 0.00000000000000000000e+00,
       76 +        1.02189714865411662714e+00, 5.10922502897344389359e-17,
       77 +        1.04427378242741375480e+00, 8.55188970553796365958e-17,
  76   78          1.06714040067682369717e+00, -7.89985396684158212226e-17,
  77   79          1.09050773266525768967e+00, -3.04678207981247114697e-17,
  78      -        1.11438674259589243221e+00,  1.04102784568455709549e-16,
  79      -        1.13878863475669156458e+00,  8.91281267602540777782e-17,
  80      -        1.16372485877757747552e+00,  3.82920483692409349872e-17,
  81      -        1.18920711500272102690e+00,  3.98201523146564611098e-17,
       80 +        1.11438674259589243221e+00, 1.04102784568455709549e-16,
       81 +        1.13878863475669156458e+00, 8.91281267602540777782e-17,
       82 +        1.16372485877757747552e+00, 3.82920483692409349872e-17,
       83 +        1.18920711500272102690e+00, 3.98201523146564611098e-17,
  82   84          1.21524735998046895524e+00, -7.71263069268148813091e-17,
  83      -        1.24185781207348400201e+00,  4.65802759183693679123e-17,
  84      -        1.26905095719173321989e+00,  2.66793213134218609523e-18,
  85      -        1.29683955465100964055e+00,  2.53825027948883149593e-17,
       85 +        1.24185781207348400201e+00, 4.65802759183693679123e-17,
       86 +        1.26905095719173321989e+00, 2.66793213134218609523e-18,
       87 +        1.29683955465100964055e+00, 2.53825027948883149593e-17,
  86   88          1.32523664315974132322e+00, -2.85873121003886075697e-17,
  87      -        1.35425554693689265129e+00,  7.70094837980298946162e-17,
       89 +        1.35425554693689265129e+00, 7.70094837980298946162e-17,
  88   90          1.38390988196383202258e+00, -6.77051165879478628716e-17,
  89   91          1.41421356237309514547e+00, -9.66729331345291345105e-17,
  90   92          1.44518080697704665027e+00, -3.02375813499398731940e-17,
  91   93          1.47682614593949934623e+00, -3.48399455689279579579e-17,
  92   94          1.50916442759342284141e+00, -1.01645532775429503911e-16,
  93      -        1.54221082540794074411e+00,  7.94983480969762085616e-17,
       95 +        1.54221082540794074411e+00, 7.94983480969762085616e-17,
  94   96          1.57598084510788649659e+00, -1.01369164712783039808e-17,
  95      -        1.61049033194925428347e+00,  2.47071925697978878522e-17,
       97 +        1.61049033194925428347e+00, 2.47071925697978878522e-17,
  96   98          1.64575547815396494578e+00, -1.01256799136747726038e-16,
  97      -        1.68179283050742900407e+00,  8.19901002058149652013e-17,
       99 +        1.68179283050742900407e+00, 8.19901002058149652013e-17,
  98  100          1.71861929812247793414e+00, -1.85138041826311098821e-17,
  99      -        1.75625216037329945351e+00,  2.96014069544887330703e-17,
 100      -        1.79470907500310716820e+00,  1.82274584279120867698e-17,
 101      -        1.83400808640934243066e+00,  3.28310722424562658722e-17,
      101 +        1.75625216037329945351e+00, 2.96014069544887330703e-17,
      102 +        1.79470907500310716820e+00, 1.82274584279120867698e-17,
      103 +        1.83400808640934243066e+00, 3.28310722424562658722e-17,
 102  104          1.87416763411029996256e+00, -6.12276341300414256164e-17,
 103  105          1.91520656139714740007e+00, -1.06199460561959626376e-16,
 104      -        1.95714412417540017941e+00,  8.96076779103666776760e-17,
      106 +        1.95714412417540017941e+00, 8.96076779103666776760e-17,
 105  107  };
 106  108  
 107  109  /*
 108  110   * For i = 0, ..., 66,
 109  111   *   TBL2[2*i] is a double precision number near (i+1)*2^-6, and
 110  112   *   TBL2[2*i+1] = exp(TBL2[2*i]) to within a relative error less
 111  113   *   than 2^-60.
 112  114   *
 113  115   * For i = 67, ..., 133,
 114  116   *   TBL2[2*i] is a double precision number near -(i+1)*2^-6, and
↓ open down ↓ 141 lines elided ↑ open up ↑
 256  258          0.5,
 257  259          4.61662413084468283841e+01,     /* 0x40471547, 0x652b82fe */
 258  260          2.16608493865351192653e-02,     /* 0x3f962e42, 0xfee00000 */
 259  261          5.96317165397058656257e-12,     /* 0x3d9a39ef, 0x35793c76 */
 260  262          1.6666666666526086527e-1,       /* 3fc5555555548f7c */
 261  263          4.1666666666226079285e-2,       /* 3fa5555555545d4e */
 262  264          8.3333679843421958056e-3,       /* 3f811115b7aa905e */
 263  265          1.3888949086377719040e-3,       /* 3f56c1728d739765 */
 264  266          1.0,
 265  267          0.0,
 266      -        7.09782712893383973096e+02,     /* 0x40862E42, 0xFEFA39EF */
 267      -        7.45133219101941108420e+02,     /* 0x40874910, 0xD52D3051 */
 268      -        5.55111512312578270212e-17,     /* 0x3c900000, 0x00000000 */
      268 +        7.09782712893383973096e+02, /* 0x40862E42, 0xFEFA39EF */
      269 +        7.45133219101941108420e+02, /* 0x40874910, 0xD52D3051 */
      270 +        5.55111512312578270212e-17, /* 0x3c900000, 0x00000000 */
 269  271  };
 270  272  
 271      -#define half            C[0]
 272      -#define invln2_32       C[1]
 273      -#define ln2_32hi        C[2]
 274      -#define ln2_32lo        C[3]
 275      -#define t2              C[4]
 276      -#define t3              C[5]
 277      -#define t4              C[6]
 278      -#define t5              C[7]
 279      -#define one             C[8]
 280      -#define zero            C[9]
 281      -#define threshold1      C[10]
 282      -#define threshold2      C[11]
 283      -#define twom54          C[12]
      273 +#define half                    C[0]
      274 +#define invln2_32               C[1]
      275 +#define ln2_32hi                C[2]
      276 +#define ln2_32lo                C[3]
      277 +#define t2                      C[4]
      278 +#define t3                      C[5]
      279 +#define t4                      C[6]
      280 +#define t5                      C[7]
      281 +#define one                     C[8]
      282 +#define zero                    C[9]
      283 +#define threshold1              C[10]
      284 +#define threshold2              C[11]
      285 +#define twom54                  C[12]
 284  286  
 285  287  double
 286      -exp(double x) {
 287      -        double  y, z, t;
 288      -        int     hx, ix, k, j, m;
      288 +exp(double x)
      289 +{
      290 +        double y, z, t;
      291 +        int hx, ix, k, j, m;
 289  292  
 290  293          ix = ((int *)&x)[HIWORD];
 291  294          hx = ix & ~0x80000000;
 292  295  
 293      -        if (hx < 0x3ff0a2b2) {  /* |x| < 3/2 ln 2 */
 294      -                if (hx < 0x3f862e42) {  /* |x| < 1/64 ln 2 */
      296 +        if (hx < 0x3ff0a2b2) {                  /* |x| < 3/2 ln 2 */
      297 +                if (hx < 0x3f862e42) {          /* |x| < 1/64 ln 2 */
 295  298                          if (hx < 0x3ed00000) {  /* |x| < 2^-18 */
 296  299                                  volatile int dummy __unused;
 297  300  
 298  301                                  dummy = (int)x; /* raise inexact if x != 0 */
 299  302  #ifdef lint
 300  303                                  dummy = dummy;
 301  304  #endif
      305 +
 302  306                                  if (hx < 0x3e300000)
 303  307                                          return (one + x);
      308 +
 304  309                                  return (one + x * (one + half * x));
 305  310                          }
      311 +
 306  312                          t = x * x;
 307      -                        y = x + (t * (half + x * t2) +
 308      -                            (t * t) * (t3 + x * t4 + t * t5));
      313 +                        y = x + (t * (half + x * t2) + (t * t) * (t3 + x * t4 +
      314 +                            t * t5));
 309  315                          return (one + y);
 310  316                  }
 311  317  
 312  318                  /* find the multiple of 2^-6 nearest x */
 313  319                  k = hx >> 20;
 314  320                  j = (0x00100000 | (hx & 0x000fffff)) >> (0x40c - k);
 315  321                  j = (j - 1) & ~1;
      322 +
 316  323                  if (ix < 0)
 317  324                          j += 134;
      325 +
 318  326                  z = x - TBL2[j];
 319  327                  t = z * z;
 320      -                y = z + (t * (half + z * t2) +
 321      -                    (t * t) * (t3 + z * t4 + t * t5));
 322      -                return (TBL2[j+1] + TBL2[j+1] * y);
      328 +                y = z + (t * (half + z * t2) + (t * t) * (t3 + z * t4 + t *
      329 +                    t5));
      330 +                return (TBL2[j + 1] + TBL2[j + 1] * y);
 323  331          }
 324  332  
 325      -        if (hx >= 0x40862e42) { /* x is large, infinite, or nan */
      333 +        if (hx >= 0x40862e42) {         /* x is large, infinite, or nan */
 326  334                  if (hx >= 0x7ff00000) {
 327  335                          if (ix == 0xfff00000 && ((int *)&x)[LOWORD] == 0)
 328  336                                  return (zero);
      337 +
 329  338                          return (x * x);
 330  339                  }
      340 +
 331  341                  if (x > threshold1)
 332  342                          return (_SVID_libm_err(x, x, 6));
      343 +
 333  344                  if (-x > threshold2)
 334  345                          return (_SVID_libm_err(x, x, 7));
 335  346          }
 336  347  
 337  348          t = invln2_32 * x;
      349 +
 338  350          if (ix < 0)
 339  351                  t -= half;
 340  352          else
 341  353                  t += half;
      354 +
 342  355          k = (int)t;
 343  356          j = (k & 0x1f) << 1;
 344  357          m = k >> 5;
 345  358          z = (x - k * ln2_32hi) - k * ln2_32lo;
 346  359  
 347  360          /* z is now in primary range */
 348  361          t = z * z;
 349  362          y = z + (t * (half + z * t2) + (t * t) * (t3 + z * t4 + t * t5));
 350      -        y = TBL[j] + (TBL[j+1] + TBL[j] * y);
      363 +        y = TBL[j] + (TBL[j + 1] + TBL[j] * y);
      364 +
 351  365          if (m < -1021) {
 352  366                  ((int *)&y)[HIWORD] += (m + 54) << 20;
 353  367                  return (twom54 * y);
 354  368          }
      369 +
 355  370          ((int *)&y)[HIWORD] += m << 20;
 356  371          return (y);
 357  372  }
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX