e_acosf.c revision 176451
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 176451 2008-02-22 02:30:36Z 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 */ 252116Sjkhpio2_hi = 1.5707962513e+00, /* 0x3fc90fda */ 262116Sjkhpio2_lo = 7.5497894159e-08, /* 0x33a22168 */ 272116SjkhpS0 = 1.6666667163e-01, /* 0x3e2aaaab */ 282116SjkhpS1 = -3.2556581497e-01, /* 0xbea6b090 */ 292116SjkhpS2 = 2.0121252537e-01, /* 0x3e4e0aa8 */ 302116SjkhpS3 = -4.0055535734e-02, /* 0xbd241146 */ 312116SjkhpS4 = 7.9153501429e-04, /* 0x3a4f7f04 */ 322116SjkhpS5 = 3.4793309169e-05, /* 0x3811ef08 */ 332116SjkhqS1 = -2.4033949375e+00, /* 0xc019d139 */ 342116SjkhqS2 = 2.0209457874e+00, /* 0x4001572d */ 352116SjkhqS3 = -6.8828397989e-01, /* 0xbf303361 */ 362116SjkhqS4 = 7.7038154006e-02; /* 0x3d9dc62e */ 372116Sjkh 3897407Salfredfloat 3997407Salfred__ieee754_acosf(float x) 402116Sjkh{ 412116Sjkh float z,p,q,r,w,s,c,df; 422116Sjkh int32_t hx,ix; 432116Sjkh GET_FLOAT_WORD(hx,x); 442116Sjkh ix = hx&0x7fffffff; 452116Sjkh if(ix==0x3f800000) { /* |x|==1 */ 462116Sjkh if(hx>0) return 0.0; /* acos(1) = 0 */ 472116Sjkh else return pi+(float)2.0*pio2_lo; /* acos(-1)= pi */ 482116Sjkh } else if(ix>0x3f800000) { /* |x| >= 1 */ 492116Sjkh return (x-x)/(x-x); /* acos(|x|>1) is NaN */ 502116Sjkh } 512116Sjkh if(ix<0x3f000000) { /* |x| < 0.5 */ 522116Sjkh if(ix<=0x23000000) return pio2_hi+pio2_lo;/*if|x|<2**-57*/ 532116Sjkh z = x*x; 542116Sjkh p = z*(pS0+z*(pS1+z*(pS2+z*(pS3+z*(pS4+z*pS5))))); 552116Sjkh q = one+z*(qS1+z*(qS2+z*(qS3+z*qS4))); 562116Sjkh r = p/q; 572116Sjkh return pio2_hi - (x - (pio2_lo-x*r)); 582116Sjkh } else if (hx<0) { /* x < -0.5 */ 592116Sjkh z = (one+x)*(float)0.5; 602116Sjkh p = z*(pS0+z*(pS1+z*(pS2+z*(pS3+z*(pS4+z*pS5))))); 612116Sjkh q = one+z*(qS1+z*(qS2+z*(qS3+z*qS4))); 6223579Sbde s = __ieee754_sqrtf(z); 632116Sjkh r = p/q; 642116Sjkh w = r*s-pio2_lo; 652116Sjkh return pi - (float)2.0*(s+w); 662116Sjkh } else { /* x > 0.5 */ 672116Sjkh int32_t idf; 682116Sjkh z = (one-x)*(float)0.5; 6923579Sbde s = __ieee754_sqrtf(z); 702116Sjkh df = s; 712116Sjkh GET_FLOAT_WORD(idf,df); 722116Sjkh SET_FLOAT_WORD(df,idf&0xfffff000); 732116Sjkh c = (z-df*df)/(s+df); 742116Sjkh p = z*(pS0+z*(pS1+z*(pS2+z*(pS3+z*(pS4+z*pS5))))); 752116Sjkh q = one+z*(qS1+z*(qS2+z*(qS3+z*qS4))); 762116Sjkh r = p/q; 772116Sjkh w = r*s+c; 782116Sjkh return (float)2.0*(df+w); 792116Sjkh } 802116Sjkh} 81