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 __sinf = sinf
  30 
  31 /*
  32  * See sincosf.c
  33  */
  34 
  35 #include "libm.h"
  36 
  37 extern const int _TBL_ipio2_inf[];
  38 extern int __rem_pio2m(double *, double *, int, int, int, const int *);

  39 #if defined(__i386) && !defined(__amd64)
  40 extern int __swapRP(int);
  41 #endif
  42 
  43 static const double C[] = {
  44         1.85735322054308378716204874632872525989806770558e-0003,
  45         -1.95035094218403635082921458859320791358115801259e-0004,
  46         5.38400550766074785970952495168558701485841707252e+0002,
  47         -3.31975110777873728964197739157371509422022905947e+0001,
  48         1.09349482127188401868272000389539985058873853699e-0003,
  49         -5.03324285989964979398034700054920226866107675091e-0004,
  50         2.43792880266971107750418061559602239831538067410e-0005,
  51         9.14499072605666582228127405245558035523741471271e+0002,
  52         -3.63151270591815439197122504991683846785293207730e+0001,
  53         0.636619772367581343075535,     /* 2^ -1  * 1.45F306DC9C883 */
  54         0.5,
  55         1.570796326734125614166,        /* 2^  0  * 1.921FB54400000 */
  56         6.077100506506192601475e-11,    /* 2^-34  * 1.0B4611A626331 */
  57 };
  58 


  75 {
  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 <= 0x39800000) {      /* |x| <= 2**-12 */
  89                                 i = (int)y;
  90 #ifdef lint
  91                                 i = i;
  92 #endif
  93                                 return (x);
  94                         }

  95                         z = y * y;
  96                         return ((float)((y * (S0 + z * S1)) *
  97                             (S2 + z * (S3 + z))));
  98                 } else if (hx > 0) {
  99                         y = (y - pio2_1) - pio2_t;
 100                         z = y * y;
 101                         return ((float)(((C0 + z * C1) + (z * z) * C2) *
 102                             (C3 + z * (C4 + z))));
 103                 } else {
 104                         y = (y + pio2_1) + pio2_t;
 105                         z = y * y;
 106                         return ((float)-(((C0 + z * C1) + (z * z) * C2) *
 107                             (C3 + z * (C4 + z))));
 108                 }
 109         } else if (ix <= 0x49c90fdb) {       /* |x| < 2^19*pi */
 110 #if defined(__i386) && !defined(__amd64)
 111                 int     rp;
 112 
 113                 rp = __swapRP(fp_extended);
 114 #endif
 115                 w = y * invpio2;

 116                 if (hx < 0)
 117                         n = (int)(w - half);
 118                 else
 119                         n = (int)(w + half);

 120                 y = (y - n * pio2_1) - n * pio2_t;
 121 #if defined(__i386) && !defined(__amd64)
 122                 if (rp != fp_extended)
 123                         (void) __swapRP(rp);
 124 #endif
 125         } else {
 126                 if (ix >= 0x7f800000)
 127                         return (x / x); /* sin(Inf or NaN) is NaN */

 128                 hy = ((int *)&y)[HIWORD];
 129                 n = ((hy >> 20) & 0x7ff) - 1046;
 130                 ((int *)&w)[HIWORD] = (hy & 0xfffff) | 0x41600000;
 131                 ((int *)&w)[LOWORD] = ((int *)&y)[LOWORD];
 132                 n = __rem_pio2m(&w, &y, n, 1, 0, _TBL_ipio2_inf);

 133                 if (hy < 0) {
 134                         y = -y;
 135                         n = -n;
 136                 }
 137         }
 138 
 139         if (n & 1) {
 140                 /* compute cos y */
 141                 z = y * y;
 142                 f = (float)(((C0 + z * C1) + (z * z) * C2) *
 143                     (C3 + z * (C4 + z)));
 144         } else {
 145                 /* compute sin y */
 146                 z = y * y;
 147                 f = (float)((y * (S0 + z * S1)) * (S2 + z * (S3 + z)));
 148         }
 149 
 150         return ((n & 2)? -f : f);
 151 }
   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 __sinf = sinf
  32 
  33 /*
  34  * See sincosf.c
  35  */
  36 
  37 #include "libm.h"
  38 
  39 extern const int _TBL_ipio2_inf[];
  40 extern int __rem_pio2m(double *, double *, int, int, int, const int *);
  41 
  42 #if defined(__i386) && !defined(__amd64)
  43 extern int __swapRP(int);
  44 #endif
  45 
  46 static const double C[] = {
  47         1.85735322054308378716204874632872525989806770558e-0003,
  48         -1.95035094218403635082921458859320791358115801259e-0004,
  49         5.38400550766074785970952495168558701485841707252e+0002,
  50         -3.31975110777873728964197739157371509422022905947e+0001,
  51         1.09349482127188401868272000389539985058873853699e-0003,
  52         -5.03324285989964979398034700054920226866107675091e-0004,
  53         2.43792880266971107750418061559602239831538067410e-0005,
  54         9.14499072605666582228127405245558035523741471271e+0002,
  55         -3.63151270591815439197122504991683846785293207730e+0001,
  56         0.636619772367581343075535,     /* 2^ -1  * 1.45F306DC9C883 */
  57         0.5,
  58         1.570796326734125614166,        /* 2^  0  * 1.921FB54400000 */
  59         6.077100506506192601475e-11,    /* 2^-34  * 1.0B4611A626331 */
  60 };
  61 


  78 {
  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 <= 0x39800000) {      /* |x| <= 2**-12 */
  92                                 i = (int)y;
  93 #ifdef lint
  94                                 i = i;
  95 #endif
  96                                 return (x);
  97                         }
  98 
  99                         z = y * y;
 100                         return ((float)((y * (S0 + z * S1)) * (S2 + z *
 101                             (S3 + z))));
 102                 } else if (hx > 0) {
 103                         y = (y - pio2_1) - pio2_t;
 104                         z = y * y;
 105                         return ((float)(((C0 + z * C1) + (z * z) * C2) * (C3 +
 106                             z * (C4 + z))));
 107                 } else {
 108                         y = (y + pio2_1) + pio2_t;
 109                         z = y * y;
 110                         return ((float)-(((C0 + z * C1) + (z * z) * C2) * (C3 +
 111                             z * (C4 + z))));
 112                 }
 113         } else if (ix <= 0x49c90fdb) {       /* |x| < 2^19*pi */
 114 #if defined(__i386) && !defined(__amd64)
 115                 int rp;
 116 
 117                 rp = __swapRP(fp_extended);
 118 #endif
 119                 w = y * invpio2;
 120 
 121                 if (hx < 0)
 122                         n = (int)(w - half);
 123                 else
 124                         n = (int)(w + half);
 125 
 126                 y = (y - n * pio2_1) - n * pio2_t;
 127 #if defined(__i386) && !defined(__amd64)
 128                 if (rp != fp_extended)
 129                         (void) __swapRP(rp);
 130 #endif
 131         } else {
 132                 if (ix >= 0x7f800000)
 133                         return (x / x);         /* sin(Inf or NaN) is NaN */
 134 
 135                 hy = ((int *)&y)[HIWORD];
 136                 n = ((hy >> 20) & 0x7ff) - 1046;
 137                 ((int *)&w)[HIWORD] = (hy & 0xfffff) | 0x41600000;
 138                 ((int *)&w)[LOWORD] = ((int *)&y)[LOWORD];
 139                 n = __rem_pio2m(&w, &y, n, 1, 0, _TBL_ipio2_inf);
 140 
 141                 if (hy < 0) {
 142                         y = -y;
 143                         n = -n;
 144                 }
 145         }
 146 
 147         if (n & 1) {
 148                 /* compute cos y */
 149                 z = y * y;
 150                 f = (float)(((C0 + z * C1) + (z * z) * C2) * (C3 + z * (C4 +
 151                     z)));
 152         } else {
 153                 /* compute sin y */
 154                 z = y * y;
 155                 f = (float)((y * (S0 + z * S1)) * (S2 + z * (S3 + z)));
 156         }
 157 
 158         return ((n & 2) ? -f : f);
 159 }