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