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