xref: /netbsd-src/lib/libm/src/e_asinf.c (revision 1ca5c1b28139779176bd5c13ad7c5f25c0bcd5f8)
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 #if defined(LIBM_SCCS) && !defined(lint)
18 __RCSID("$NetBSD: e_asinf.c,v 1.7 1999/07/02 15:37:38 simonb Exp $");
19 #endif
20 
21 #include "math.h"
22 #include "math_private.h"
23 
24 #ifdef __STDC__
25 static const float
26 #else
27 static float
28 #endif
29 one =  1.0000000000e+00, /* 0x3F800000 */
30 huge =  1.000e+30,
31 pio2_hi =  1.5707962513e+00, /* 0x3fc90fda */
32 pio2_lo =  7.5497894159e-08, /* 0x33a22168 */
33 pio4_hi =  7.8539818525e-01, /* 0x3f490fdb */
34 	/* coefficient for R(x^2) */
35 pS0 =  1.6666667163e-01, /* 0x3e2aaaab */
36 pS1 = -3.2556581497e-01, /* 0xbea6b090 */
37 pS2 =  2.0121252537e-01, /* 0x3e4e0aa8 */
38 pS3 = -4.0055535734e-02, /* 0xbd241146 */
39 pS4 =  7.9153501429e-04, /* 0x3a4f7f04 */
40 pS5 =  3.4793309169e-05, /* 0x3811ef08 */
41 qS1 = -2.4033949375e+00, /* 0xc019d139 */
42 qS2 =  2.0209457874e+00, /* 0x4001572d */
43 qS3 = -6.8828397989e-01, /* 0xbf303361 */
44 qS4 =  7.7038154006e-02; /* 0x3d9dc62e */
45 
46 #ifdef __STDC__
47 	float __ieee754_asinf(float x)
48 #else
49 	float __ieee754_asinf(x)
50 	float x;
51 #endif
52 {
53 	float t,w,p,q,c,r,s;
54 	int32_t hx,ix;
55 
56 	t = 0;
57 	GET_FLOAT_WORD(hx,x);
58 	ix = hx&0x7fffffff;
59 	if(ix==0x3f800000) {
60 		/* asin(1)=+-pi/2 with inexact */
61 	    return x*pio2_hi+x*pio2_lo;
62 	} else if(ix> 0x3f800000) {	/* |x|>= 1 */
63 	    return (x-x)/(x-x);		/* asin(|x|>1) is NaN */
64 	} else if (ix<0x3f000000) {	/* |x|<0.5 */
65 	    if(ix<0x32000000) {		/* if |x| < 2**-27 */
66 		if(huge+x>one) return x;/* return x with inexact if x!=0*/
67 	    } else
68 		t = x*x;
69 		p = t*(pS0+t*(pS1+t*(pS2+t*(pS3+t*(pS4+t*pS5)))));
70 		q = one+t*(qS1+t*(qS2+t*(qS3+t*qS4)));
71 		w = p/q;
72 		return x+x*w;
73 	}
74 	/* 1> |x|>= 0.5 */
75 	w = one-fabsf(x);
76 	t = w*(float)0.5;
77 	p = t*(pS0+t*(pS1+t*(pS2+t*(pS3+t*(pS4+t*pS5)))));
78 	q = one+t*(qS1+t*(qS2+t*(qS3+t*qS4)));
79 	s = __ieee754_sqrtf(t);
80 	if(ix>=0x3F79999A) { 	/* if |x| > 0.975 */
81 	    w = p/q;
82 	    t = pio2_hi-((float)2.0*(s+s*w)-pio2_lo);
83 	} else {
84 	    int32_t iw;
85 	    w  = s;
86 	    GET_FLOAT_WORD(iw,w);
87 	    SET_FLOAT_WORD(w,iw&0xfffff000);
88 	    c  = (t-w*w)/(s+w);
89 	    r  = p/q;
90 	    p  = (float)2.0*s*r-(pio2_lo-(float)2.0*c);
91 	    q  = pio4_hi-(float)2.0*w;
92 	    t  = pio4_hi-(p-q);
93 	}
94 	if(hx>0) return t; else return -t;
95 }
96