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

Split Close
Expand all
Collapse all
          --- old/usr/src/lib/libm/common/C/sincospi.c
          +++ new/usr/src/lib/libm/common/C/sincospi.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  
  30      -/* INDENT OFF */
  31   31  /*
  32   32   * void sincospi(double x, double *s, double *c)
  33   33   * *s = sin(pi*x); *c = cos(pi*x);
  34   34   *
  35   35   * Algorithm, 10/17/2002, K.C. Ng
  36   36   * ------------------------------
  37   37   * Let y = |4x|, z = floor(y), and n = (int)(z mod 8.0) (displayed in binary).
  38   38   *      1. If y == z, then x is a multiple of pi/4. Return the following values:
  39   39   *             ---------------------------------------------------
  40   40   *               n  x mod 2    sin(x*pi)    cos(x*pi)   tan(x*pi)
↓ open down ↓ 29 lines elided ↑ open up ↑
  70   70   */
  71   71  
  72   72  #include "libm.h"
  73   73  #include "libm_protos.h"
  74   74  #include "libm_macros.h"
  75   75  #include <math.h>
  76   76  #if defined(__SUNPRO_C)
  77   77  #include <sunmath.h>
  78   78  #endif
  79   79  
  80      -static const double
  81      -        pi      = 3.14159265358979323846,       /* 400921FB,54442D18 */
       80 +/* BEGIN CSTYLEd */
       81 +static const double pi = 3.14159265358979323846,        /* 400921FB,54442D18 */
  82   82          sqrth_h = 0.70710678118654757273731092936941422522068023681640625,
  83   83          sqrth_l = -4.8336466567264565185935844299127932213411660131004e-17;
  84      -/* INDENT ON */
       84 +/* END CSTYLED */
  85   85  
  86   86  void
  87   87  sincospi(double x, double *s, double *c)
  88   88  {
  89   89          double y, z, t;
  90   90          int n, ix, k;
  91   91          int hx = ((int *)&x)[HIWORD];
  92   92          unsigned h, lx = ((unsigned *)&x)[LOWORD];
  93   93  
  94   94          ix = hx & ~0x80000000;
  95   95          n = (ix >> 20) - 0x3ff;
       96 +
  96   97          if (n >= 51) {                  /* |x| >= 2**51 */
  97   98                  if (n >= 1024) {
  98   99  #if defined(FPADD_TRAPS_INCOMPLETE_ON_NAN)
  99  100                          *s = *c = ix >= 0x7ff80000 ? x : x - x;
 100  101                          /* assumes sparc-like QNaN */
 101  102  #else
 102  103                          *s = *c = x - x;
 103  104  #endif
 104  105                  } else {
 105  106                          if (n >= 53) {
↓ open down ↓ 8 lines elided ↑ open up ↑
 114  115                                          *c = -1.0;
 115  116                                  }
 116  117                          } else {        /* n == 51 */
 117  118                                  if ((lx & 1) == 0) {
 118  119                                          *s = 0.0;
 119  120                                          *c = 1.0;
 120  121                                  } else {
 121  122                                          *s = 1.0;
 122  123                                          *c = 0.0;
 123  124                                  }
      125 +
 124  126                                  if ((lx & 2) != 0) {
 125  127                                          *s = -*s;
 126  128                                          *c = -*c;
 127  129                                  }
 128  130                          }
 129  131                  }
 130      -        } else if (n < -2)      /* |x| < 0.25 */
      132 +        } else if (n < -2) {            /* |x| < 0.25 */
 131  133                  *s = __k_sincos(pi * fabs(x), 0.0, c);
 132      -        else {
      134 +        } else {
 133  135                  /* y = |4x|, z = floor(y), and n = (int)(z mod 8.0) */
 134      -                if (ix < 0x41C00000) {          /* |x| < 2**29 */
      136 +                if (ix < 0x41C00000) {  /* |x| < 2**29 */
 135  137                          y = 4.0 * fabs(x);
 136      -                        n = (int)y;             /* exact */
      138 +                        n = (int)y;     /* exact */
 137  139                          z = (double)n;
 138  140                          k = z == y;
 139  141                          t = (y - z) * 0.25;
 140      -                } else {                        /* 2**29 <= |x| < 2**51 */
      142 +                } else {                /* 2**29 <= |x| < 2**51 */
 141  143                          y = fabs(x);
 142  144                          k = 50 - n;
 143  145                          n = lx >> k;
 144  146                          h = n << k;
 145  147                          ((unsigned *)&z)[LOWORD] = h;
 146  148                          ((int *)&z)[HIWORD] = ix;
 147  149                          k = h == lx;
 148  150                          t = y - z;
 149  151                  }
 150      -                if (k) {                        /* x = N/4 */
      152 +
      153 +                if (k) {                /* x = N/4 */
 151  154                          if ((n & 1) != 0) {
 152  155                                  *s = *c = sqrth_h + sqrth_l;
 153  156                          } else {
 154  157                                  if ((n & 2) == 0) {
 155  158                                          *s = 0.0;
 156  159                                          *c = 1.0;
 157  160                                  } else {
 158  161                                          *s = 1.0;
 159  162                                          *c = 0.0;
 160  163                                  }
 161  164                          }
      165 +
 162  166                          if ((n & 4) != 0)
 163  167                                  *s = -*s;
      168 +
 164  169                          if (((n + 1) & 4) != 0)
 165  170                                  *c = -*c;
 166  171                  } else {
 167  172                          if ((n & 1) != 0)
 168  173                                  t = 0.25 - t;
      174 +
 169  175                          if (((n + (n & 1)) & 2) == 0)
 170  176                                  *s = __k_sincos(pi * t, 0.0, c);
 171  177                          else
 172  178                                  *c = __k_sincos(pi * t, 0.0, s);
      179 +
 173  180                          if ((n & 4) != 0)
 174  181                                  *s = -*s;
      182 +
 175  183                          if (((n + 2) & 4) != 0)
 176  184                                  *c = -*c;
 177  185                  }
 178  186          }
      187 +
 179  188          if (hx < 0)
 180  189                  *s = -*s;
 181  190  }
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX