e_asinl.c revision 256281
1185377Ssam 2187831Ssam/* @(#)e_asin.c 1.3 95/01/18 */ 3185377Ssam/* FreeBSD: head/lib/msun/src/e_asin.c 176451 2008-02-22 02:30:36Z das */ 4185377Ssam/* 5185377Ssam * ==================================================== 6185377Ssam * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. 7185377Ssam * 8185377Ssam * Developed at SunSoft, a Sun Microsystems, Inc. business. 9185377Ssam * Permission to use, copy, modify, and distribute this 10185377Ssam * software is freely granted, provided that this notice 11185377Ssam * is preserved. 12185377Ssam * ==================================================== 13185377Ssam */ 14185377Ssam 15185377Ssam#include <sys/cdefs.h> 16185377Ssam__FBSDID("$FreeBSD: stable/10/lib/msun/src/e_asinl.c 181258 2008-08-03 17:49:05Z das $"); 17185377Ssam 18187345Ssam/* 19185377Ssam * See comments in e_asin.c. 20185377Ssam * Converted to long double by David Schultz <das@FreeBSD.ORG>. 21185377Ssam */ 22185377Ssam 23187831Ssam#include <float.h> 24187831Ssam 25187831Ssam#include "invtrig.h" 26187831Ssam#include "math.h" 27185377Ssam#include "math_private.h" 28185377Ssam 29185377Ssamstatic const long double 30185377Ssamone = 1.00000000000000000000e+00, 31219394Sadrianhuge = 1.000e+300; 32219394Sadrian 33185377Ssamlong double 34185377Ssamasinl(long double x) 35185377Ssam{ 36185377Ssam union IEEEl2bits u; 37185377Ssam long double t=0.0,w,p,q,c,r,s; 38185377Ssam int16_t expsign, expt; 39185377Ssam u.e = x; 40185377Ssam expsign = u.xbits.expsign; 41185377Ssam expt = expsign & 0x7fff; 42185377Ssam if(expt >= BIAS) { /* |x|>= 1 */ 43185377Ssam if(expt==BIAS && ((u.bits.manh&~LDBL_NBIT)|u.bits.manl)==0) 44185380Ssam /* asin(1)=+-pi/2 with inexact */ 45185380Ssam return x*pio2_hi+x*pio2_lo; 46185377Ssam return (x-x)/(x-x); /* asin(|x|>1) is NaN */ 47185377Ssam } else if (expt<BIAS-1) { /* |x|<0.5 */ 48185380Ssam if(expt<ASIN_LINEAR) { /* if |x| is small, asinl(x)=x */ 49185380Ssam if(huge+x>one) return x;/* return x with inexact if x!=0*/ 50185377Ssam } 51185377Ssam t = x*x; 52185377Ssam p = P(t); 53185377Ssam q = Q(t); 54219442Sadrian w = p/q; 55185377Ssam return x+x*w; 56185377Ssam } 57185377Ssam /* 1> |x|>= 0.5 */ 58185377Ssam w = one-fabsl(x); 59185377Ssam t = w*0.5; 60185377Ssam p = P(t); 61185377Ssam q = Q(t); 62185377Ssam s = sqrtl(t); 63219442Sadrian if(u.bits.manh>=THRESH) { /* if |x| is close to 1 */ 64185377Ssam w = p/q; 65185377Ssam t = pio2_hi-(2.0*(s+s*w)-pio2_lo); 66185380Ssam } else { 67185377Ssam u.e = s; 68185377Ssam u.bits.manl = 0; 69185377Ssam w = u.e; 70185377Ssam c = (t-w*w)/(s+w); 71185377Ssam r = p/q; 72185377Ssam p = 2.0*s*r-(pio2_lo-2.0*c); 73185377Ssam q = pio4_hi-2.0*w; 74185380Ssam t = pio4_hi-(p-q); 75219442Sadrian } 76219442Sadrian if(expsign>0) return t; else return -t; 77185380Ssam} 78219442Sadrian