/[jscoverage]/trunk/js/src/fdlibm/e_asin.c
ViewVC logotype

Annotation of /trunk/js/src/fdlibm/e_asin.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2 - (hide annotations)
Wed Aug 1 13:51:53 2007 UTC (14 years, 11 months ago) by siliconforks
File MIME type: text/plain
File size: 5437 byte(s)
Initial import.

1 siliconforks 2 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2     *
3     * ***** BEGIN LICENSE BLOCK *****
4     * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5     *
6     * The contents of this file are subject to the Mozilla Public License Version
7     * 1.1 (the "License"); you may not use this file except in compliance with
8     * the License. You may obtain a copy of the License at
9     * http://www.mozilla.org/MPL/
10     *
11     * Software distributed under the License is distributed on an "AS IS" basis,
12     * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13     * for the specific language governing rights and limitations under the
14     * License.
15     *
16     * The Original Code is Mozilla Communicator client code, released
17     * March 31, 1998.
18     *
19     * The Initial Developer of the Original Code is
20     * Sun Microsystems, Inc.
21     * Portions created by the Initial Developer are Copyright (C) 1998
22     * the Initial Developer. All Rights Reserved.
23     *
24     * Contributor(s):
25     *
26     * Alternatively, the contents of this file may be used under the terms of
27     * either of the GNU General Public License Version 2 or later (the "GPL"),
28     * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29     * in which case the provisions of the GPL or the LGPL are applicable instead
30     * of those above. If you wish to allow use of your version of this file only
31     * under the terms of either the GPL or the LGPL, and not to allow others to
32     * use your version of this file under the terms of the MPL, indicate your
33     * decision by deleting the provisions above and replace them with the notice
34     * and other provisions required by the GPL or the LGPL. If you do not delete
35     * the provisions above, a recipient may use your version of this file under
36     * the terms of any one of the MPL, the GPL or the LGPL.
37     *
38     * ***** END LICENSE BLOCK ***** */
39    
40     /* @(#)e_asin.c 1.3 95/01/18 */
41     /*
42     * ====================================================
43     * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
44     *
45     * Developed at SunSoft, a Sun Microsystems, Inc. business.
46     * Permission to use, copy, modify, and distribute this
47     * software is freely granted, provided that this notice
48     * is preserved.
49     * ====================================================
50     */
51    
52     /* __ieee754_asin(x)
53     * Method :
54     * Since asin(x) = x + x^3/6 + x^5*3/40 + x^7*15/336 + ...
55     * we approximate asin(x) on [0,0.5] by
56     * asin(x) = x + x*x^2*R(x^2)
57     * where
58     * R(x^2) is a rational approximation of (asin(x)-x)/x^3
59     * and its remez error is bounded by
60     * |(asin(x)-x)/x^3 - R(x^2)| < 2^(-58.75)
61     *
62     * For x in [0.5,1]
63     * asin(x) = pi/2-2*asin(sqrt((1-x)/2))
64     * Let y = (1-x), z = y/2, s := sqrt(z), and pio2_hi+pio2_lo=pi/2;
65     * then for x>0.98
66     * asin(x) = pi/2 - 2*(s+s*z*R(z))
67     * = pio2_hi - (2*(s+s*z*R(z)) - pio2_lo)
68     * For x<=0.98, let pio4_hi = pio2_hi/2, then
69     * f = hi part of s;
70     * c = sqrt(z) - f = (z-f*f)/(s+f) ...f+c=sqrt(z)
71     * and
72     * asin(x) = pi/2 - 2*(s+s*z*R(z))
73     * = pio4_hi+(pio4-2s)-(2s*z*R(z)-pio2_lo)
74     * = pio4_hi+(pio4-2f)-(2s*z*R(z)-(pio2_lo+2c))
75     *
76     * Special cases:
77     * if x is NaN, return x itself;
78     * if |x|>1, return NaN with invalid signal.
79     *
80     */
81    
82    
83     #include "fdlibm.h"
84    
85     #ifdef __STDC__
86     static const double
87     #else
88     static double
89     #endif
90     one = 1.00000000000000000000e+00, /* 0x3FF00000, 0x00000000 */
91     really_big = 1.000e+300,
92     pio2_hi = 1.57079632679489655800e+00, /* 0x3FF921FB, 0x54442D18 */
93     pio2_lo = 6.12323399573676603587e-17, /* 0x3C91A626, 0x33145C07 */
94     pio4_hi = 7.85398163397448278999e-01, /* 0x3FE921FB, 0x54442D18 */
95     /* coefficient for R(x^2) */
96     pS0 = 1.66666666666666657415e-01, /* 0x3FC55555, 0x55555555 */
97     pS1 = -3.25565818622400915405e-01, /* 0xBFD4D612, 0x03EB6F7D */
98     pS2 = 2.01212532134862925881e-01, /* 0x3FC9C155, 0x0E884455 */
99     pS3 = -4.00555345006794114027e-02, /* 0xBFA48228, 0xB5688F3B */
100     pS4 = 7.91534994289814532176e-04, /* 0x3F49EFE0, 0x7501B288 */
101     pS5 = 3.47933107596021167570e-05, /* 0x3F023DE1, 0x0DFDF709 */
102     qS1 = -2.40339491173441421878e+00, /* 0xC0033A27, 0x1C8A2D4B */
103     qS2 = 2.02094576023350569471e+00, /* 0x40002AE5, 0x9C598AC8 */
104     qS3 = -6.88283971605453293030e-01, /* 0xBFE6066C, 0x1B8D0159 */
105     qS4 = 7.70381505559019352791e-02; /* 0x3FB3B8C5, 0xB12E9282 */
106    
107     #ifdef __STDC__
108     double __ieee754_asin(double x)
109     #else
110     double __ieee754_asin(x)
111     double x;
112     #endif
113     {
114     fd_twoints u;
115     double w,t,p,q,c,r,s;
116     int hx,ix;
117     u.d = x;
118     hx = __HI(u);
119     x = u.d;
120     ix = hx&0x7fffffff;
121     if(ix>= 0x3ff00000) { /* |x|>= 1 */
122     if(((ix-0x3ff00000)|__LO(u))==0)
123     /* asin(1)=+-pi/2 with inexact */
124     return x*pio2_hi+x*pio2_lo;
125     return (x-x)/(x-x); /* asin(|x|>1) is NaN */
126     } else if (ix<0x3fe00000) { /* |x|<0.5 */
127     if(ix<0x3e400000) { /* if |x| < 2**-27 */
128     if(really_big+x>one) return x;/* return x with inexact if x!=0*/
129     } else
130     t = x*x;
131     p = t*(pS0+t*(pS1+t*(pS2+t*(pS3+t*(pS4+t*pS5)))));
132     q = one+t*(qS1+t*(qS2+t*(qS3+t*qS4)));
133     w = p/q;
134     return x+x*w;
135     }
136     /* 1> |x|>= 0.5 */
137     w = one-fd_fabs(x);
138     t = w*0.5;
139     p = t*(pS0+t*(pS1+t*(pS2+t*(pS3+t*(pS4+t*pS5)))));
140     q = one+t*(qS1+t*(qS2+t*(qS3+t*qS4)));
141     s = fd_sqrt(t);
142     if(ix>=0x3FEF3333) { /* if |x| > 0.975 */
143     w = p/q;
144     t = pio2_hi-(2.0*(s+s*w)-pio2_lo);
145     } else {
146     u.d = s;
147     __LO(u) = 0;
148     w = u.d;
149     c = (t-w*w)/(s+w);
150     r = p/q;
151     p = 2.0*s*r-(pio2_lo-2.0*c);
152     q = pio4_hi-2.0*w;
153     t = pio4_hi-(p-q);
154     }
155     if(hx>0) return t; else return -t;
156     }

  ViewVC Help
Powered by ViewVC 1.1.24