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

Split Close
Expand all
Collapse all
          --- old/usr/src/lib/libm/common/LD/sincospil.c
          +++ new/usr/src/lib/libm/common/LD/sincospil.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   31  /*
  31   32   * void sincospil(long double x, long double *s, long double *c)
  32   33   * *s = sinl(pi*x); *c = cosl(pi*x);
  33   34   *
  34   35   * Algorithm, 10/17/2002, K.C. Ng
↓ open down ↓ 31 lines elided ↑ open up ↑
  66   67   * than 2 ulp). If one wants accurate result,  one may break up pi*t in
  67   68   * high (tpi_h) and low (tpi_l) parts and call __k_sin/cos(tip_h, tip_lo)
  68   69   * instead.
  69   70   */
  70   71  
  71   72  #include "libm.h"
  72   73  #include "longdouble.h"
  73   74  
  74   75  #include <sys/isa_defs.h>
  75   76  
  76      -#define I(q, m) ((int *) &(q))[m]
  77      -#define U(q, m) ((unsigned *) &(q))[m]
       77 +#define I(q, m)                         ((int *)&(q))[m]
       78 +#define U(q, m)                         ((unsigned *)&(q))[m]
  78   79  #if defined(__i386) || defined(__amd64)
  79      -#define LDBL_MOST_SIGNIF_I(ld)  ((I(ld, 2) << 16) | (0xffff & (I(ld, 1) >> 15)))
  80      -#define LDBL_LEAST_SIGNIF_U(ld) U(ld, 0)
  81      -#define PREC    64
  82      -#define PRECM1  63
  83      -#define PRECM2  62
       80 +#define LDBL_MOST_SIGNIF_I(ld)          ((I(ld, 2) << 16) | (0xffff & (I(ld, \
       81 +        1) >> 15)))
       82 +#define LDBL_LEAST_SIGNIF_U(ld)         U(ld, 0)
       83 +#define PREC                            64
       84 +#define PRECM1                          63
       85 +#define PRECM2                          62
       86 +
  84   87  static const long double twoPRECM2 = 9.223372036854775808000000000000000e+18L;
  85   88  #else
  86      -#define LDBL_MOST_SIGNIF_I(ld)  I(ld, 0)
  87      -#define LDBL_LEAST_SIGNIF_U(ld) U(ld, sizeof(long double) / sizeof(int) - 1)
  88      -#define PREC    113
  89      -#define PRECM1  112
  90      -#define PRECM2  111
       89 +#define LDBL_MOST_SIGNIF_I(ld)          I(ld, 0)
       90 +#define LDBL_LEAST_SIGNIF_U(ld)         U(ld, sizeof (long double) / \
       91 +        sizeof (int) - 1)
       92 +#define PREC                            113
       93 +#define PRECM1                          112
       94 +#define PRECM2                          111
       95 +
  91   96  static const long double twoPRECM2 = 5.192296858534827628530496329220096e+33L;
  92   97  #endif
  93   98  
  94      -static const long double
  95      -zero    = 0.0L,
  96      -quater  = 0.25L,
  97      -one     = 1.0L,
  98      -pi      = 3.141592653589793238462643383279502884197e+0000L,
  99      -sqrth   = 0.707106781186547524400844362104849039284835937688474,
 100      -tiny    = 1.0e-100;
       99 +static const long double zero = 0.0L,
      100 +        quater = 0.25L,
      101 +        one = 1.0L,
      102 +        pi = 3.141592653589793238462643383279502884197e+0000L,
      103 +        sqrth = 0.707106781186547524400844362104849039284835937688474,
      104 +        tiny = 1.0e-100;
 101  105  
 102  106  void
 103      -sincospil(long double x, long double *s, long double *c) {
      107 +sincospil(long double x, long double *s, long double *c)
      108 +{
 104  109          long double y, z, t;
 105  110          int hx, n, k;
 106  111          unsigned lx;
 107  112  
 108  113          hx = LDBL_MOST_SIGNIF_I(x);
 109  114          lx = LDBL_LEAST_SIGNIF_U(x);
 110  115          k = ((hx & 0x7fff0000) >> 16) - 0x3fff;
      116 +
 111  117          if (k >= PRECM2) {              /* |x| >= 2**(Prec-2) */
 112  118                  if (k >= 16384) {
 113  119                          *s = *c = x - x;
 114      -                }
 115      -                else {
      120 +                } else {
 116  121                          if (k >= PREC) {
 117  122                                  *s = zero;
 118  123                                  *c = one;
 119      -                        }
 120      -                        else if (k == PRECM1) {
      124 +                        } else if (k == PRECM1) {
 121  125                                  if ((lx & 1) == 0) {
 122  126                                          *s = zero;
 123  127                                          *c = one;
 124      -                                }
 125      -                                else {
      128 +                                } else {
 126  129                                          *s = -zero;
 127  130                                          *c = -one;
 128  131                                  }
 129      -                        }
 130      -                        else {  /* k = Prec - 2 */
      132 +                        } else { /* k = Prec - 2 */
 131  133                                  if ((lx & 1) == 0) {
 132  134                                          *s = zero;
 133  135                                          *c = one;
 134      -                                }
 135      -                                else {
      136 +                                } else {
 136  137                                          *s = one;
 137  138                                          *c = zero;
 138  139                                  }
      140 +
 139  141                                  if ((lx & 2) != 0) {
 140  142                                          *s = -*s;
 141  143                                          *c = -*c;
 142  144                                  }
 143  145                          }
 144  146                  }
 145      -        }
 146      -        else if (k < -2)        /* |x| < 0.25 */
      147 +        } else if (k < -2) {            /* |x| < 0.25 */
 147  148                  *s = __k_sincosl(pi * fabsl(x), zero, c);
 148      -        else {
      149 +        } else {
 149  150                  /* y = |4x|, z = floor(y), and n = (int)(z mod 8.0) */
 150  151                  y = 4.0L * fabsl(x);
      152 +
 151  153                  if (k < PRECM2) {
 152  154                          z = y + twoPRECM2;
 153  155                          n = LDBL_LEAST_SIGNIF_U(z) & 7; /* 3 LSb of z */
 154  156                          t = z - twoPRECM2;
 155  157                          k = 0;
 156      -                        if (t == y)
      158 +
      159 +                        if (t == y) {
 157  160                                  k = 1;
 158      -                        else if (t > y) {
      161 +                        } else if (t > y) {
 159  162                                  n -= 1;
 160  163                                  t = quater + (y - t) * quater;
 161      -                        }
 162      -                        else
      164 +                        } else {
 163  165                                  t = (y - t) * quater;
 164      -                }
 165      -                else {  /* k = Prec-3 */
      166 +                        }
      167 +                } else { /* k = Prec-3 */
 166  168                          n = LDBL_LEAST_SIGNIF_U(y) & 7; /* 3 LSb of z */
 167  169                          k = 1;
 168  170                  }
 169      -                if (k) {        /* x = N/4 */
 170      -                        if ((n & 1) != 0)
      171 +
      172 +                if (k) {                /* x = N/4 */
      173 +                        if ((n & 1) != 0) {
 171  174                                  *s = *c = sqrth + tiny;
 172      -                        else
 173      -                                if ((n & 2) == 0) {
 174      -                                        *s = zero;
 175      -                                        *c = one;
 176      -                                }
 177      -                                else {
 178      -                                        *s = one;
 179      -                                        *c = zero;
 180      -                                }
      175 +                        } else if ((n & 2) == 0) {
      176 +                                *s = zero;
      177 +                                *c = one;
      178 +                        } else {
      179 +                                *s = one;
      180 +                                *c = zero;
      181 +                        }
      182 +
 181  183                          if ((n & 4) != 0)
 182  184                                  *s = -*s;
      185 +
 183  186                          if (((n + 1) & 4) != 0)
 184  187                                  *c = -*c;
 185      -                }
 186      -                else {
      188 +                } else {
 187  189                          if ((n & 1) != 0)
 188  190                                  t = quater - t;
      191 +
 189  192                          if (((n + (n & 1)) & 2) == 0)
 190  193                                  *s = __k_sincosl(pi * t, zero, c);
 191  194                          else
 192  195                                  *c = __k_sincosl(pi * t, zero, s);
      196 +
 193  197                          if ((n & 4) != 0)
 194  198                                  *s = -*s;
      199 +
 195  200                          if (((n + 2) & 4) != 0)
 196  201                                  *c = -*c;
 197  202                  }
 198  203          }
      204 +
 199  205          if (hx < 0)
 200  206                  *s = -*s;
 201  207  }
      208 +
 202  209  #undef U
 203  210  #undef LDBL_LEAST_SIGNIF_U
 204  211  #undef I
 205  212  #undef LDBL_MOST_SIGNIF_I
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX