e_acosf.c revision 181257
12116Sjkh/* e_acosf.c -- float version of e_acos.c. 22116Sjkh * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com. 32116Sjkh */ 42116Sjkh 52116Sjkh/* 62116Sjkh * ==================================================== 72116Sjkh * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. 82116Sjkh * 92116Sjkh * Developed at SunPro, a Sun Microsystems, Inc. business. 102116Sjkh * Permission to use, copy, modify, and distribute this 118870Srgrimes * software is freely granted, provided that this notice 122116Sjkh * is preserved. 132116Sjkh * ==================================================== 142116Sjkh */ 152116Sjkh 16176451Sdas#include <sys/cdefs.h> 17176451Sdas__FBSDID("$FreeBSD: head/lib/msun/src/e_acosf.c 181257 2008-08-03 17:39:54Z das $"); 182116Sjkh 192116Sjkh#include "math.h" 202116Sjkh#include "math_private.h" 212116Sjkh 228870Srgrimesstatic const float 232116Sjkhone = 1.0000000000e+00, /* 0x3F800000 */ 242116Sjkhpi = 3.1415925026e+00, /* 0x40490fda */ 25181062Sdaspio2_hi = 1.5707962513e+00; /* 0x3fc90fda */ 26181062Sdasstatic volatile float 27181062Sdaspio2_lo = 7.5497894159e-08; /* 0x33a22168 */ 28181062Sdasstatic const float 29181100SdaspS0 = 1.6666586697e-01, 30181100SdaspS1 = -4.2743422091e-02, 31181100SdaspS2 = -8.6563630030e-03, 32181100SdasqS1 = -7.0662963390e-01; 332116Sjkh 3497407Salfredfloat 3597407Salfred__ieee754_acosf(float x) 362116Sjkh{ 372116Sjkh float z,p,q,r,w,s,c,df; 382116Sjkh int32_t hx,ix; 392116Sjkh GET_FLOAT_WORD(hx,x); 402116Sjkh ix = hx&0x7fffffff; 41181257Sdas if(ix>=0x3f800000) { /* |x| >= 1 */ 42181257Sdas if(ix==0x3f800000) { /* |x| == 1 */ 43181257Sdas if(hx>0) return 0.0; /* acos(1) = 0 */ 44181257Sdas else return pi+(float)2.0*pio2_lo; /* acos(-1)= pi */ 45181257Sdas } 462116Sjkh return (x-x)/(x-x); /* acos(|x|>1) is NaN */ 472116Sjkh } 482116Sjkh if(ix<0x3f000000) { /* |x| < 0.5 */ 49181100Sdas if(ix<=0x32800000) return pio2_hi+pio2_lo;/*if|x|<2**-26*/ 502116Sjkh z = x*x; 51181100Sdas p = z*(pS0+z*(pS1+z*pS2)); 52181100Sdas q = one+z*qS1; 532116Sjkh r = p/q; 542116Sjkh return pio2_hi - (x - (pio2_lo-x*r)); 552116Sjkh } else if (hx<0) { /* x < -0.5 */ 562116Sjkh z = (one+x)*(float)0.5; 57181100Sdas p = z*(pS0+z*(pS1+z*pS2)); 58181100Sdas q = one+z*qS1; 59181257Sdas s = sqrtf(z); 602116Sjkh r = p/q; 612116Sjkh w = r*s-pio2_lo; 622116Sjkh return pi - (float)2.0*(s+w); 632116Sjkh } else { /* x > 0.5 */ 642116Sjkh int32_t idf; 652116Sjkh z = (one-x)*(float)0.5; 66181257Sdas s = sqrtf(z); 672116Sjkh df = s; 682116Sjkh GET_FLOAT_WORD(idf,df); 692116Sjkh SET_FLOAT_WORD(df,idf&0xfffff000); 702116Sjkh c = (z-df*df)/(s+df); 71181100Sdas p = z*(pS0+z*(pS1+z*pS2)); 72181100Sdas q = one+z*qS1; 732116Sjkh r = p/q; 742116Sjkh w = r*s+c; 752116Sjkh return (float)2.0*(df+w); 762116Sjkh } 772116Sjkh} 78