e_acosf.c revision 2116
11558Srgrimes/* e_acosf.c -- float version of e_acos.c.
21558Srgrimes * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
31558Srgrimes */
41558Srgrimes
51558Srgrimes/*
61558Srgrimes * ====================================================
71558Srgrimes * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
81558Srgrimes *
91558Srgrimes * Developed at SunPro, a Sun Microsystems, Inc. business.
101558Srgrimes * Permission to use, copy, modify, and distribute this
111558Srgrimes * software is freely granted, provided that this notice
121558Srgrimes * is preserved.
131558Srgrimes * ====================================================
141558Srgrimes */
151558Srgrimes
161558Srgrimes#ifndef lint
171558Srgrimesstatic char rcsid[] = "$Id: e_acosf.c,v 1.2 1994/08/18 23:04:53 jtc Exp $";
181558Srgrimes#endif
191558Srgrimes
201558Srgrimes#include "math.h"
211558Srgrimes#include "math_private.h"
221558Srgrimes
231558Srgrimes#ifdef __STDC__
241558Srgrimesstatic const float
251558Srgrimes#else
261558Srgrimesstatic float
271558Srgrimes#endif
281558Srgrimesone =  1.0000000000e+00, /* 0x3F800000 */
291558Srgrimespi =  3.1415925026e+00, /* 0x40490fda */
301558Srgrimespio2_hi =  1.5707962513e+00, /* 0x3fc90fda */
311558Srgrimespio2_lo =  7.5497894159e-08, /* 0x33a22168 */
321558SrgrimespS0 =  1.6666667163e-01, /* 0x3e2aaaab */
331558SrgrimespS1 = -3.2556581497e-01, /* 0xbea6b090 */
341558SrgrimespS2 =  2.0121252537e-01, /* 0x3e4e0aa8 */
351558SrgrimespS3 = -4.0055535734e-02, /* 0xbd241146 */
3637906ScharnierpS4 =  7.9153501429e-04, /* 0x3a4f7f04 */
3723685SpeterpS5 =  3.4793309169e-05, /* 0x3811ef08 */
3837906ScharnierqS1 = -2.4033949375e+00, /* 0xc019d139 */
391558SrgrimesqS2 =  2.0209457874e+00, /* 0x4001572d */
401558SrgrimesqS3 = -6.8828397989e-01, /* 0xbf303361 */
41146754ScharnierqS4 =  7.7038154006e-02; /* 0x3d9dc62e */
42146754Scharnier
43146754Scharnier#ifdef __STDC__
441558Srgrimes	float __ieee754_acosf(float x)
451558Srgrimes#else
461558Srgrimes	float __ieee754_acosf(x)
471558Srgrimes	float x;
4866907Swollman#endif
49167011Smckusick{
50167011Smckusick	float z,p,q,r,w,s,c,df;
511558Srgrimes	int32_t hx,ix;
52167259Smckusick	GET_FLOAT_WORD(hx,x);
531558Srgrimes	ix = hx&0x7fffffff;
541558Srgrimes	if(ix==0x3f800000) {		/* |x|==1 */
551558Srgrimes	    if(hx>0) return 0.0;	/* acos(1) = 0  */
561558Srgrimes	    else return pi+(float)2.0*pio2_lo;	/* acos(-1)= pi */
57103949Smike	} else if(ix>0x3f800000) {	/* |x| >= 1 */
5873986Sobrien	    return (x-x)/(x-x);		/* acos(|x|>1) is NaN */
591558Srgrimes	}
60164911Sdwmalone	if(ix<0x3f000000) {	/* |x| < 0.5 */
611558Srgrimes	    if(ix<=0x23000000) return pio2_hi+pio2_lo;/*if|x|<2**-57*/
621558Srgrimes	    z = x*x;
631558Srgrimes	    p = z*(pS0+z*(pS1+z*(pS2+z*(pS3+z*(pS4+z*pS5)))));
6466907Swollman	    q = one+z*(qS1+z*(qS2+z*(qS3+z*qS4)));
65129665Sstefanf	    r = p/q;
661558Srgrimes	    return pio2_hi - (x - (pio2_lo-x*r));
671558Srgrimes	} else  if (hx<0) {		/* x < -0.5 */
681558Srgrimes	    z = (one+x)*(float)0.5;
691558Srgrimes	    p = z*(pS0+z*(pS1+z*(pS2+z*(pS3+z*(pS4+z*pS5)))));
701558Srgrimes	    q = one+z*(qS1+z*(qS2+z*(qS3+z*qS4)));
711558Srgrimes	    s = sqrtf(z);
721558Srgrimes	    r = p/q;
731558Srgrimes	    w = r*s-pio2_lo;
74128175Sgreen	    return pi - (float)2.0*(s+w);
75128175Sgreen	} else {			/* x > 0.5 */
7621174Sguido	    int32_t idf;
771558Srgrimes	    z = (one-x)*(float)0.5;
781558Srgrimes	    s = sqrtf(z);
791558Srgrimes	    df = s;
801558Srgrimes	    GET_FLOAT_WORD(idf,df);
81164911Sdwmalone	    SET_FLOAT_WORD(df,idf&0xfffff000);
821558Srgrimes	    c  = (z-df*df)/(s+df);
8398542Smckusick	    p = z*(pS0+z*(pS1+z*(pS2+z*(pS3+z*(pS4+z*pS5)))));
841558Srgrimes	    q = one+z*(qS1+z*(qS2+z*(qS3+z*qS4)));
851558Srgrimes	    r = p/q;
861558Srgrimes	    w = r*s+c;
871558Srgrimes	    return (float)2.0*(df+w);
8898542Smckusick	}
891558Srgrimes}
901558Srgrimes