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

Split Close
Expand all
Collapse all
          --- old/usr/src/lib/libm/common/C/__cos.c
          +++ new/usr/src/lib/libm/common/C/__cos.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   * __k_cos(double x; 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   * Accurate Table look-up algorithm by K.C. Ng, May, 1995.
  37   39   *
  38   40   * Algorithm: see __sincos.c
  39   41   */
  40   42  
  41   43  #include "libm.h"
  42   44  
  43   45  static const double sc[] = {
  44      -/* ONE  = */  1.0,
       46 +/* ONE  = */
       47 +        1.0,
  45   48  /* NONE = */ -1.0,
       49 +
  46   50  /*
  47   51   * |sin(x) - (x+pp1*x^3+pp2*x^5)| <= 2^-58.79 for |x| < 0.008
  48   52   */
  49      -/* PP1  = */ -0.166666666666316558867252052378889521480627858683055567,
  50      -/* PP2  = */   .008333315652997472323564894248466758248475374977974017927,
       53 +/* PP1  = */-0.166666666666316558867252052378889521480627858683055567,
       54 +/* PP2  = */.008333315652997472323564894248466758248475374977974017927,
       55 +
  51   56  /*
  52   57   * |(sin(x) - (x+p1*x^3+...+p4*x^9)|
  53   58   * |------------------------------ | <= 2^-57.63 for |x| < 0.1953125
  54   59   * |                 x             |
  55   60   */
  56      -/* P1   = */ -1.666666666666629669805215138920301589656e-0001,
  57      -/* P2   = */  8.333333332390951295683993455280336376663e-0003,
  58      -/* P3   = */ -1.984126237997976692791551778230098403960e-0004,
  59      -/* P4   = */  2.753403624854277237649987622848330351110e-0006,
       61 +/* P1   = */ -1.666666666666629669805215138920301589656e-0001,
       62 +/* P2   = */ 8.333333332390951295683993455280336376663e-0003,
       63 +/* P3   = */ -1.984126237997976692791551778230098403960e-0004,
       64 +/* P4   = */ 2.753403624854277237649987622848330351110e-0006,
       65 +
  60   66  /*
  61   67   * |cos(x) - (1+qq1*x^2+qq2*x^4)| <= 2^-55.99 for |x| <= 0.008 (0x3f80624d)
  62   68   */
  63      -/* QQ1  = */ -0.4999999999975492381842911981948418542742729,
  64      -/* QQ2  = */  0.041666542904352059294545209158357640398771740,
       69 +/* QQ1  = */-0.4999999999975492381842911981948418542742729,
       70 +/* QQ2  = */0.041666542904352059294545209158357640398771740,
       71 +
  65   72  /*
  66   73   * |cos(x) - (1+q1*x^2+...+q4*x^8)| <= 2^-55.86 for |x| <= 0.1640625 (10.5/64)
  67   74   */
  68      -/* Q1   = */ -0.5,
  69      -/* Q2   = */  4.166666666500350703680945520860748617445e-0002,
  70      -/* Q3   = */ -1.388888596436972210694266290577848696006e-0003,
  71      -/* Q4   = */  2.478563078858589473679519517892953492192e-0005,
  72      -};
  73      -/* INDENT ON */
  74      -
  75      -#define ONE     sc[0]
  76      -#define NONE    sc[1]
  77      -#define PP1     sc[2]
  78      -#define PP2     sc[3]
  79      -#define P1      sc[4]
  80      -#define P2      sc[5]
  81      -#define P3      sc[6]
  82      -#define P4      sc[7]
  83      -#define QQ1     sc[8]
  84      -#define QQ2     sc[9]
  85      -#define Q1      sc[10]
  86      -#define Q2      sc[11]
  87      -#define Q3      sc[12]
  88      -#define Q4      sc[13]
       75 +/* Q1   = */ -0.5,
       76 +/* Q2   = */ 4.166666666500350703680945520860748617445e-0002,
       77 +/* Q3   = */ -1.388888596436972210694266290577848696006e-0003,
       78 +/* Q4   = */ 2.478563078858589473679519517892953492192e-0005, };
       79 +
       80 +
       81 +#define ONE             sc[0]
       82 +#define NONE            sc[1]
       83 +#define PP1             sc[2]
       84 +#define PP2             sc[3]
       85 +#define P1              sc[4]
       86 +#define P2              sc[5]
       87 +#define P3              sc[6]
       88 +#define P4              sc[7]
       89 +#define QQ1             sc[8]
       90 +#define QQ2             sc[9]
       91 +#define Q1              sc[10]
       92 +#define Q2              sc[11]
       93 +#define Q3              sc[12]
       94 +#define Q4              sc[13]
  89   95  
  90   96  extern const double _TBL_sincos[], _TBL_sincosx[];
  91   97  
  92   98  double
  93      -__k_cos(double x, double y) {
  94      -        double  z, w, s, v, p, q;
  95      -        int     i, j, n, hx, ix;
       99 +__k_cos(double x, double y)
      100 +{
      101 +        double z, w, s, v, p, q;
      102 +        int i, j, n, hx, ix;
  96  103  
  97  104          hx = ((int *)&x)[HIWORD];
  98  105          ix = hx & ~0x80000000;
  99  106  
 100      -        if (ix <= 0x3fc50000) { /* |x| < 10.5/64 = 0.164062500 */
      107 +        if (ix <= 0x3fc50000) {         /* |x| < 10.5/64 = 0.164062500 */
 101  108                  if (ix < 0x3e400000)    /* |x| < 2**-27 */
 102  109                          if ((int)x == 0)
 103  110                                  return (ONE);
      111 +
 104  112                  z = x * x;
      113 +
 105  114                  if (ix < 0x3f800000)    /* |x| < 0.008 */
 106  115                          q = z * (QQ1 + z * QQ2);
 107  116                  else
 108  117                          q = z * ((Q1 + z * Q2) + (z * z) * (Q3 + z * Q4));
      118 +
 109  119                  return (ONE + q);
 110      -        } else {                /* 0.164062500 < |x| < ~pi/4 */
      120 +        } else {                        /* 0.164062500 < |x| < ~pi/4 */
 111  121                  n = ix >> 20;
 112  122                  i = (((ix >> 12) & 0xff) | 0x100) >> (0x401 - n);
 113  123                  j = i - 10;
      124 +
 114  125                  if (hx < 0)
 115  126                          v = -y - (_TBL_sincosx[j] + x);
 116  127                  else
 117  128                          v = y - (_TBL_sincosx[j] - x);
      129 +
 118  130                  s = v * v;
 119  131                  j <<= 1;
 120  132                  w = _TBL_sincos[j];
 121      -                z = _TBL_sincos[j+1];
      133 +                z = _TBL_sincos[j + 1];
 122  134                  p = s * (PP1 + s * PP2);
 123  135                  q = s * (QQ1 + s * QQ2);
 124  136                  p = v + v * p;
 125  137                  return (z - (w * p - z * q));
 126  138          }
 127  139  }
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX