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