1
2 /* @(#)e_asin.c 1.3 95/01/18 */
3 /* FreeBSD: head/lib/msun/src/e_asin.c 176451 2008-02-22 02:30:36Z das */
4 /*
5 * ====================================================
6 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
7 *
8 * Developed at SunSoft, a Sun Microsystems, Inc. business.
9 * Permission to use, copy, modify, and distribute this
10 * software is freely granted, provided that this notice
11 * is preserved.
12 * ====================================================
13 */
14
15 //__FBSDID("$FreeBSD: src/lib/msun/src/e_asinl.c,v 1.2 2008/08/03 17:49:05 das Exp $");
16
17 /*
18 * See comments in e_asin.c.
19 * Converted to long double by David Schultz <das@FreeBSD.ORG>.
20 */
21
22
23 #include "invtrig.h"
24
25 static const long double
26 one = 1.00000000000000000000e+00L,
27 huge = 1.000e+300L;
28
29 long double
asinl(long double x)30 asinl(long double x)
31 {
32 union IEEEl2bits u;
33 long double t=0.0L,w,p,q,c,r,s;
34 int16_t expsign, expt;
35 u.e = x;
36 expsign = u.xbits.expsign;
37 expt = expsign & 0x7fff;
38 if(expt >= BIAS) { /* |x|>= 1 */
39 if(expt==BIAS && ((u.bits.manh&~LDBL_NBIT)|u.bits.manl)==0)
40 /* asin(1)=+-pi/2 with inexact */
41 return x*pio2_hi+x*pio2_lo;
42 return __math_invalidl(x); /* asin(|x|>1) is NaN */
43 } else if (expt<BIAS-1) { /* |x|<0.5 */
44 if(expt<ASIN_LINEAR) { /* if |x| is small, asinl(x)=x */
45 if(huge+x>one) return x;/* return x with inexact if x!=0*/
46 }
47 t = x*x;
48 p = P(t);
49 q = Q(t);
50 w = p/q;
51 return x+x*w;
52 }
53 /* 1> |x|>= 0.5 */
54 w = one-fabsl(x);
55 t = w*0.5L;
56 p = P(t);
57 q = Q(t);
58 s = sqrtl(t);
59 if(u.bits.manh>=THRESH) { /* if |x| is close to 1 */
60 w = p/q;
61 t = pio2_hi-(2.0L*(s+s*w)-pio2_lo);
62 } else {
63 u.e = s;
64 u.bits.manl = 0;
65 w = u.e;
66 c = (t-w*w)/(s+w);
67 r = p/q;
68 p = 2.0L*s*r-(pio2_lo-2.0L*c);
69 q = pio4_hi-2.0L*w;
70 t = pio4_hi-(p-q);
71 }
72 if(expsign>0) return t; else return -t;
73 }
74