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

Split Close
Expand all
Collapse all
          --- old/usr/src/lib/libm/common/Q/__cosl.c
          +++ new/usr/src/lib/libm/common/Q/__cosl.c
↓ open down ↓ 14 lines elided ↑ open up ↑
  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   23   * Copyright 2011 Nexenta Systems, Inc.  All rights reserved.
  24   24   */
       25 +
  25   26  /*
  26   27   * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
  27   28   * Use is subject to license terms.
  28   29   */
  29   30  
       31 +/* BEGIN CSTYLED */
  30   32  /*
  31   33   * __k_cosl(long double x, long double y)
  32   34   * kernel cos function on [-pi/4, pi/4], pi/4 ~ 0.785398164
  33   35   * Input x is assumed to be bounded by ~pi/4 in magnitude.
  34   36   * Input y is the tail of x.
  35   37   *
  36   38   * Table look up algorithm
  37   39   *      1. by cos(-x) = cos(x), we may replace x by |x|
  38   40   *      2. if x < 25/128 = [0x3ffc4000, 0] = 0.15625 , then
  39   41   *           if x < 2^-57 (hx < 0x3fc60000 0), return 1.0 with inexact if x !=  0
  40   42   *           z = x*x;
  41   43   *           if x <= 1/128 = 2**-7 = 0.0078125
  42   44   *              cos(x)=1.0+z*(qq1+z*(qq2+z*(qq3+z*(qq4+z*qq5))))
  43   45   *           else
  44   46   *              cos(x)=1.0+z*(q1+ ... z*q8)
  45   47   *      3. else
  46   48   *              ht = (hx + 0x400)&0x7ffff800    (round x to a break point t)
  47   49   *              lt = 0
  48   50   *              i  = (hy-0x3ffc4000)>>11;       (i<=64)
  49      - *              x' = (x - t)+y                  (|x'| ~<= 2^-7
       51 + *              x' = (x - t)+y                  (|x'| ~<= 2^-7
  50   52   *         By
  51   53   *              cos(t+x')
  52   54   *                = cos(t)cos(x')-sin(t)sin(x')
  53   55   *                = cos(t)(1+z*(qq1+z*qq2))-[sin(t)]*x*(1+z*(pp1+z*pp2))
  54   56   *                = cos(t) + [cos(t)]*(z*(qq1+z*qq2))-
  55   57   *                              [sin(t)]*x*(1+z*(pp1+z*pp2))
  56   58   *
  57   59   *         Thus,
  58   60   *              let a= _TBL_cos_hi[i], b = _TBL_cos_lo[i], c= _TBL_sin_hi[i],
  59   61   *              x = (x-t)+y
  60   62   *              z = x*x;
  61   63   *              cos(t+x) = a+(b+ (-c*x*(1+z*(pp1+z*pp2))+a*(z*(qq1+z*qq2)))
  62   64   */
       65 +/* END CSTYLED */
  63   66  
  64   67  #include "libm.h"
  65   68  
  66   69  extern const long double _TBL_cosl_hi[], _TBL_cosl_lo[], _TBL_sinl_hi[];
  67      -static const long double
  68      -        one     = 1.0L,
       70 +static const long double one = 1.0L;
       71 +
  69   72  /*
  70   73   *                   3           11       -122.32
  71   74   * |sin(x) - (x+pp1*x +...+ pp5*x  )| <= 2        for |x|<1/64
  72   75   */
  73      -        pp1     = -1.666666666666666666666666666586782940810e-0001L,
  74      -        pp2     = +8.333333333333333333333003723660929317540e-0003L,
  75      -        pp3     = -1.984126984126984076045903483778337804470e-0004L,
  76      -        pp4     = +2.755731922361906641319723106210900949413e-0006L,
  77      -        pp5     = -2.505198398570947019093998469135012057673e-0008L,
       76 +static const long double
       77 +        pp1 = -1.666666666666666666666666666586782940810e-0001L,
       78 +        pp2 = +8.333333333333333333333003723660929317540e-0003L,
       79 +        pp3 = -1.984126984126984076045903483778337804470e-0004L,
       80 +        pp4 = +2.755731922361906641319723106210900949413e-0006L,
       81 +        pp5 = -2.505198398570947019093998469135012057673e-0008L;
       82 +
  78   83  /*
  79   84   *                  2            16       -117.11
  80   85   * |cos(x) - (1+q1*x + ... + q8*x  )| <= 2        for |x|<= 0.15625
  81   86   */
  82      -        q1      = -4.999999999999999999999999999999756416975e-0001L,
  83      -        q2      = +4.166666666666666666666666664006066577258e-0002L,
  84      -        q3      = -1.388888888888888888888877700363937169637e-0003L,
  85      -        q4      = +2.480158730158730158494468463031814083559e-0005L,
  86      -        q5      = -2.755731922398586276322819250356005542871e-0007L,
  87      -        q6      = +2.087675698767424261441959760729854017855e-0009L,
  88      -        q7      = -1.147074481239662089072452129010790774761e-0011L,
  89      -        q8      = +4.777761647399651599730663422263531034782e-0014L,
       87 +static const long double
       88 +        q1 = -4.999999999999999999999999999999756416975e-0001L,
       89 +        q2 = +4.166666666666666666666666664006066577258e-0002L,
       90 +        q3 = -1.388888888888888888888877700363937169637e-0003L,
       91 +        q4 = +2.480158730158730158494468463031814083559e-0005L,
       92 +        q5 = -2.755731922398586276322819250356005542871e-0007L,
       93 +        q6 = +2.087675698767424261441959760729854017855e-0009L,
       94 +        q7 = -1.147074481239662089072452129010790774761e-0011L,
       95 +        q8 = +4.777761647399651599730663422263531034782e-0014L;
       96 +
  90   97  /*
  91   98   *                   2           10       -123.84
  92   99   * |cos(x) - (1+qq1*x +...+ qq5*x  )| <= 2        for |x|<=1/128
  93  100   */
  94      -        qq1     = -4.999999999999999999999999999999378373641e-0001L,
  95      -        qq2     = +4.166666666666666666666665478399327703130e-0002L,
  96      -        qq3     = -1.388888888888888888058211230618051613494e-0003L,
  97      -        qq4     = +2.480158730156105377771585658905303111866e-0005L,
  98      -        qq5     = -2.755728099762526325736488376695157008736e-0007L;
      101 +static const long double
      102 +        qq1 = -4.999999999999999999999999999999378373641e-0001L,
      103 +        qq2 = +4.166666666666666666666665478399327703130e-0002L,
      104 +        qq3 = -1.388888888888888888058211230618051613494e-0003L,
      105 +        qq4 = +2.480158730156105377771585658905303111866e-0005L,
      106 +        qq5 = -2.755728099762526325736488376695157008736e-0007L;
  99  107  
 100  108  #define i0      0
 101  109  
 102  110  long double
 103      -__k_cosl(long double x, long double y) {
      111 +__k_cosl(long double x, long double y)
      112 +{
 104  113          long double a, t, z, w;
 105      -        int *pt = (int *) &t, *px = (int *) &x;
      114 +        int *pt = (int *)&t, *px = (int *)&x;
 106  115          int i, j, hx, ix;
 107  116  
 108  117          t = 1.0L;
 109  118          hx = px[i0];
 110  119          ix = hx & 0x7fffffff;
      120 +
 111  121          if (ix < 0x3ffc4000) {
 112  122                  if (ix < 0x3fc60000)
 113      -                        if ((i = (int) x) == 0)
 114      -                                return (one);   /* generate inexact */
      123 +                        if ((i = (int)x) == 0)
      124 +                                return (one);
      125 +
      126 +                /* generate inexact */
 115  127                  z = x * x;
 116  128  
 117      -                if (ix < 0x3ff80000)    /* 0.0078125 */
 118      -                        return one + z * (qq1 + z * (qq2 + z * (qq3 +
 119      -                                z * (qq4 + z * qq5))));
 120      -                else
 121      -                        return one + z * (q1 + z * (q2 + z * (q3 +
 122      -                                z * (q4 + z * (q5 + z * (q6 + z * (q7 +
 123      -                                z * q8)))))));
      129 +                if (ix < 0x3ff80000) {  /* 0.0078125 */
      130 +                        return (one + z * (qq1 + z * (qq2 + z * (qq3 + z *
      131 +                            (qq4 + z * qq5)))));
      132 +                } else {
      133 +                        return (one + z * (q1 + z * (q2 + z * (q3 + z * (q4 +
      134 +                            z * (q5 + z * (q6 + z * (q7 + z * q8))))))));
      135 +                }
 124  136          }
      137 +
 125  138          j = (ix + 0x400) & 0x7ffff800;
 126  139          i = (j - 0x3ffc4000) >> 11;
 127  140          pt[i0] = j;
      141 +
 128  142          if (hx > 0)
 129  143                  x = y - (t - x);
 130  144          else
 131  145                  x = (-y) - (t + x);
      146 +
 132  147          a = _TBL_cosl_hi[i];
 133  148          z = x * x;
 134  149          t = z * (qq1 + z * (qq2 + z * (qq3 + z * (qq4 + z * qq5))));
 135  150          w = x * (one + z * (pp1 + z * (pp2 + z * (pp3 + z * (pp4 + z * pp5)))));
 136  151          t = _TBL_cosl_lo[i] - (_TBL_sinl_hi[i] * w - a * t);
 137  152          return (a + t);
 138  153  }
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX