xref: /freebsd/lib/msun/src/e_asinl.c (revision e0c4386e7e71d93b0edc0c8fa156263fc4a8b0b6)
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 /*
15  * See comments in e_asin.c.
16  * Converted to long double by David Schultz <das@FreeBSD.ORG>.
17  */
18 
19 #include <float.h>
20 
21 #include "invtrig.h"
22 #include "math.h"
23 #include "math_private.h"
24 
25 static const long double
26 one =  1.00000000000000000000e+00,
27 huge = 1.000e+300;
28 
29 long double
30 asinl(long double x)
31 {
32 	union IEEEl2bits u;
33 	long double t=0.0,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 (x-x)/(x-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.5;
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.0*(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.0*s*r-(pio2_lo-2.0*c);
69 	    q  = pio4_hi-2.0*w;
70 	    t  = pio4_hi-(p-q);
71 	}
72 	if(expsign>0) return t; else return -t;
73 }
74