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 
16 /*
17  * See comments in e_asin.c.
18  * Converted to long double by David Schultz <das@FreeBSD.ORG>.
19  */
20 
21 
22 #include "invtrig.h"
23 
24 static const long double
25 one =  1.00000000000000000000e+00L,
26 huge = 1.000e+300L;
27 
28 long double
asinl(long double x)29 asinl(long double x)
30 {
31 	union IEEEl2bits u;
32 	long double t=0.0L,w,p,q,c,r,s;
33 	int16_t expsign, expt;
34 	u.e = x;
35 	expsign = u.xbits.expsign;
36 	expt = expsign & 0x7fff;
37 	if(expt >= BIAS) {		/* |x|>= 1 */
38 		if(expt==BIAS && ((u.bits.manh&~LDBL_NBIT)|u.bits.manl)==0)
39 		    /* asin(1)=+-pi/2 with inexact */
40 		    return x*pio2_hi+x*pio2_lo;
41                 return __math_invalidl(x);		/* asin(|x|>1) is NaN */
42 	} else if (expt<BIAS-1) {	/* |x|<0.5 */
43 	    if(expt<ASIN_LINEAR) {	/* if |x| is small, asinl(x)=x */
44 		if(huge+x>one) return x;/* return x with inexact if x!=0*/
45 	    }
46 	    t = x*x;
47 	    p = P(t);
48 	    q = Q(t);
49 	    w = p/q;
50 	    return x+x*w;
51 	}
52 	/* 1> |x|>= 0.5 */
53 	w = one-fabsl(x);
54 	t = w*0.5L;
55 	p = P(t);
56 	q = Q(t);
57 	s = sqrtl(t);
58 	if(u.bits.manh>=THRESH) { 	/* if |x| is close to 1 */
59 	    w = p/q;
60 	    t = pio2_hi-(2.0L*(s+s*w)-pio2_lo);
61 	} else {
62 	    u.e = s;
63 	    u.bits.manl = 0;
64 	    w = u.e;
65 	    c  = (t-w*w)/(s+w);
66 	    r  = p/q;
67 	    p  = 2.0L*s*r-(pio2_lo-2.0L*c);
68 	    q  = pio4_hi-2.0L*w;
69 	    t  = pio4_hi-(p-q);
70 	}
71 	if(expsign>0) return t; else return -t;
72 }
73