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