2c47979de619dbaf19618dcdcd9e7b2d8ec5ac56
[dragonfly.git] / lib / msun / src / e_asinf.c
1 /* e_asinf.c -- float version of e_asin.c.
2  * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
3  *
4  * $FreeBSD: src/lib/msun/src/e_asinf.c,v 1.7 1999/08/28 00:06:28 peter Exp $
5  * $DragonFly: src/lib/msun/src/Attic/e_asinf.c,v 1.2 2003/06/17 04:26:52 dillon Exp $
6  */
7
8 /*
9  * ====================================================
10  * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
11  *
12  * Developed at SunPro, a Sun Microsystems, Inc. business.
13  * Permission to use, copy, modify, and distribute this
14  * software is freely granted, provided that this notice
15  * is preserved.
16  * ====================================================
17  */
18
19 #include "math.h"
20 #include "math_private.h"
21
22 #ifdef __STDC__
23 static const float
24 #else
25 static float
26 #endif
27 one =  1.0000000000e+00, /* 0x3F800000 */
28 huge =  1.000e+30,
29 pio2_hi =  1.5707962513e+00, /* 0x3fc90fda */
30 pio2_lo =  7.5497894159e-08, /* 0x33a22168 */
31 pio4_hi =  7.8539818525e-01, /* 0x3f490fdb */
32         /* coefficient for R(x^2) */
33 pS0 =  1.6666667163e-01, /* 0x3e2aaaab */
34 pS1 = -3.2556581497e-01, /* 0xbea6b090 */
35 pS2 =  2.0121252537e-01, /* 0x3e4e0aa8 */
36 pS3 = -4.0055535734e-02, /* 0xbd241146 */
37 pS4 =  7.9153501429e-04, /* 0x3a4f7f04 */
38 pS5 =  3.4793309169e-05, /* 0x3811ef08 */
39 qS1 = -2.4033949375e+00, /* 0xc019d139 */
40 qS2 =  2.0209457874e+00, /* 0x4001572d */
41 qS3 = -6.8828397989e-01, /* 0xbf303361 */
42 qS4 =  7.7038154006e-02; /* 0x3d9dc62e */
43
44 #ifdef __STDC__
45         float __ieee754_asinf(float x)
46 #else
47         float __ieee754_asinf(x)
48         float x;
49 #endif
50 {
51         float t=0.0,w,p,q,c,r,s;
52         int32_t hx,ix;
53         GET_FLOAT_WORD(hx,x);
54         ix = hx&0x7fffffff;
55         if(ix==0x3f800000) {
56                 /* asin(1)=+-pi/2 with inexact */
57             return x*pio2_hi+x*pio2_lo;
58         } else if(ix> 0x3f800000) {     /* |x|>= 1 */
59             return (x-x)/(x-x);         /* asin(|x|>1) is NaN */
60         } else if (ix<0x3f000000) {     /* |x|<0.5 */
61             if(ix<0x32000000) {         /* if |x| < 2**-27 */
62                 if(huge+x>one) return x;/* return x with inexact if x!=0*/
63             } else
64                 t = x*x;
65                 p = t*(pS0+t*(pS1+t*(pS2+t*(pS3+t*(pS4+t*pS5)))));
66                 q = one+t*(qS1+t*(qS2+t*(qS3+t*qS4)));
67                 w = p/q;
68                 return x+x*w;
69         }
70         /* 1> |x|>= 0.5 */
71         w = one-fabsf(x);
72         t = w*(float)0.5;
73         p = t*(pS0+t*(pS1+t*(pS2+t*(pS3+t*(pS4+t*pS5)))));
74         q = one+t*(qS1+t*(qS2+t*(qS3+t*qS4)));
75         s = __ieee754_sqrtf(t);
76         if(ix>=0x3F79999A) {    /* if |x| > 0.975 */
77             w = p/q;
78             t = pio2_hi-((float)2.0*(s+s*w)-pio2_lo);
79         } else {
80             int32_t iw;
81             w  = s;
82             GET_FLOAT_WORD(iw,w);
83             SET_FLOAT_WORD(w,iw&0xfffff000);
84             c  = (t-w*w)/(s+w);
85             r  = p/q;
86             p  = (float)2.0*s*r-(pio2_lo-(float)2.0*c);
87             q  = pio4_hi-(float)2.0*w;
88             t  = pio4_hi-(p-q);
89         }
90         if(hx>0) return t; else return -t;
91 }