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