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

Split Close
Expand all
Collapse all
          --- old/usr/src/lib/libm/common/C/__sincos.c
          +++ new/usr/src/lib/libm/common/C/__sincos.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 2005 Sun Microsystems, Inc.  All rights reserved.
  26   28   * Use is subject to license terms.
  27   29   */
  28   30  
  29      -/* INDENT OFF */
       31 +
  30   32  /*
  31   33   * double __k_sincos(double x, double y, double *c);
  32   34   * kernel sincos 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   * return sin(x) with *c = cos(x)
  36   38   *
  37   39   * Accurate Table look-up algorithm by K.C. Ng, May, 1995.
  38   40   *
  39   41   * 1. Reduce x to x>0 by sin(-x)=-sin(x),cos(-x)=cos(x).
↓ open down ↓ 20 lines elided ↑ open up ↑
  60   62   *      sin(y) = y + y^3*(pp1+y^2*pp2)
  61   63   *      cos(y) = 1 + y^2*(qq1+y^2*qq2)
  62   64   *
  63   65   * Accuracy:
  64   66   *      TRIG(x) returns trig(x) nearly rounded (less than 1 ulp)
  65   67   */
  66   68  
  67   69  #include "libm.h"
  68   70  
  69   71  static const double sc[] = {
  70      -/* ONE  = */  1.0,
       72 +/* ONE  = */
       73 +        1.0,
  71   74  /* NONE = */ -1.0,
       75 +
  72   76  /*
  73   77   * |sin(x) - (x+pp1*x^3+pp2*x^5)| <= 2^-58.79 for |x| < 0.008
  74   78   */
  75      -/* PP1  = */ -0.166666666666316558867252052378889521480627858683055567,
  76      -/* PP2  = */   .008333315652997472323564894248466758248475374977974017927,
       79 +/* PP1  = */-0.166666666666316558867252052378889521480627858683055567,
       80 +/* PP2  = */.008333315652997472323564894248466758248475374977974017927,
       81 +
  77   82  /*
  78   83   * |(sin(x) - (x+p1*x^3+...+p4*x^9)|
  79   84   * |------------------------------ | <= 2^-57.63 for |x| < 0.1953125
  80   85   * |                 x             |
  81   86   */
  82      -/* P1   = */ -1.666666666666629669805215138920301589656e-0001,
  83      -/* P2   = */  8.333333332390951295683993455280336376663e-0003,
  84      -/* P3   = */ -1.984126237997976692791551778230098403960e-0004,
  85      -/* P4   = */  2.753403624854277237649987622848330351110e-0006,
       87 +/* P1   = */ -1.666666666666629669805215138920301589656e-0001,
       88 +/* P2   = */ 8.333333332390951295683993455280336376663e-0003,
       89 +/* P3   = */ -1.984126237997976692791551778230098403960e-0004,
       90 +/* P4   = */ 2.753403624854277237649987622848330351110e-0006,
       91 +
  86   92  /*
  87   93   * |cos(x) - (1+qq1*x^2+qq2*x^4)| <= 2^-55.99 for |x| <= 0.008 (0x3f80624d)
  88   94   */
  89      -/* QQ1  = */ -0.4999999999975492381842911981948418542742729,
  90      -/* QQ2  = */  0.041666542904352059294545209158357640398771740,
       95 +/* QQ1  = */-0.4999999999975492381842911981948418542742729,
       96 +/* QQ2  = */0.041666542904352059294545209158357640398771740,
       97 +
  91   98  /*
  92   99   * |cos(x) - (1+q1*x^2+...+q4*x^8)| <= 2^-55.86 for |x| <= 0.1640625 (10.5/64)
  93  100   */
  94      -/* Q1   = */ -0.5,
  95      -/* Q2   = */  4.166666666500350703680945520860748617445e-0002,
  96      -/* Q3   = */ -1.388888596436972210694266290577848696006e-0003,
  97      -/* Q4   = */  2.478563078858589473679519517892953492192e-0005,
      101 +/* Q1   = */ -0.5,
      102 +/* Q2   = */ 4.166666666500350703680945520860748617445e-0002,
      103 +/* Q3   = */ -1.388888596436972210694266290577848696006e-0003,
      104 +/* Q4   = */ 2.478563078858589473679519517892953492192e-0005,
  98  105  };
  99      -/* INDENT ON */
 100  106  
 101      -#define ONE     sc[0]
 102      -#define NONE    sc[1]
 103      -#define PP1     sc[2]
 104      -#define PP2     sc[3]
 105      -#define P1      sc[4]
 106      -#define P2      sc[5]
 107      -#define P3      sc[6]
 108      -#define P4      sc[7]
 109      -#define QQ1     sc[8]
 110      -#define QQ2     sc[9]
 111      -#define Q1      sc[10]
 112      -#define Q2      sc[11]
 113      -#define Q3      sc[12]
 114      -#define Q4      sc[13]
      107 +
      108 +#define ONE             sc[0]
      109 +#define NONE            sc[1]
      110 +#define PP1             sc[2]
      111 +#define PP2             sc[3]
      112 +#define P1              sc[4]
      113 +#define P2              sc[5]
      114 +#define P3              sc[6]
      115 +#define P4              sc[7]
      116 +#define QQ1             sc[8]
      117 +#define QQ2             sc[9]
      118 +#define Q1              sc[10]
      119 +#define Q2              sc[11]
      120 +#define Q3              sc[12]
      121 +#define Q4              sc[13]
 115  122  
 116  123  extern const double _TBL_sincos[], _TBL_sincosx[];
 117  124  
 118  125  double
 119      -__k_sincos(double x, double y, double *c) {
 120      -        double  z, w, s, v, p, q;
 121      -        int     i, j, n, hx, ix;
      126 +__k_sincos(double x, double y, double *c)
      127 +{
      128 +        double z, w, s, v, p, q;
      129 +        int i, j, n, hx, ix;
 122  130  
 123  131          hx = ((int *)&x)[HIWORD];
 124  132          ix = hx & ~0x80000000;
 125  133  
 126      -        if (ix <= 0x3fc50000) { /* |x| < 10.5/64 = 0.164062500 */
      134 +        if (ix <= 0x3fc50000) {         /* |x| < 10.5/64 = 0.164062500 */
 127  135                  if (ix < 0x3e400000) {  /* |x| < 2**-27 */
 128  136                          if ((int)x == 0)
 129  137                                  *c = ONE;
      138 +
 130  139                          return (x + y);
 131  140                  } else {
 132  141                          z = x * x;
      142 +
 133  143                          if (ix < 0x3f800000) {  /* |x| < 0.008 */
 134  144                                  q = z * (QQ1 + z * QQ2);
 135  145                                  p = (x * z) * (PP1 + z * PP2) + y;
 136  146                          } else {
 137      -                                q = z * ((Q1 + z * Q2) + (z * z) * (Q3 +
 138      -                                    z * Q4));
      147 +                                q = z * ((Q1 + z * Q2) + (z * z) * (Q3 + z *
      148 +                                    Q4));
 139  149                                  p = (x * z) * ((P1 + z * P2) + (z * z) * (P3 +
 140  150                                      z * P4)) + y;
 141  151                          }
      152 +
 142  153                          *c = ONE + q;
 143  154                          return (x + p);
 144  155                  }
 145      -        } else {                /* 0.164062500 < |x| < ~pi/4 */
      156 +        } else {                        /* 0.164062500 < |x| < ~pi/4 */
 146  157                  n = ix >> 20;
 147  158                  i = (((ix >> 12) & 0xff) | 0x100) >> (0x401 - n);
 148  159                  j = i - 10;
      160 +
 149  161                  if (hx < 0)
 150  162                          v = -y - (_TBL_sincosx[j] + x);
 151  163                  else
 152  164                          v = y - (_TBL_sincosx[j] - x);
      165 +
 153  166                  s = v * v;
 154  167                  j <<= 1;
 155  168                  w = _TBL_sincos[j];
 156      -                z = _TBL_sincos[j+1];
      169 +                z = _TBL_sincos[j + 1];
 157  170                  p = s * (PP1 + s * PP2);
 158  171                  q = s * (QQ1 + s * QQ2);
 159  172                  p = v + v * p;
 160  173                  *c = z - (w * p - z * q);
 161  174                  s = w * q + z * p;
 162      -                return ((hx >= 0)? w + s : -(w + s));
      175 +                return ((hx >= 0) ? w + s : -(w + s));
 163  176          }
 164  177  }
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX