Print this page
11210 libm should be cstyle(1ONBLD) clean
   1 /*
   2  * CDDL HEADER START
   3  *
   4  * The contents of this file are subject to the terms of the
   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */

  21 /*
  22  * Copyright 2011 Nexenta Systems, Inc.  All rights reserved.
  23  */

  24 /*
  25  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
  26  * Use is subject to license terms.
  27  */
  28 
  29 #pragma weak __tanf = tanf
  30 
  31 #include "libm.h"
  32 
  33 extern const int _TBL_ipio2_inf[];
  34 extern int __rem_pio2m(double *, double *, int, int, int, const int *);

  35 #if defined(__i386) && !defined(__amd64)
  36 extern int __swapRP(int);
  37 #endif
  38 
  39 static const double C[] = {
  40         1.0,
  41         4.46066928428959230679140546271810308098793029785e-0003,
  42         4.92165316309189027066395283327437937259674072266e+0000,
  43         -7.11410648161473480044492134766187518835067749023e-0001,
  44         4.08549808374053391446523164631798863410949707031e+0000,
  45         2.50411070398050927821032018982805311679840087891e+0000,
  46         1.11492064560251158411574579076841473579406738281e+0001,
  47         -1.50565540968422650891511693771462887525558471680e+0000,
  48         -1.81484378878349295050043110677506774663925170898e+0000,
  49         3.333335997532835641297409611782510896641e-0001,
  50         2.999997598248363761541668282006867229939e+00,
  51         0.636619772367581343075535,     /* 2^ -1  * 1.45F306DC9C883 */
  52         0.5,
  53         1.570796326734125614166,        /* 2^  0  * 1.921FB54400000 */
  54         6.077100506506192601475e-11,    /* 2^-34  * 1.0B4611A626331 */


  76         double  y, z, w;
  77         float   f;
  78         int     n, ix, hx, hy;
  79         volatile int i __unused;
  80 
  81         hx = *((int *)&x);
  82         ix = hx & 0x7fffffff;
  83 
  84         y = (double)x;
  85 
  86         if (ix <= 0x4016cbe4) {              /* |x| < 3*pi/4 */
  87                 if (ix <= 0x3f490fdb) {              /* |x| < pi/4 */
  88                         if (ix < 0x3c000000) {               /* |x| < 2**-7 */
  89                                 if (ix <= 0x39800000) {      /* |x| < 2**-12 */
  90                                         i = (int)y;
  91 #ifdef lint
  92                                         i = i;
  93 #endif
  94                                         return (x);
  95                                 }

  96                                 return ((float)((y * T0) * (T1 + y * y)));
  97                         }

  98                         z = y * y;
  99                         return ((float)(((P0 * y) * (P1 + z * (P2 + z)) *
 100                             (P3 + z * (P4 + z))) *
 101                             (P5 + z * (P6 + z * (P7 + z)))));
 102                 }

 103                 if (hx > 0)
 104                         y = (y - pio2_1) - pio2_t;
 105                 else
 106                         y = (y + pio2_1) + pio2_t;

 107                 hy = ((int *)&y)[HIWORD] & ~0x80000000;

 108                 if (hy < 0x3f800000) {               /* |y| < 2**-7 */
 109                         z = (y * T0) * (T1 + y * y);
 110                         return ((float)(-one / z));
 111                 }

 112                 z = y * y;
 113                 w = ((P0 * y) * (P1 + z * (P2 + z)) * (P3 + z * (P4 + z))) *
 114                     (P5 + z * (P6 + z * (P7 + z)));
 115                 return ((float)(-one / w));
 116         }
 117 
 118         if (ix <= 0x49c90fdb) {      /* |x| < 2^19*pi */
 119 #if defined(__i386) && !defined(__amd64)
 120                 int     rp;
 121 
 122                 rp = __swapRP(fp_extended);
 123 #endif
 124                 w = y * invpio2;

 125                 if (hx < 0)
 126                         n = (int)(w - half);
 127                 else
 128                         n = (int)(w + half);

 129                 y = (y - n * pio2_1) - n * pio2_t;
 130 #if defined(__i386) && !defined(__amd64)
 131                 if (rp != fp_extended)
 132                         (void) __swapRP(rp);
 133 #endif
 134         } else {
 135                 if (ix >= 0x7f800000)
 136                         return (x / x); /* sin(Inf or NaN) is NaN */

 137                 hy = ((int *)&y)[HIWORD];
 138                 n = ((hy >> 20) & 0x7ff) - 1046;
 139                 ((int *)&w)[HIWORD] = (hy & 0xfffff) | 0x41600000;
 140                 ((int *)&w)[LOWORD] = ((int *)&y)[LOWORD];
 141                 n = __rem_pio2m(&w, &y, n, 1, 0, _TBL_ipio2_inf);

 142                 if (hy < 0) {
 143                         y = -y;
 144                         n = -n;
 145                 }
 146         }
 147 
 148         hy = ((int *)&y)[HIWORD] & ~0x80000000;

 149         if (hy < 0x3f800000) {               /* |y| < 2**-7 */
 150                 z = (y * T0) * (T1 + y * y);
 151                 f = ((n & 1) == 0)? (float)z : (float)(-one / z);
 152                 return (f);
 153         }

 154         z = y * y;
 155         w = ((P0 * y) * (P1 + z * (P2 + z)) * (P3 + z * (P4 + z))) *
 156             (P5 + z * (P6 + z * (P7 + z)));
 157         f = ((n & 1) == 0)? (float)w : (float)(-one / w);
 158         return (f);
 159 }
   1 /*
   2  * CDDL HEADER START
   3  *
   4  * The contents of this file are subject to the terms of the
   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 
  22 /*
  23  * Copyright 2011 Nexenta Systems, Inc.  All rights reserved.
  24  */
  25 
  26 /*
  27  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
  28  * Use is subject to license terms.
  29  */
  30 
  31 #pragma weak __tanf = tanf
  32 
  33 #include "libm.h"
  34 
  35 extern const int _TBL_ipio2_inf[];
  36 extern int __rem_pio2m(double *, double *, int, int, int, const int *);
  37 
  38 #if defined(__i386) && !defined(__amd64)
  39 extern int __swapRP(int);
  40 #endif
  41 
  42 static const double C[] = {
  43         1.0,
  44         4.46066928428959230679140546271810308098793029785e-0003,
  45         4.92165316309189027066395283327437937259674072266e+0000,
  46         -7.11410648161473480044492134766187518835067749023e-0001,
  47         4.08549808374053391446523164631798863410949707031e+0000,
  48         2.50411070398050927821032018982805311679840087891e+0000,
  49         1.11492064560251158411574579076841473579406738281e+0001,
  50         -1.50565540968422650891511693771462887525558471680e+0000,
  51         -1.81484378878349295050043110677506774663925170898e+0000,
  52         3.333335997532835641297409611782510896641e-0001,
  53         2.999997598248363761541668282006867229939e+00,
  54         0.636619772367581343075535,     /* 2^ -1  * 1.45F306DC9C883 */
  55         0.5,
  56         1.570796326734125614166,        /* 2^  0  * 1.921FB54400000 */
  57         6.077100506506192601475e-11,    /* 2^-34  * 1.0B4611A626331 */


  79         double y, z, w;
  80         float f;
  81         int n, ix, hx, hy;
  82         volatile int i __unused;
  83 
  84         hx = *((int *)&x);
  85         ix = hx & 0x7fffffff;
  86 
  87         y = (double)x;
  88 
  89         if (ix <= 0x4016cbe4) {                              /* |x| < 3*pi/4 */
  90                 if (ix <= 0x3f490fdb) {                      /* |x| < pi/4 */
  91                         if (ix < 0x3c000000) {               /* |x| < 2**-7 */
  92                                 if (ix <= 0x39800000) {      /* |x| < 2**-12 */
  93                                         i = (int)y;
  94 #ifdef lint
  95                                         i = i;
  96 #endif
  97                                         return (x);
  98                                 }
  99 
 100                                 return ((float)((y * T0) * (T1 + y * y)));
 101                         }
 102 
 103                         z = y * y;
 104                         return ((float)(((P0 * y) * (P1 + z * (P2 + z)) * (P3 +
 105                             z * (P4 + z))) * (P5 + z * (P6 + z *
 106                             (P7 + z)))));
 107                 }
 108 
 109                 if (hx > 0)
 110                         y = (y - pio2_1) - pio2_t;
 111                 else
 112                         y = (y + pio2_1) + pio2_t;
 113 
 114                 hy = ((int *)&y)[HIWORD] & ~0x80000000;
 115 
 116                 if (hy < 0x3f800000) {       /* |y| < 2**-7 */
 117                         z = (y * T0) * (T1 + y * y);
 118                         return ((float)(-one / z));
 119                 }
 120 
 121                 z = y * y;
 122                 w = ((P0 * y) * (P1 + z * (P2 + z)) * (P3 + z * (P4 + z))) *
 123                     (P5 + z * (P6 + z * (P7 + z)));
 124                 return ((float)(-one / w));
 125         }
 126 
 127         if (ix <= 0x49c90fdb) {              /* |x| < 2^19*pi */
 128 #if defined(__i386) && !defined(__amd64)
 129                 int rp;
 130 
 131                 rp = __swapRP(fp_extended);
 132 #endif
 133                 w = y * invpio2;
 134 
 135                 if (hx < 0)
 136                         n = (int)(w - half);
 137                 else
 138                         n = (int)(w + half);
 139 
 140                 y = (y - n * pio2_1) - n * pio2_t;
 141 #if defined(__i386) && !defined(__amd64)
 142                 if (rp != fp_extended)
 143                         (void) __swapRP(rp);
 144 #endif
 145         } else {
 146                 if (ix >= 0x7f800000)
 147                         return (x / x);         /* sin(Inf or NaN) is NaN */
 148 
 149                 hy = ((int *)&y)[HIWORD];
 150                 n = ((hy >> 20) & 0x7ff) - 1046;
 151                 ((int *)&w)[HIWORD] = (hy & 0xfffff) | 0x41600000;
 152                 ((int *)&w)[LOWORD] = ((int *)&y)[LOWORD];
 153                 n = __rem_pio2m(&w, &y, n, 1, 0, _TBL_ipio2_inf);
 154 
 155                 if (hy < 0) {
 156                         y = -y;
 157                         n = -n;
 158                 }
 159         }
 160 
 161         hy = ((int *)&y)[HIWORD] & ~0x80000000;
 162 
 163         if (hy < 0x3f800000) {               /* |y| < 2**-7 */
 164                 z = (y * T0) * (T1 + y * y);
 165                 f = ((n & 1) == 0) ? (float)z : (float)(-one / z);
 166                 return (f);
 167         }
 168 
 169         z = y * y;
 170         w = ((P0 * y) * (P1 + z * (P2 + z)) * (P3 + z * (P4 + z))) * (P5 + z *
 171             (P6 + z * (P7 + z)));
 172         f = ((n & 1) == 0) ? (float)w : (float)(-one / w);
 173         return (f);
 174 }