1 /*
2 * Copyright (c) 1998, 2001, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
79 qS4 = 7.70381505559019352791e-02; /* 0x3FB3B8C5, 0xB12E9282 */
80
81 #ifdef __STDC__
82 double __ieee754_asin(double x)
83 #else
84 double __ieee754_asin(x)
85 double x;
86 #endif
87 {
88 double t=0,w,p,q,c,r,s;
89 int hx,ix;
90 hx = __HI(x);
91 ix = hx&0x7fffffff;
92 if(ix>= 0x3ff00000) { /* |x|>= 1 */
93 if(((ix-0x3ff00000)|__LO(x))==0)
94 /* asin(1)=+-pi/2 with inexact */
95 return x*pio2_hi+x*pio2_lo;
96 return (x-x)/(x-x); /* asin(|x|>1) is NaN */
97 } else if (ix<0x3fe00000) { /* |x|<0.5 */
98 if(ix<0x3e400000) { /* if |x| < 2**-27 */
99 if(huge+x>one) return x;/* return x with inexact if x!=0*/
100 } else
101 t = x*x;
102 p = t*(pS0+t*(pS1+t*(pS2+t*(pS3+t*(pS4+t*pS5)))));
103 q = one+t*(qS1+t*(qS2+t*(qS3+t*qS4)));
104 w = p/q;
105 return x+x*w;
106 }
107 /* 1> |x|>= 0.5 */
108 w = one-fabs(x);
109 t = w*0.5;
110 p = t*(pS0+t*(pS1+t*(pS2+t*(pS3+t*(pS4+t*pS5)))));
111 q = one+t*(qS1+t*(qS2+t*(qS3+t*qS4)));
112 s = sqrt(t);
113 if(ix>=0x3FEF3333) { /* if |x| > 0.975 */
114 w = p/q;
115 t = pio2_hi-(2.0*(s+s*w)-pio2_lo);
116 } else {
117 w = s;
118 __LO(w) = 0;
119 c = (t-w*w)/(s+w);
120 r = p/q;
121 p = 2.0*s*r-(pio2_lo-2.0*c);
|
1 /*
2 * Copyright (c) 1998, 2016, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
79 qS4 = 7.70381505559019352791e-02; /* 0x3FB3B8C5, 0xB12E9282 */
80
81 #ifdef __STDC__
82 double __ieee754_asin(double x)
83 #else
84 double __ieee754_asin(x)
85 double x;
86 #endif
87 {
88 double t=0,w,p,q,c,r,s;
89 int hx,ix;
90 hx = __HI(x);
91 ix = hx&0x7fffffff;
92 if(ix>= 0x3ff00000) { /* |x|>= 1 */
93 if(((ix-0x3ff00000)|__LO(x))==0)
94 /* asin(1)=+-pi/2 with inexact */
95 return x*pio2_hi+x*pio2_lo;
96 return (x-x)/(x-x); /* asin(|x|>1) is NaN */
97 } else if (ix<0x3fe00000) { /* |x|<0.5 */
98 if(ix<0x3e400000) { /* if |x| < 2**-27 */
99 if (huge+x>one) {
100 return x;/* return x with inexact if x!=0*/
101 }
102 // Never reached. If so, t=0 will result in returning x
103 // which is correct for |x| < 2**-27.
104 } else {
105 t = x*x;
106 }
107 p = t*(pS0+t*(pS1+t*(pS2+t*(pS3+t*(pS4+t*pS5)))));
108 q = one+t*(qS1+t*(qS2+t*(qS3+t*qS4)));
109 w = p/q;
110 return x+x*w;
111 }
112 /* 1> |x|>= 0.5 */
113 w = one-fabs(x);
114 t = w*0.5;
115 p = t*(pS0+t*(pS1+t*(pS2+t*(pS3+t*(pS4+t*pS5)))));
116 q = one+t*(qS1+t*(qS2+t*(qS3+t*qS4)));
117 s = sqrt(t);
118 if(ix>=0x3FEF3333) { /* if |x| > 0.975 */
119 w = p/q;
120 t = pio2_hi-(2.0*(s+s*w)-pio2_lo);
121 } else {
122 w = s;
123 __LO(w) = 0;
124 c = (t-w*w)/(s+w);
125 r = p/q;
126 p = 2.0*s*r-(pio2_lo-2.0*c);
|