Print this page
    
5262 libm needs to be carefully unifdef'd
5268 libm doesn't need to hide symbols which are already local
    
      
        | Split | 
	Close | 
      
      | Expand all | 
      | Collapse all | 
    
    
          --- old/usr/src/lib/libm/common/Q/expm1l.c
          +++ new/usr/src/lib/libm/common/Q/expm1l.c
   1    1  /*
   2    2   * CDDL HEADER START
   3    3   *
   4    4   * The contents of this file are subject to the terms of the
   5    5   * Common Development and Distribution License (the "License").
   6    6   * You may not use this file except in compliance with the License.
   7    7   *
   8    8   * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9    9   * or http://www.opensolaris.org/os/licensing.
  10   10   * See the License for the specific language governing permissions
  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
  
    | 
      ↓ open down ↓ | 
    19 lines elided | 
    
      ↑ open up ↑ | 
  
  20   20   */
  21   21  
  22   22  /*
  23   23   * Copyright 2011 Nexenta Systems, Inc.  All rights reserved.
  24   24   */
  25   25  /*
  26   26   * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
  27   27   * Use is subject to license terms.
  28   28   */
  29   29  
  30      -#if defined(ELFOBJ)
  31   30  #pragma weak expm1l = __expm1l
  32      -#endif
  33   31  #if !defined(__sparc)
  34   32  #error Unsupported architecture
  35   33  #endif
  36   34  
  37   35  /*
  38   36   * expm1l(x)
  39   37   *
  40   38   * Table driven method
  41   39   * Written by K.C. Ng, June 1995.
  42   40   * Algorithm :
  43   41   *      1. expm1(x) = x if x<2**-114
  44   42   *      2. if |x| <= 0.0625 = 1/16, use approximation
  45   43   *              expm1(x) = x + x*P/(2-P)
  46   44   * where
  47   45   *      P = x - z*(P1+z*(P2+z*(P3+z*(P4+z*(P5+z*P6+z*P7))))), z = x*x;
  48   46   * (this formula is derived from
  49   47   *      2-P+x = R = x*(exp(x)+1)/(exp(x)-1) ~ 2 + x*x/6 - x^4/360 + ...)
  50   48   *
  51   49   * P1 =   1.66666666666666666666666666666638500528074603030e-0001
  52   50   * P2 =  -2.77777777777777777777777759668391122822266551158e-0003
  53   51   * P3 =   6.61375661375661375657437408890138814721051293054e-0005
  54   52   * P4 =  -1.65343915343915303310185228411892601606669528828e-0006
  55   53   * P5 =   4.17535139755122945763580609663414647067443411178e-0008
  56   54   * P6 =  -1.05683795988668526689182102605260986731620026832e-0009
  57   55   * P7 =   2.67544168821852702827123344217198187229611470514e-0011
  58   56   *
  59   57   * Accuracy: |R-x*(exp(x)+1)/(exp(x)-1)|<=2**-119.13
  60   58   *
  61   59   *      3. For 1/16 < |x| < 1.125, choose x(+-i) ~ +-(i+4.5)/64, i=0,..,67
  62   60   *         since
  63   61   *              exp(x) = exp(xi+(x-xi))= exp(xi)*exp((x-xi))
  64   62   *         we have
  65   63   *              expm1(x) = expm1(xi)+(exp(xi))*(expm1(x-xi))
  66   64   *         where
  67   65   *              |s=x-xi| <= 1/128
  68   66   *         and
  69   67   *      expm1(s)=2s/(2-R), R= s-s^2*(T1+s^2*(T2+s^2*(T3+s^2*(T4+s^2*T5))))
  70   68   *
  71   69   * T1 =   1.666666666666666666666666666660876387437e-1L,
  72   70   * T2 =  -2.777777777777777777777707812093173478756e-3L,
  73   71   * T3 =   6.613756613756613482074280932874221202424e-5L,
  74   72   * T4 =  -1.653439153392139954169609822742235851120e-6L,
  75   73   * T5 =   4.175314851769539751387852116610973796053e-8L;
  76   74   *
  77   75   *      4. For |x| >= 1.125, return exp(x)-1.
  78   76   *          (see algorithm for exp)
  79   77   *
  80   78   * Special cases:
  81   79   *      expm1l(INF) is INF, expm1l(NaN) is NaN;
  82   80   *      expm1l(-INF)= -1;
  83   81   *      for finite argument, only expm1l(0)=0 is exact.
  84   82   *
  85   83   * Accuracy:
  86   84   *      according to an error analysis, the error is always less than
  87   85   *      2 ulp (unit in the last place).
  88   86   *
  89   87   * Misc. info.
  90   88   *      For 113 bit long double
  91   89   *              if x >  1.135652340629414394949193107797076342845e+4
  92   90   *      then expm1l(x) overflow;
  93   91   *
  94   92   * Constants:
  95   93   * Only decimal values are given. We assume that the compiler will convert
  96   94   * from decimal to binary accurately enough to produce the correct
  97   95   * hexadecimal values.
  98   96   */
  99   97  
 100   98  #include "libm.h"
 101   99  
 102  100  extern const long double _TBL_expl_hi[], _TBL_expl_lo[];
 103  101  extern const long double _TBL_expm1lx[], _TBL_expm1l[];
 104  102  
 105  103  static const long double
 106  104          zero            = +0.0L,
 107  105          one             = +1.0L,
 108  106          two             = +2.0L,
 109  107          ln2_64          = +1.083042469624914545964425189778400898568e-2L,
 110  108          ovflthreshold   = +1.135652340629414394949193107797076342845e+4L,
 111  109          invln2_32       = +4.616624130844682903551758979206054839765e+1L,
 112  110          ln2_32hi        = +2.166084939249829091928849858592451515688e-2L,
 113  111          ln2_32lo        = +5.209643502595475652782654157501186731779e-27L,
 114  112          huge            = +1.0e4000L,
 115  113          tiny            = +1.0e-4000L,
 116  114          P1 = +1.66666666666666666666666666666638500528074603030e-0001L,
 117  115          P2 = -2.77777777777777777777777759668391122822266551158e-0003L,
 118  116          P3 = +6.61375661375661375657437408890138814721051293054e-0005L,
 119  117          P4 = -1.65343915343915303310185228411892601606669528828e-0006L,
 120  118          P5 = +4.17535139755122945763580609663414647067443411178e-0008L,
 121  119          P6 = -1.05683795988668526689182102605260986731620026832e-0009L,
 122  120          P7 = +2.67544168821852702827123344217198187229611470514e-0011L,
 123  121  /* rational approximation coeffs for [-(ln2)/64,(ln2)/64] */
 124  122          T1 = +1.666666666666666666666666666660876387437e-1L,
 125  123          T2 = -2.777777777777777777777707812093173478756e-3L,
 126  124          T3 = +6.613756613756613482074280932874221202424e-5L,
 127  125          T4 = -1.653439153392139954169609822742235851120e-6L,
 128  126          T5 = +4.175314851769539751387852116610973796053e-8L;
 129  127  
 130  128  long double
 131  129  expm1l(long double x) {
 132  130          int hx, ix, j, k, m;
 133  131          long double t, r, s, w;
 134  132  
 135  133          hx = ((int *) &x)[HIXWORD];
 136  134          ix = hx & ~0x80000000;
 137  135          if (ix >= 0x7fff0000) {
 138  136                  if (x != x)
 139  137                          return (x + x); /* NaN */
 140  138                  if (x < zero)
 141  139                          return (-one);  /* -inf */
 142  140                  return (x);     /* +inf */
 143  141          }
 144  142          if (ix < 0x3fff4000) {  /* |x| < 1.25 */
 145  143                  if (ix < 0x3ffb0000) {  /* |x| < 0.0625 */
 146  144                          if (ix < 0x3f8d0000) {
 147  145                                  if ((int) x == 0)
 148  146                                          return (x);     /* |x|<2^-114 */
 149  147                          }
 150  148                          t = x * x;
 151  149                          r = (x - t * (P1 + t * (P2 + t * (P3 + t * (P4 + t *
 152  150                                  (P5 + t * (P6 + t * P7)))))));
 153  151                          return (x + (x * r) / (two - r));
 154  152                  }
 155  153                  /* compute i = [64*x] */
 156  154                  m = 0x4009 - (ix >> 16);
 157  155                  j = ((ix & 0x0000ffff) | 0x10000) >> m; /* j=4,...,67 */
 158  156                  if (hx < 0)
 159  157                          j += 82;                        /* negative */
 160  158                  s = x - _TBL_expm1lx[j];
 161  159                  t = s * s;
 162  160                  r = s - t * (T1 + t * (T2 + t * (T3 + t * (T4 + t * T5))));
 163  161                  r = (s + s) / (two - r);
 164  162                  w = _TBL_expm1l[j];
 165  163                  return (w + (w + one) * r);
 166  164          }
 167  165          if (hx > 0) {
 168  166                  if (x > ovflthreshold)
 169  167                          return (huge * huge);
 170  168                  k = (int) (invln2_32 * (x + ln2_64));
 171  169          } else {
 172  170                  if (x < -80.0)
 173  171                          return (tiny - x / x);
 174  172                  k = (int) (invln2_32 * (x - ln2_64));
 175  173          }
 176  174          j = k & 0x1f;
 177  175          m = k >> 5;
 178  176          t = (long double) k;
 179  177          x = (x - t * ln2_32hi) - t * ln2_32lo;
 180  178          t = x * x;
 181  179          r = (x - t * (T1 + t * (T2 + t * (T3 + t * (T4 + t * T5))))) - two;
 182  180          x = _TBL_expl_hi[j] - ((_TBL_expl_hi[j] * (x + x)) / r -
 183  181                  _TBL_expl_lo[j]);
 184  182          return (scalbnl(x, m) - one);
 185  183  }
  
    | 
      ↓ open down ↓ | 
    143 lines elided | 
    
      ↑ open up ↑ | 
  
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX