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

Split Close
Expand all
Collapse all
          --- old/usr/src/lib/libm/common/R/sincosf.c
          +++ new/usr/src/lib/libm/common/R/sincosf.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   31  #pragma weak __sincosf = sincosf
  30   32  
  31      -/* INDENT OFF */
       33 +
  32   34  /*
  33   35   * For |x| < pi/4, let z = x * x, and approximate sin(x) by
  34   36   *
  35   37   *      S(x) = x(S0 + S1*z)(S2 + S3*z + z*z)
  36   38   * where
  37   39   *      S0 =   1.85735322054308378716204874632872525989806770558e-0003,
  38   40   *      S1 =  -1.95035094218403635082921458859320791358115801259e-0004,
  39   41   *      S2 =   5.38400550766074785970952495168558701485841707252e+0002,
  40   42   *      S3 =  -3.31975110777873728964197739157371509422022905947e+0001,
  41   43   *
↓ open down ↓ 3 lines elided ↑ open up ↑
  45   47   *      C(x) = (C0 + C1*z + C2*z*z) * (C3 + C4*z + z*z)
  46   48   * where
  47   49   *      C0 =   1.09349482127188401868272000389539985058873853699e-0003
  48   50   *      C1 =  -5.03324285989964979398034700054920226866107675091e-0004
  49   51   *      C2 =   2.43792880266971107750418061559602239831538067410e-0005
  50   52   *      C3 =   9.14499072605666582228127405245558035523741471271e+0002
  51   53   *      C4 =  -3.63151270591815439197122504991683846785293207730e+0001
  52   54   *
  53   55   * with error bounded by |cos(x) - C(x)| < 2**(-34.2).
  54   56   */
  55      -/* INDENT ON */
  56   57  
  57   58  #include "libm.h"
  58   59  
  59   60  extern const int _TBL_ipio2_inf[];
  60   61  extern int __rem_pio2m(double *, double *, int, int, int, const int *);
       62 +
  61   63  #if defined(__i386) && !defined(__amd64)
  62   64  extern int __swapRP(int);
  63   65  #endif
  64   66  
  65   67  static const double C[] = {
  66   68          1.85735322054308378716204874632872525989806770558e-0003,
  67   69          -1.95035094218403635082921458859320791358115801259e-0004,
  68   70          5.38400550766074785970952495168558701485841707252e+0002,
  69   71          -3.31975110777873728964197739157371509422022905947e+0001,
  70   72          1.09349482127188401868272000389539985058873853699e-0003,
  71   73          -5.03324285989964979398034700054920226866107675091e-0004,
  72   74          2.43792880266971107750418061559602239831538067410e-0005,
  73   75          9.14499072605666582228127405245558035523741471271e+0002,
  74   76          -3.63151270591815439197122504991683846785293207730e+0001,
  75   77          0.636619772367581343075535,     /* 2^ -1  * 1.45F306DC9C883 */
  76   78          0.5,
  77   79          1.570796326734125614166,        /* 2^  0  * 1.921FB54400000 */
  78   80          6.077100506506192601475e-11,    /* 2^-34  * 1.0B4611A626331 */
  79   81  };
  80   82  
  81      -#define S0      C[0]
  82      -#define S1      C[1]
  83      -#define S2      C[2]
  84      -#define S3      C[3]
  85      -#define C0      C[4]
  86      -#define C1      C[5]
  87      -#define C2      C[6]
  88      -#define C3      C[7]
  89      -#define C4      C[8]
  90      -#define invpio2 C[9]
  91      -#define half    C[10]
  92      -#define pio2_1  C[11]
  93      -#define pio2_t  C[12]
       83 +#define S0              C[0]
       84 +#define S1              C[1]
       85 +#define S2              C[2]
       86 +#define S3              C[3]
       87 +#define C0              C[4]
       88 +#define C1              C[5]
       89 +#define C2              C[6]
       90 +#define C3              C[7]
       91 +#define C4              C[8]
       92 +#define invpio2         C[9]
       93 +#define half            C[10]
       94 +#define pio2_1          C[11]
       95 +#define pio2_t          C[12]
  94   96  
  95   97  void
  96   98  sincosf(float x, float *s, float *c)
  97   99  {
  98      -        double  y, z, w;
  99      -        float   f, g;
 100      -        int     n, ix, hx, hy;
      100 +        double y, z, w;
      101 +        float f, g;
      102 +        int n, ix, hx, hy;
 101  103          volatile int i __unused;
 102  104  
 103  105          hx = *((int *)&x);
 104  106          ix = hx & 0x7fffffff;
 105  107  
 106  108          y = (double)x;
 107  109  
 108      -        if (ix <= 0x4016cbe4) {         /* |x| < 3*pi/4 */
      110 +        if (ix <= 0x4016cbe4) {                 /* |x| < 3*pi/4 */
 109  111                  if (ix <= 0x3f490fdb) {         /* |x| < pi/4 */
 110  112                          if (ix <= 0x39800000) { /* |x| <= 2**-12 */
 111  113                                  i = (int)y;
 112  114  #ifdef lint
 113  115                                  i = i;
 114  116  #endif
 115  117                                  *s = x;
 116  118                                  *c = 1.0f;
 117  119                                  return;
 118  120                          }
      121 +
 119  122                          z = y * y;
 120      -                        *s = (float)((y * (S0 + z * S1)) *
 121      -                            (S2 + z * (S3 + z)));
 122      -                        *c = (float)(((C0 + z * C1) + (z * z) * C2) *
 123      -                            (C3 + z * (C4 + z)));
      123 +                        *s = (float)((y * (S0 + z * S1)) * (S2 + z * (S3 + z)));
      124 +                        *c = (float)(((C0 + z * C1) + (z * z) * C2) * (C3 + z *
      125 +                            (C4 + z)));
 124  126                  } else if (hx > 0) {
 125  127                          y = (y - pio2_1) - pio2_t;
 126  128                          z = y * y;
 127      -                        *s = (float)(((C0 + z * C1) + (z * z) * C2) *
 128      -                            (C3 + z * (C4 + z)));
 129      -                        *c = (float)-((y * (S0 + z * S1)) *
 130      -                            (S2 + z * (S3 + z)));
      129 +                        *s = (float)(((C0 + z * C1) + (z * z) * C2) * (C3 + z *
      130 +                            (C4 + z)));
      131 +                        *c = (float)-((y * (S0 + z * S1)) * (S2 + z * (S3 +
      132 +                            z)));
 131  133                  } else {
 132  134                          y = (y + pio2_1) + pio2_t;
 133  135                          z = y * y;
 134      -                        *s = (float)-(((C0 + z * C1) + (z * z) * C2) *
 135      -                            (C3 + z * (C4 + z)));
 136      -                        *c = (float)((y * (S0 + z * S1)) *
 137      -                            (S2 + z * (S3 + z)));
      136 +                        *s = (float)-(((C0 + z * C1) + (z * z) * C2) * (C3 + z *
      137 +                            (C4 + z)));
      138 +                        *c = (float)((y * (S0 + z * S1)) * (S2 + z * (S3 + z)));
 138  139                  }
      140 +
 139  141                  return;
 140  142          } else if (ix <= 0x49c90fdb) {  /* |x| < 2^19*pi */
 141  143  #if defined(__i386) && !defined(__amd64)
 142      -                int     rp;
      144 +                int rp;
 143  145  
 144  146                  rp = __swapRP(fp_extended);
 145  147  #endif
 146  148                  w = y * invpio2;
      149 +
 147  150                  if (hx < 0)
 148  151                          n = (int)(w - half);
 149  152                  else
 150  153                          n = (int)(w + half);
      154 +
 151  155                  y = (y - n * pio2_1) - n * pio2_t;
 152  156  #if defined(__i386) && !defined(__amd64)
 153  157                  if (rp != fp_extended)
 154  158                          (void) __swapRP(rp);
 155  159  #endif
 156  160          } else {
 157  161                  if (ix >= 0x7f800000) {
 158  162                          *s = *c = x / x;
 159  163                          return;
 160  164                  }
      165 +
 161  166                  hy = ((int *)&y)[HIWORD];
 162  167                  n = ((hy >> 20) & 0x7ff) - 1046;
 163  168                  ((int *)&w)[HIWORD] = (hy & 0xfffff) | 0x41600000;
 164  169                  ((int *)&w)[LOWORD] = ((int *)&y)[LOWORD];
 165  170                  n = __rem_pio2m(&w, &y, n, 1, 0, _TBL_ipio2_inf);
      171 +
 166  172                  if (hy < 0) {
 167  173                          y = -y;
 168  174                          n = -n;
 169  175                  }
 170  176          }
 171  177  
 172  178          z = y * y;
 173  179          f = (float)((y * (S0 + z * S1)) * (S2 + z * (S3 + z)));
 174      -        g = (float)(((C0 + z * C1) + (z * z) * C2) *
 175      -            (C3 + z * (C4 + z)));
      180 +        g = (float)(((C0 + z * C1) + (z * z) * C2) * (C3 + z * (C4 + z)));
      181 +
 176  182          if (n & 2) {
 177  183                  f = -f;
 178  184                  g = -g;
 179  185          }
      186 +
 180  187          if (n & 1) {
 181  188                  *s = g;
 182  189                  *c = -f;
 183  190          } else {
 184  191                  *s = f;
 185  192                  *c = g;
 186  193          }
 187  194  }
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX