diff options
-rw-r--r-- | newlib/ChangeLog | 22 | ||||
-rw-r--r-- | newlib/libm/math/e_pow.c | 314 | ||||
-rw-r--r-- | newlib/libm/math/ef_pow.c | 254 | ||||
-rw-r--r-- | newlib/libm/math/w_acos.c | 118 | ||||
-rw-r--r-- | newlib/libm/math/w_asin.c | 121 | ||||
-rw-r--r-- | newlib/libm/math/w_atan2.c | 90 | ||||
-rw-r--r-- | newlib/libm/math/w_log.c | 116 | ||||
-rw-r--r-- | newlib/libm/math/w_log10.c | 116 | ||||
-rw-r--r-- | newlib/libm/math/w_pow.c | 231 | ||||
-rw-r--r-- | newlib/libm/math/wf_acos.c | 69 | ||||
-rw-r--r-- | newlib/libm/math/wf_asin.c | 71 | ||||
-rw-r--r-- | newlib/libm/math/wf_atan2.c | 46 | ||||
-rw-r--r-- | newlib/libm/math/wf_log.c | 86 | ||||
-rw-r--r-- | newlib/libm/math/wf_log10.c | 89 | ||||
-rw-r--r-- | newlib/libm/math/wf_pow.c | 179 |
15 files changed, 1922 insertions, 0 deletions
diff --git a/newlib/ChangeLog b/newlib/ChangeLog index 64e0a5a3f11..52a28828abe 100644 --- a/newlib/ChangeLog +++ b/newlib/ChangeLog @@ -138,6 +138,12 @@ * libc/include/argz.h: Guard against multiple inclusion. Guard for use with C++. +2007-05-17 Cary R. <cygcary <at> yahoo.com> + + * libm/math/w_atan2.c: Fix atan2 to be consistent with glibc + (atan2(+0,-0), atan2(-0,-0) and atan(-0,+0)) + * libm/math/wf_atan2.c: Ditto. + 2007-05-17 Charles Wilson <cygwin@...> * stdio/tmpfile.c: Include <sys/stat.h>. @@ -182,6 +188,22 @@ * libc/stdio/makebuf.c (__smakebuf_r): Likewise. * libc/stdio/mktemp.c (_gettemp): Likewise. +2007-05-01 Cary R. <cygcary <at> yahoo.com> + + * libm/math/e_pow.c: Fix to be consistent with glibc with regards to + treatment of NaN and +-inf arguments. + * libm/math/ef_pow.c: Ditto. + * libm/math/w_pow.c: Ditto. + * libm/math/wf_pow.c: Ditto. + * libm/math/w_acos.c: Fix domain errors to return NaN. + * libm/math/w_asin.c: Ditto. + * libm/math/wf_acos.c: Ditto. + * libm/math/wf_asin.c: Ditto. + * libm/math/w_log.c: Fix to return NaN for negative number inputs. + * libm/math/wf_log.c: Ditto. + * libm/math/wf_log10.c: Ditto. + * libm/math/w_log10.c: Ditto. + 2007-04-25 Eric Blake <ebb9@byu.net> * libc/stdio/vfprintf.c (get_arg): Support %1$lc. Simplify types diff --git a/newlib/libm/math/e_pow.c b/newlib/libm/math/e_pow.c new file mode 100644 index 00000000000..aac0b421147 --- /dev/null +++ b/newlib/libm/math/e_pow.c @@ -0,0 +1,314 @@ + +/* @(#)e_pow.c 5.1 93/09/24 */ +/* + * ==================================================== + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * + * Developed at SunPro, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + * ==================================================== + */ + +/* __ieee754_pow(x,y) return x**y + * + * n + * Method: Let x = 2 * (1+f) + * 1. Compute and return log2(x) in two pieces: + * log2(x) = w1 + w2, + * where w1 has 53-24 = 29 bit trailing zeros. + * 2. Perform y*log2(x) = n+y' by simulating multi-precision + * arithmetic, where |y'|<=0.5. + * 3. Return x**y = 2**n*exp(y'*log2) + * + * Special cases: + * 1. (anything) ** 0 is 1 + * 2. (anything) ** 1 is itself + * 3a. (anything) ** NAN is NAN except + * 3b. +1 ** NAN is 1 + * 4. NAN ** (anything except 0) is NAN + * 5. +-(|x| > 1) ** +INF is +INF + * 6. +-(|x| > 1) ** -INF is +0 + * 7. +-(|x| < 1) ** +INF is +0 + * 8. +-(|x| < 1) ** -INF is +INF + * 9. +-1 ** +-INF is 1 + * 10. +0 ** (+anything except 0, NAN) is +0 + * 11. -0 ** (+anything except 0, NAN, odd integer) is +0 + * 12. +0 ** (-anything except 0, NAN) is +INF + * 13. -0 ** (-anything except 0, NAN, odd integer) is +INF + * 14. -0 ** (odd integer) = -( +0 ** (odd integer) ) + * 15. +INF ** (+anything except 0,NAN) is +INF + * 16. +INF ** (-anything except 0,NAN) is +0 + * 17. -INF ** (anything) = -0 ** (-anything) + * 18. (-anything) ** (integer) is (-1)**(integer)*(+anything**integer) + * 19. (-anything except 0 and inf) ** (non-integer) is NAN + * + * Accuracy: + * pow(x,y) returns x**y nearly rounded. In particular + * pow(integer,integer) + * always returns the correct integer provided it is + * representable. + * + * Constants : + * The hexadecimal values are the intended ones for the following + * constants. The decimal values may be used, provided that the + * compiler will convert from decimal to binary accurately enough + * to produce the hexadecimal values shown. + */ + +#include "fdlibm.h" + +#ifndef _DOUBLE_IS_32BITS + +#ifdef __STDC__ +static const double +#else +static double +#endif +bp[] = {1.0, 1.5,}, +dp_h[] = { 0.0, 5.84962487220764160156e-01,}, /* 0x3FE2B803, 0x40000000 */ +dp_l[] = { 0.0, 1.35003920212974897128e-08,}, /* 0x3E4CFDEB, 0x43CFD006 */ +zero = 0.0, +one = 1.0, +two = 2.0, +two53 = 9007199254740992.0, /* 0x43400000, 0x00000000 */ +huge = 1.0e300, +tiny = 1.0e-300, + /* poly coefs for (3/2)*(log(x)-2s-2/3*s**3 */ +L1 = 5.99999999999994648725e-01, /* 0x3FE33333, 0x33333303 */ +L2 = 4.28571428578550184252e-01, /* 0x3FDB6DB6, 0xDB6FABFF */ +L3 = 3.33333329818377432918e-01, /* 0x3FD55555, 0x518F264D */ +L4 = 2.72728123808534006489e-01, /* 0x3FD17460, 0xA91D4101 */ +L5 = 2.30660745775561754067e-01, /* 0x3FCD864A, 0x93C9DB65 */ +L6 = 2.06975017800338417784e-01, /* 0x3FCA7E28, 0x4A454EEF */ +P1 = 1.66666666666666019037e-01, /* 0x3FC55555, 0x5555553E */ +P2 = -2.77777777770155933842e-03, /* 0xBF66C16C, 0x16BEBD93 */ +P3 = 6.61375632143793436117e-05, /* 0x3F11566A, 0xAF25DE2C */ +P4 = -1.65339022054652515390e-06, /* 0xBEBBBD41, 0xC5D26BF1 */ +P5 = 4.13813679705723846039e-08, /* 0x3E663769, 0x72BEA4D0 */ +lg2 = 6.93147180559945286227e-01, /* 0x3FE62E42, 0xFEFA39EF */ +lg2_h = 6.93147182464599609375e-01, /* 0x3FE62E43, 0x00000000 */ +lg2_l = -1.90465429995776804525e-09, /* 0xBE205C61, 0x0CA86C39 */ +ovt = 8.0085662595372944372e-0017, /* -(1024-log2(ovfl+.5ulp)) */ +cp = 9.61796693925975554329e-01, /* 0x3FEEC709, 0xDC3A03FD =2/(3ln2) */ +cp_h = 9.61796700954437255859e-01, /* 0x3FEEC709, 0xE0000000 =(float)cp */ +cp_l = -7.02846165095275826516e-09, /* 0xBE3E2FE0, 0x145B01F5 =tail of cp_h*/ +ivln2 = 1.44269504088896338700e+00, /* 0x3FF71547, 0x652B82FE =1/ln2 */ +ivln2_h = 1.44269502162933349609e+00, /* 0x3FF71547, 0x60000000 =24b 1/ln2*/ +ivln2_l = 1.92596299112661746887e-08; /* 0x3E54AE0B, 0xF85DDF44 =1/ln2 tail*/ + +#ifdef __STDC__ + double __ieee754_pow(double x, double y) +#else + double __ieee754_pow(x,y) + double x, y; +#endif +{ + double z,ax,z_h,z_l,p_h,p_l; + double y1,t1,t2,r,s,t,u,v,w; + __int32_t i,j,k,yisint,n; + __int32_t hx,hy,ix,iy; + __uint32_t lx,ly; + + EXTRACT_WORDS(hx,lx,x); + EXTRACT_WORDS(hy,ly,y); + ix = hx&0x7fffffff; iy = hy&0x7fffffff; + + /* y==zero: x**0 = 1 */ + if((iy|ly)==0) return one; + + /* x|y==NaN return NaN unless x==1 then return 1 */ + if(ix > 0x7ff00000 || ((ix==0x7ff00000)&&(lx!=0)) || + iy > 0x7ff00000 || ((iy==0x7ff00000)&&(ly!=0))) + if(((ix-0x3ff00000)|lx)==0) return one; + else return nan(""); + + /* determine if y is an odd int when x < 0 + * yisint = 0 ... y is not an integer + * yisint = 1 ... y is an odd int + * yisint = 2 ... y is an even int + */ + yisint = 0; + if(hx<0) { + if(iy>=0x43400000) yisint = 2; /* even integer y */ + else if(iy>=0x3ff00000) { + k = (iy>>20)-0x3ff; /* exponent */ + if(k>20) { + j = ly>>(52-k); + if((j<<(52-k))==ly) yisint = 2-(j&1); + } else if(ly==0) { + j = iy>>(20-k); + if((j<<(20-k))==iy) yisint = 2-(j&1); + } + } + } + + /* special value of y */ + if(ly==0) { + if (iy==0x7ff00000) { /* y is +-inf */ + if(((ix-0x3ff00000)|lx)==0) + return one; /* +-1**+-inf = 1 */ + else if (ix >= 0x3ff00000)/* (|x|>1)**+-inf = inf,0 */ + return (hy>=0)? y: zero; + else /* (|x|<1)**-,+inf = inf,0 */ + return (hy<0)?-y: zero; + } + if(iy==0x3ff00000) { /* y is +-1 */ + if(hy<0) return one/x; else return x; + } + if(hy==0x40000000) return x*x; /* y is 2 */ + if(hy==0x3fe00000) { /* y is 0.5 */ + if(hx>=0) /* x >= +0 */ + return __ieee754_sqrt(x); + } + } + + ax = fabs(x); + /* special value of x */ + if(lx==0) { + if(ix==0x7ff00000||ix==0||ix==0x3ff00000){ + z = ax; /*x is +-0,+-inf,+-1*/ + if(hy<0) z = one/z; /* z = (1/|x|) */ + if(hx<0) { + if(((ix-0x3ff00000)|yisint)==0) { + z = (z-z)/(z-z); /* (-1)**non-int is NaN */ + } else if(yisint==1) + z = -z; /* (x<0)**odd = -(|x|**odd) */ + } + return z; + } + } + + /* (x<0)**(non-int) is NaN */ + /* REDHAT LOCAL: This used to be + if((((hx>>31)+1)|yisint)==0) return (x-x)/(x-x); + but ANSI C says a right shift of a signed negative quantity is + implementation defined. */ + if(((((__uint32_t)hx>>31)-1)|yisint)==0) return (x-x)/(x-x); + + /* |y| is huge */ + if(iy>0x41e00000) { /* if |y| > 2**31 */ + if(iy>0x43f00000){ /* if |y| > 2**64, must o/uflow */ + if(ix<=0x3fefffff) return (hy<0)? huge*huge:tiny*tiny; + if(ix>=0x3ff00000) return (hy>0)? huge*huge:tiny*tiny; + } + /* over/underflow if x is not close to one */ + if(ix<0x3fefffff) return (hy<0)? huge*huge:tiny*tiny; + if(ix>0x3ff00000) return (hy>0)? huge*huge:tiny*tiny; + /* now |1-x| is tiny <= 2**-20, suffice to compute + log(x) by x-x^2/2+x^3/3-x^4/4 */ + t = ax-1; /* t has 20 trailing zeros */ + w = (t*t)*(0.5-t*(0.3333333333333333333333-t*0.25)); + u = ivln2_h*t; /* ivln2_h has 21 sig. bits */ + v = t*ivln2_l-w*ivln2; + t1 = u+v; + SET_LOW_WORD(t1,0); + t2 = v-(t1-u); + } else { + double s2,s_h,s_l,t_h,t_l; + n = 0; + /* take care subnormal number */ + if(ix<0x00100000) + {ax *= two53; n -= 53; GET_HIGH_WORD(ix,ax); } + n += ((ix)>>20)-0x3ff; + j = ix&0x000fffff; + /* determine interval */ + ix = j|0x3ff00000; /* normalize ix */ + if(j<=0x3988E) k=0; /* |x|<sqrt(3/2) */ + else if(j<0xBB67A) k=1; /* |x|<sqrt(3) */ + else {k=0;n+=1;ix -= 0x00100000;} + SET_HIGH_WORD(ax,ix); + + /* compute s = s_h+s_l = (x-1)/(x+1) or (x-1.5)/(x+1.5) */ + u = ax-bp[k]; /* bp[0]=1.0, bp[1]=1.5 */ + v = one/(ax+bp[k]); + s = u*v; + s_h = s; + SET_LOW_WORD(s_h,0); + /* t_h=ax+bp[k] High */ + t_h = zero; + SET_HIGH_WORD(t_h,((ix>>1)|0x20000000)+0x00080000+(k<<18)); + t_l = ax - (t_h-bp[k]); + s_l = v*((u-s_h*t_h)-s_h*t_l); + /* compute log(ax) */ + s2 = s*s; + r = s2*s2*(L1+s2*(L2+s2*(L3+s2*(L4+s2*(L5+s2*L6))))); + r += s_l*(s_h+s); + s2 = s_h*s_h; + t_h = 3.0+s2+r; + SET_LOW_WORD(t_h,0); + t_l = r-((t_h-3.0)-s2); + /* u+v = s*(1+...) */ + u = s_h*t_h; + v = s_l*t_h+t_l*s; + /* 2/(3log2)*(s+...) */ + p_h = u+v; + SET_LOW_WORD(p_h,0); + p_l = v-(p_h-u); + z_h = cp_h*p_h; /* cp_h+cp_l = 2/(3*log2) */ + z_l = cp_l*p_h+p_l*cp+dp_l[k]; + /* log2(ax) = (s+..)*2/(3*log2) = n + dp_h + z_h + z_l */ + t = (double)n; + t1 = (((z_h+z_l)+dp_h[k])+t); + SET_LOW_WORD(t1,0); + t2 = z_l-(((t1-t)-dp_h[k])-z_h); + } + + s = one; /* s (sign of result -ve**odd) = -1 else = 1 */ + if(((((__uint32_t)hx>>31)-1)|(yisint-1))==0) + s = -one;/* (-ve)**(odd int) */ + + /* split up y into y1+y2 and compute (y1+y2)*(t1+t2) */ + y1 = y; + SET_LOW_WORD(y1,0); + p_l = (y-y1)*t1+y*t2; + p_h = y1*t1; + z = p_l+p_h; + EXTRACT_WORDS(j,i,z); + if (j>=0x40900000) { /* z >= 1024 */ + if(((j-0x40900000)|i)!=0) /* if z > 1024 */ + return s*huge*huge; /* overflow */ + else { + if(p_l+ovt>z-p_h) return s*huge*huge; /* overflow */ + } + } else if((j&0x7fffffff)>=0x4090cc00 ) { /* z <= -1075 */ + if(((j-0xc090cc00)|i)!=0) /* z < -1075 */ + return s*tiny*tiny; /* underflow */ + else { + if(p_l<=z-p_h) return s*tiny*tiny; /* underflow */ + } + } + /* + * compute 2**(p_h+p_l) + */ + i = j&0x7fffffff; + k = (i>>20)-0x3ff; + n = 0; + if(i>0x3fe00000) { /* if |z| > 0.5, set n = [z+0.5] */ + n = j+(0x00100000>>(k+1)); + k = ((n&0x7fffffff)>>20)-0x3ff; /* new k for n */ + t = zero; + SET_HIGH_WORD(t,n&~(0x000fffff>>k)); + n = ((n&0x000fffff)|0x00100000)>>(20-k); + if(j<0) n = -n; + p_h -= t; + } + t = p_l+p_h; + SET_LOW_WORD(t,0); + u = t*lg2_h; + v = (p_l-(t-p_h))*lg2+t*lg2_l; + z = u+v; + w = v-(z-u); + t = z*z; + t1 = z - t*(P1+t*(P2+t*(P3+t*(P4+t*P5)))); + r = (z*t1)/(t1-two)-(w+z*w); + z = one-(r-z); + GET_HIGH_WORD(j,z); + j += (n<<20); + if((j>>20)<=0) z = scalbn(z,(int)n); /* subnormal output */ + else SET_HIGH_WORD(z,j); + return s*z; +} + +#endif /* defined(_DOUBLE_IS_32BITS) */ diff --git a/newlib/libm/math/ef_pow.c b/newlib/libm/math/ef_pow.c new file mode 100644 index 00000000000..6804ce45ae2 --- /dev/null +++ b/newlib/libm/math/ef_pow.c @@ -0,0 +1,254 @@ +/* ef_pow.c -- float version of e_pow.c. + * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com. + */ + +/* + * ==================================================== + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * + * Developed at SunPro, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + * ==================================================== + */ + +#include "fdlibm.h" + +#ifdef __v810__ +#define const +#endif + +#ifdef __STDC__ +static const float +#else +static float +#endif +bp[] = {1.0, 1.5,}, +dp_h[] = { 0.0, 5.84960938e-01,}, /* 0x3f15c000 */ +dp_l[] = { 0.0, 1.56322085e-06,}, /* 0x35d1cfdc */ +zero = 0.0, +one = 1.0, +two = 2.0, +two24 = 16777216.0, /* 0x4b800000 */ +huge = 1.0e30, +tiny = 1.0e-30, + /* poly coefs for (3/2)*(log(x)-2s-2/3*s**3 */ +L1 = 6.0000002384e-01, /* 0x3f19999a */ +L2 = 4.2857143283e-01, /* 0x3edb6db7 */ +L3 = 3.3333334327e-01, /* 0x3eaaaaab */ +L4 = 2.7272811532e-01, /* 0x3e8ba305 */ +L5 = 2.3066075146e-01, /* 0x3e6c3255 */ +L6 = 2.0697501302e-01, /* 0x3e53f142 */ +P1 = 1.6666667163e-01, /* 0x3e2aaaab */ +P2 = -2.7777778450e-03, /* 0xbb360b61 */ +P3 = 6.6137559770e-05, /* 0x388ab355 */ +P4 = -1.6533901999e-06, /* 0xb5ddea0e */ +P5 = 4.1381369442e-08, /* 0x3331bb4c */ +lg2 = 6.9314718246e-01, /* 0x3f317218 */ +lg2_h = 6.93145752e-01, /* 0x3f317200 */ +lg2_l = 1.42860654e-06, /* 0x35bfbe8c */ +ovt = 4.2995665694e-08, /* -(128-log2(ovfl+.5ulp)) */ +cp = 9.6179670095e-01, /* 0x3f76384f =2/(3ln2) */ +cp_h = 9.6179199219e-01, /* 0x3f763800 =head of cp */ +cp_l = 4.7017383622e-06, /* 0x369dc3a0 =tail of cp_h */ +ivln2 = 1.4426950216e+00, /* 0x3fb8aa3b =1/ln2 */ +ivln2_h = 1.4426879883e+00, /* 0x3fb8aa00 =16b 1/ln2*/ +ivln2_l = 7.0526075433e-06; /* 0x36eca570 =1/ln2 tail*/ + +#ifdef __STDC__ + float __ieee754_powf(float x, float y) +#else + float __ieee754_powf(x,y) + float x, y; +#endif +{ + float z,ax,z_h,z_l,p_h,p_l; + float y1,t1,t2,r,s,t,u,v,w; + __int32_t i,j,k,yisint,n; + __int32_t hx,hy,ix,iy,is; + + GET_FLOAT_WORD(hx,x); + GET_FLOAT_WORD(hy,y); + ix = hx&0x7fffffff; iy = hy&0x7fffffff; + + /* y==zero: x**0 = 1 */ + if(FLT_UWORD_IS_ZERO(iy)) return one; + + /* x|y==NaN return NaN unless x==1 then return 1 */ + if(FLT_UWORD_IS_NAN(ix) || + FLT_UWORD_IS_NAN(iy)) + if(ix==0x3f800000) return one; + else return nanf(""); + + /* determine if y is an odd int when x < 0 + * yisint = 0 ... y is not an integer + * yisint = 1 ... y is an odd int + * yisint = 2 ... y is an even int + */ + yisint = 0; + if(hx<0) { + if(iy>=0x4b800000) yisint = 2; /* even integer y */ + else if(iy>=0x3f800000) { + k = (iy>>23)-0x7f; /* exponent */ + j = iy>>(23-k); + if((j<<(23-k))==iy) yisint = 2-(j&1); + } + } + + /* special value of y */ + if (FLT_UWORD_IS_INFINITE(iy)) { /* y is +-inf */ + if (ix==0x3f800000) + return one; /* +-1**+-inf = 1 */ + else if (ix > 0x3f800000)/* (|x|>1)**+-inf = inf,0 */ + return (hy>=0)? y: zero; + else /* (|x|<1)**-,+inf = inf,0 */ + return (hy<0)?-y: zero; + } + if(iy==0x3f800000) { /* y is +-1 */ + if(hy<0) return one/x; else return x; + } + if(hy==0x40000000) return x*x; /* y is 2 */ + if(hy==0x3f000000) { /* y is 0.5 */ + if(hx>=0) /* x >= +0 */ + return __ieee754_sqrtf(x); + } + + ax = fabsf(x); + /* special value of x */ + if(FLT_UWORD_IS_INFINITE(ix)||FLT_UWORD_IS_ZERO(ix)||ix==0x3f800000){ + z = ax; /*x is +-0,+-inf,+-1*/ + if(hy<0) z = one/z; /* z = (1/|x|) */ + if(hx<0) { + if(((ix-0x3f800000)|yisint)==0) { + z = (z-z)/(z-z); /* (-1)**non-int is NaN */ + } else if(yisint==1) + z = -z; /* (x<0)**odd = -(|x|**odd) */ + } + return z; + } + + /* (x<0)**(non-int) is NaN */ + if(((((__uint32_t)hx>>31)-1)|yisint)==0) return (x-x)/(x-x); + + /* |y| is huge */ + if(iy>0x4d000000) { /* if |y| > 2**27 */ + /* over/underflow if x is not close to one */ + if(ix<0x3f7ffff8) return (hy<0)? huge*huge:tiny*tiny; + if(ix>0x3f800007) return (hy>0)? huge*huge:tiny*tiny; + /* now |1-x| is tiny <= 2**-20, suffice to compute + log(x) by x-x^2/2+x^3/3-x^4/4 */ + t = ax-1; /* t has 20 trailing zeros */ + w = (t*t)*((float)0.5-t*((float)0.333333333333-t*(float)0.25)); + u = ivln2_h*t; /* ivln2_h has 16 sig. bits */ + v = t*ivln2_l-w*ivln2; + t1 = u+v; + GET_FLOAT_WORD(is,t1); + SET_FLOAT_WORD(t1,is&0xfffff000); + t2 = v-(t1-u); + } else { + float s2,s_h,s_l,t_h,t_l; + n = 0; + /* take care subnormal number */ + if(FLT_UWORD_IS_SUBNORMAL(ix)) + {ax *= two24; n -= 24; GET_FLOAT_WORD(ix,ax); } + n += ((ix)>>23)-0x7f; + j = ix&0x007fffff; + /* determine interval */ + ix = j|0x3f800000; /* normalize ix */ + if(j<=0x1cc471) k=0; /* |x|<sqrt(3/2) */ + else if(j<0x5db3d7) k=1; /* |x|<sqrt(3) */ + else {k=0;n+=1;ix -= 0x00800000;} + SET_FLOAT_WORD(ax,ix); + + /* compute s = s_h+s_l = (x-1)/(x+1) or (x-1.5)/(x+1.5) */ + u = ax-bp[k]; /* bp[0]=1.0, bp[1]=1.5 */ + v = one/(ax+bp[k]); + s = u*v; + s_h = s; + GET_FLOAT_WORD(is,s_h); + SET_FLOAT_WORD(s_h,is&0xfffff000); + /* t_h=ax+bp[k] High */ + SET_FLOAT_WORD(t_h,((ix>>1)|0x20000000)+0x0040000+(k<<21)); + t_l = ax - (t_h-bp[k]); + s_l = v*((u-s_h*t_h)-s_h*t_l); + /* compute log(ax) */ + s2 = s*s; + r = s2*s2*(L1+s2*(L2+s2*(L3+s2*(L4+s2*(L5+s2*L6))))); + r += s_l*(s_h+s); + s2 = s_h*s_h; + t_h = (float)3.0+s2+r; + GET_FLOAT_WORD(is,t_h); + SET_FLOAT_WORD(t_h,is&0xfffff000); + t_l = r-((t_h-(float)3.0)-s2); + /* u+v = s*(1+...) */ + u = s_h*t_h; + v = s_l*t_h+t_l*s; + /* 2/(3log2)*(s+...) */ + p_h = u+v; + GET_FLOAT_WORD(is,p_h); + SET_FLOAT_WORD(p_h,is&0xfffff000); + p_l = v-(p_h-u); + z_h = cp_h*p_h; /* cp_h+cp_l = 2/(3*log2) */ + z_l = cp_l*p_h+p_l*cp+dp_l[k]; + /* log2(ax) = (s+..)*2/(3*log2) = n + dp_h + z_h + z_l */ + t = (float)n; + t1 = (((z_h+z_l)+dp_h[k])+t); + GET_FLOAT_WORD(is,t1); + SET_FLOAT_WORD(t1,is&0xfffff000); + t2 = z_l-(((t1-t)-dp_h[k])-z_h); + } + + s = one; /* s (sign of result -ve**odd) = -1 else = 1 */ + if(((((__uint32_t)hx>>31)-1)|(yisint-1))==0) + s = -one; /* (-ve)**(odd int) */ + + /* split up y into y1+y2 and compute (y1+y2)*(t1+t2) */ + GET_FLOAT_WORD(is,y); + SET_FLOAT_WORD(y1,is&0xfffff000); + p_l = (y-y1)*t1+y*t2; + p_h = y1*t1; + z = p_l+p_h; + GET_FLOAT_WORD(j,z); + i = j&0x7fffffff; + if (j>0) { + if (i>FLT_UWORD_EXP_MAX) + return s*huge*huge; /* overflow */ + else if (i==FLT_UWORD_EXP_MAX) + if(p_l+ovt>z-p_h) return s*huge*huge; /* overflow */ + } else { + if (i>FLT_UWORD_EXP_MIN) + return s*tiny*tiny; /* underflow */ + else if (i==FLT_UWORD_EXP_MIN) + if(p_l<=z-p_h) return s*tiny*tiny; /* underflow */ + } + /* + * compute 2**(p_h+p_l) + */ + k = (i>>23)-0x7f; + n = 0; + if(i>0x3f000000) { /* if |z| > 0.5, set n = [z+0.5] */ + n = j+(0x00800000>>(k+1)); + k = ((n&0x7fffffff)>>23)-0x7f; /* new k for n */ + SET_FLOAT_WORD(t,n&~(0x007fffff>>k)); + n = ((n&0x007fffff)|0x00800000)>>(23-k); + if(j<0) n = -n; + p_h -= t; + } + t = p_l+p_h; + GET_FLOAT_WORD(is,t); + SET_FLOAT_WORD(t,is&0xfffff000); + u = t*lg2_h; + v = (p_l-(t-p_h))*lg2+t*lg2_l; + z = u+v; + w = v-(z-u); + t = z*z; + t1 = z - t*(P1+t*(P2+t*(P3+t*(P4+t*P5)))); + r = (z*t1)/(t1-two)-(w+z*w); + z = one-(r-z); + GET_FLOAT_WORD(j,z); + j += (n<<23); + if((j>>23)<=0) z = scalbnf(z,(int)n); /* subnormal output */ + else SET_FLOAT_WORD(z,j); + return s*z; +} diff --git a/newlib/libm/math/w_acos.c b/newlib/libm/math/w_acos.c new file mode 100644 index 00000000000..fdf2eb07e60 --- /dev/null +++ b/newlib/libm/math/w_acos.c @@ -0,0 +1,118 @@ + +/* @(#)w_acos.c 5.1 93/09/24 */ +/* + * ==================================================== + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * + * Developed at SunPro, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + * ==================================================== + */ + +/* +FUNCTION + <<acos>>, <<acosf>>---arc cosine + +INDEX + acos +INDEX + acosf + +ANSI_SYNOPSIS + #include <math.h> + double acos(double <[x]>); + float acosf(float <[x]>); + +TRAD_SYNOPSIS + #include <math.h> + double acos(<[x]>) + double <[x]>; + + float acosf(<[x]>) + float <[x]>; + + + +DESCRIPTION + + <<acos>> computes the inverse cosine (arc cosine) of the input value. + Arguments to <<acos>> must be in the range @minus{}1 to 1. + + <<acosf>> is identical to <<acos>>, except that it performs + its calculations on <<floats>>. + +RETURNS + @ifnottex + <<acos>> and <<acosf>> return values in radians, in the range of 0 to pi. + @end ifnottex + @tex + <<acos>> and <<acosf>> return values in radians, in the range of <<0>> to $\pi$. + @end tex + + If <[x]> is not between @minus{}1 and 1, the returned value is NaN + (not a number) the global variable <<errno>> is set to <<EDOM>>, and a + <<DOMAIN error>> message is sent as standard error output. + + You can modify error handling for these functions using <<matherr>>. + + +QUICKREF ANSI SVID POSIX RENTRANT + acos y,y,y,m + acosf n,n,n,m + +MATHREF + acos, [-1,1], acos(arg),,, + acos, NAN, arg,DOMAIN,EDOM + +MATHREF + acosf, [-1,1], acosf(arg),,, + acosf, NAN, argf,DOMAIN,EDOM + +*/ + +/* + * wrap_acos(x) + */ + +#include "fdlibm.h" +#include <errno.h> + +#ifndef _DOUBLE_IS_32BITS + +#ifdef __STDC__ + double acos(double x) /* wrapper acos */ +#else + double acos(x) /* wrapper acos */ + double x; +#endif +{ +#ifdef _IEEE_LIBM + return __ieee754_acos(x); +#else + double z; + struct exception exc; + z = __ieee754_acos(x); + if(_LIB_VERSION == _IEEE_ || isnan(x)) return z; + if(fabs(x)>1.0) { + /* acos(|x|>1) */ + exc.type = DOMAIN; + exc.name = "acos"; + exc.err = 0; + exc.arg1 = exc.arg2 = x; + exc.retval = nan(""); + if (_LIB_VERSION == _POSIX_) + errno = EDOM; + else if (!matherr(&exc)) { + errno = EDOM; + } + if (exc.err != 0) + errno = exc.err; + return exc.retval; + } else + return z; +#endif +} + +#endif /* defined(_DOUBLE_IS_32BITS) */ diff --git a/newlib/libm/math/w_asin.c b/newlib/libm/math/w_asin.c new file mode 100644 index 00000000000..e7884b2e383 --- /dev/null +++ b/newlib/libm/math/w_asin.c @@ -0,0 +1,121 @@ + +/* @(#)w_asin.c 5.1 93/09/24 */ +/* + * ==================================================== + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * + * Developed at SunPro, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + * ==================================================== + * + */ + +/* +FUNCTION + <<asin>>, <<asinf>>---arc sine + +INDEX + asin +INDEX + asinf + +ANSI_SYNOPSIS + #include <math.h> + double asin(double <[x]>); + float asinf(float <[x]>); + +TRAD_SYNOPSIS + #include <math.h> + double asin(<[x]>) + double <[x]>; + + float asinf(<[x]>) + float <[x]>; + + +DESCRIPTION + +<<asin>> computes the inverse sine (arc sine) of the argument <[x]>. +Arguments to <<asin>> must be in the range @minus{}1 to 1. + +<<asinf>> is identical to <<asin>>, other than taking and +returning floats. + +You can modify error handling for these routines using <<matherr>>. + +RETURNS +@ifnottex +<<asin>> returns values in radians, in the range of -pi/2 to pi/2. +@end ifnottex +@tex +<<asin>> returns values in radians, in the range of $-\pi/2$ to $\pi/2$. +@end tex + +If <[x]> is not in the range @minus{}1 to 1, <<asin>> and <<asinf>> +return NaN (not a number), set the global variable <<errno>> to +<<EDOM>>, and issue a <<DOMAIN error>> message. + +You can change this error treatment using <<matherr>>. + +QUICKREF ANSI SVID POSIX RENTRANT + asin y,y,y,m + asinf n,n,n,m + +MATHREF + asin, -1<=arg<=1, asin(arg),,, + asin, NAN, arg,EDOM, DOMAIN + +MATHREF + asinf, -1<=arg<=1, asin(arg),,, + asinf, NAN, arg,EDOM, DOMAIN + + +*/ + +/* + * wrapper asin(x) + */ + + +#include "fdlibm.h" +#include <errno.h> + +#ifndef _DOUBLE_IS_32BITS + +#ifdef __STDC__ + double asin(double x) /* wrapper asin */ +#else + double asin(x) /* wrapper asin */ + double x; +#endif +{ +#ifdef _IEEE_LIBM + return __ieee754_asin(x); +#else + double z; + struct exception exc; + z = __ieee754_asin(x); + if(_LIB_VERSION == _IEEE_ || isnan(x)) return z; + if(fabs(x)>1.0) { + /* asin(|x|>1) */ + exc.type = DOMAIN; + exc.name = "asin"; + exc.err = 0; + exc.arg1 = exc.arg2 = x; + exc.retval = nan(""); + if(_LIB_VERSION == _POSIX_) + errno = EDOM; + else if (!matherr(&exc)) { + errno = EDOM; + } + if (exc.err != 0) + errno = exc.err; + return exc.retval; + } else + return z; +#endif +} + +#endif /* defined(_DOUBLE_IS_32BITS) */ diff --git a/newlib/libm/math/w_atan2.c b/newlib/libm/math/w_atan2.c new file mode 100644 index 00000000000..f3e344ea614 --- /dev/null +++ b/newlib/libm/math/w_atan2.c @@ -0,0 +1,90 @@ + +/* @(#)w_atan2.c 5.1 93/09/24 */ +/* + * ==================================================== + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * + * Developed at SunPro, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + * ==================================================== + * + */ + +/* +FUNCTION + <<atan2>>, <<atan2f>>---arc tangent of y/x + +INDEX + atan2 +INDEX + atan2f + +ANSI_SYNOPSIS + #include <math.h> + double atan2(double <[y]>,double <[x]>); + float atan2f(float <[y]>,float <[x]>); + +TRAD_SYNOPSIS + #include <math.h> + double atan2(<[y]>,<[x]>); + double <[y]>; + double <[x]>; + + float atan2f(<[y]>,<[x]>); + float <[y]>; + float <[x]>; + +DESCRIPTION + +<<atan2>> computes the inverse tangent (arc tangent) of <[y]>/<[x]>. +<<atan2>> produces the correct result even for angles near +@ifnottex +pi/2 or -pi/2 +@end ifnottex +@tex +$\pi/2$ or $-\pi/2$ +@end tex +(that is, when <[x]> is near 0). + +<<atan2f>> is identical to <<atan2>>, save that it takes and returns +<<float>>. + +RETURNS +<<atan2>> and <<atan2f>> return a value in radians, in the range of +@ifnottex +-pi to pi. +@end ifnottex +@tex +$-\pi$ to $\pi$. +@end tex + +You can modify error handling for these functions using <<matherr>>. + +PORTABILITY +<<atan2>> is ANSI C. <<atan2f>> is an extension. + + +*/ + +/* + * wrapper atan2(y,x) + */ + +#include "fdlibm.h" +#include <errno.h> + +#ifndef _DOUBLE_IS_32BITS + +#ifdef __STDC__ + double atan2(double y, double x) /* wrapper atan2 */ +#else + double atan2(y,x) /* wrapper atan2 */ + double y,x; +#endif +{ + return __ieee754_atan2(y,x); +} + +#endif /* defined(_DOUBLE_IS_32BITS) */ diff --git a/newlib/libm/math/w_log.c b/newlib/libm/math/w_log.c new file mode 100644 index 00000000000..e23efd7e6f6 --- /dev/null +++ b/newlib/libm/math/w_log.c @@ -0,0 +1,116 @@ + +/* @(#)w_log.c 5.1 93/09/24 */ +/* + * ==================================================== + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * + * Developed at SunPro, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + * ==================================================== + */ + +/* +FUNCTION + <<log>>, <<logf>>---natural logarithms + +INDEX + log +INDEX + logf + +ANSI_SYNOPSIS + #include <math.h> + double log(double <[x]>); + float logf(float <[x]>); + +TRAD_SYNOPSIS + #include <math.h> + double log(<[x]>); + double <[x]>; + + float logf(<[x]>); + float <[x]>; + +DESCRIPTION +Return the natural logarithm of <[x]>, that is, its logarithm base e +(where e is the base of the natural system of logarithms, 2.71828@dots{}). +<<log>> and <<logf>> are identical save for the return and argument types. + +You can use the (non-ANSI) function <<matherr>> to specify error +handling for these functions. + +RETURNS +Normally, returns the calculated value. When <[x]> is zero, the +returned value is <<-HUGE_VAL>> and <<errno>> is set to <<ERANGE>>. +When <[x]> is negative, the returned value is NaN (not a number) and +<<errno>> is set to <<EDOM>>. You can control the error behavior via +<<matherr>>. + +PORTABILITY +<<log>> is ANSI. <<logf>> is an extension. +*/ + +/* + * wrapper log(x) + */ + +#include "fdlibm.h" +#include <errno.h> + +#ifndef _DOUBLE_IS_32BITS + +#ifdef __STDC__ + double log(double x) /* wrapper log */ +#else + double log(x) /* wrapper log */ + double x; +#endif +{ +#ifdef _IEEE_LIBM + return __ieee754_log(x); +#else + double z; + struct exception exc; + z = __ieee754_log(x); + if(_LIB_VERSION == _IEEE_ || isnan(x) || x > 0.0) return z; +#ifndef HUGE_VAL +#define HUGE_VAL inf + double inf = 0.0; + + SET_HIGH_WORD(inf,0x7ff00000); /* set inf to infinite */ +#endif + exc.name = "log"; + exc.err = 0; + exc.arg1 = x; + exc.arg2 = x; + if (_LIB_VERSION == _SVID_) + exc.retval = -HUGE; + else + exc.retval = -HUGE_VAL; + if(x==0.0) { + /* log(0) */ + exc.type = SING; + if (_LIB_VERSION == _POSIX_) + errno = ERANGE; + else if (!matherr(&exc)) { + errno = EDOM; + } + } else { + /* log(x<0) */ + exc.type = DOMAIN; + if (_LIB_VERSION == _POSIX_) + errno = EDOM; + else if (!matherr(&exc)) { + errno = EDOM; + } + exc.retval = nan(""); + } + if (exc.err != 0) + errno = exc.err; + return exc.retval; +#endif +} + +#endif /* defined(_DOUBLE_IS_32BITS) */ diff --git a/newlib/libm/math/w_log10.c b/newlib/libm/math/w_log10.c new file mode 100644 index 00000000000..7c39669545c --- /dev/null +++ b/newlib/libm/math/w_log10.c @@ -0,0 +1,116 @@ + +/* @(#)w_log10.c 5.1 93/09/24 */ +/* + * ==================================================== + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * + * Developed at SunPro, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + * ==================================================== + */ + +/* +FUNCTION + <<log10>>, <<log10f>>---base 10 logarithms + +INDEX +log10 +INDEX +log10f + +ANSI_SYNOPSIS + #include <math.h> + double log10(double <[x]>); + float log10f(float <[x]>); + +TRAD_SYNOPSIS + #include <math.h> + double log10(<[x]>) + double <[x]>; + + float log10f(<[x]>) + float <[x]>; + +DESCRIPTION +<<log10>> returns the base 10 logarithm of <[x]>. +It is implemented as <<log(<[x]>) / log(10)>>. + +<<log10f>> is identical, save that it takes and returns <<float>> values. + +RETURNS +<<log10>> and <<log10f>> return the calculated value. + +See the description of <<log>> for information on errors. + +PORTABILITY +<<log10>> is ANSI C. <<log10f>> is an extension. + + */ + +/* + * wrapper log10(X) + */ + +#include "fdlibm.h" +#include <errno.h> + +#ifndef _DOUBLE_IS_32BITS + +#ifdef __STDC__ + double log10(double x) /* wrapper log10 */ +#else + double log10(x) /* wrapper log10 */ + double x; +#endif +{ +#ifdef _IEEE_LIBM + return __ieee754_log10(x); +#else + double z; + struct exception exc; + z = __ieee754_log10(x); + if(_LIB_VERSION == _IEEE_ || isnan(x)) return z; + if(x<=0.0) { +#ifndef HUGE_VAL +#define HUGE_VAL inf + double inf = 0.0; + + SET_HIGH_WORD(inf,0x7ff00000); /* set inf to infinite */ +#endif + exc.name = "log10"; + exc.err = 0; + exc.arg1 = x; + exc.arg2 = x; + if (_LIB_VERSION == _SVID_) + exc.retval = -HUGE; + else + exc.retval = -HUGE_VAL; + if(x==0.0) { + /* log10(0) */ + exc.type = SING; + if (_LIB_VERSION == _POSIX_) + errno = ERANGE; + else if (!matherr(&exc)) { + errno = EDOM; + } + } else { + /* log10(x<0) */ + exc.type = DOMAIN; + if (_LIB_VERSION == _POSIX_) + errno = EDOM; + else if (!matherr(&exc)) { + errno = EDOM; + } + exc.retval = nan(""); + } + if (exc.err != 0) + errno = exc.err; + return exc.retval; + } else + return z; +#endif +} + +#endif /* defined(_DOUBLE_IS_32BITS) */ diff --git a/newlib/libm/math/w_pow.c b/newlib/libm/math/w_pow.c new file mode 100644 index 00000000000..2e08619321c --- /dev/null +++ b/newlib/libm/math/w_pow.c @@ -0,0 +1,231 @@ + + +/* @(#)w_pow.c 5.2 93/10/01 */ +/* + * ==================================================== + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * + * Developed at SunPro, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + * ==================================================== + */ + +/* +FUNCTION + <<pow>>, <<powf>>---x to the power y +INDEX + pow +INDEX + powf + + +ANSI_SYNOPSIS + #include <math.h> + double pow(double <[x]>, double <[y]>); + float pow(float <[x]>, float <[y]>); + +TRAD_SYNOPSIS + #include <math.h> + double pow(<[x]>, <[y]>); + double <[x]>, <[y]>; + + float pow(<[x]>, <[y]>); + float <[x]>, <[y]>; + +DESCRIPTION + <<pow>> and <<powf>> calculate <[x]> raised to the exponent <[y]>. + @tex + (That is, $x^y$.) + @end tex + +RETURNS + On success, <<pow>> and <<powf>> return the value calculated. + + When the argument values would produce overflow, <<pow>> + returns <<HUGE_VAL>> and set <<errno>> to <<ERANGE>>. If the + argument <[x]> passed to <<pow>> or <<powf>> is a negative + noninteger, and <[y]> is also not an integer, then <<errno>> + is set to <<EDOM>>. If <[x]> and <[y]> are both 0, then + <<pow>> and <<powf>> return <<1>>. + + You can modify error handling for these functions using <<matherr>>. + +PORTABILITY + <<pow>> is ANSI C. <<powf>> is an extension. */ + +/* + * wrapper pow(x,y) return x**y + */ + +#include "fdlibm.h" +#include <errno.h> + +#ifndef _DOUBLE_IS_32BITS + +#ifdef __STDC__ + double pow(double x, double y) /* wrapper pow */ +#else + double pow(x,y) /* wrapper pow */ + double x,y; +#endif +{ +#ifdef _IEEE_LIBM + return __ieee754_pow(x,y); +#else + double z; +#ifndef HUGE_VAL +#define HUGE_VAL inf + double inf = 0.0; + + SET_HIGH_WORD(inf,0x7ff00000); /* set inf to infinite */ +#endif + struct exception exc; + z=__ieee754_pow(x,y); + if(_LIB_VERSION == _IEEE_|| isnan(y)) return z; + if(isnan(x)) { + if(y==0.0) { + /* pow(NaN,0.0) */ + /* error only if _LIB_VERSION == _SVID_ & _XOPEN_ */ + exc.type = DOMAIN; + exc.name = "pow"; + exc.err = 0; + exc.arg1 = x; + exc.arg2 = y; + exc.retval = 1.0; + if (_LIB_VERSION == _IEEE_ || + _LIB_VERSION == _POSIX_) exc.retval = 1.0; + else if (!matherr(&exc)) { + errno = EDOM; + } + if (exc.err != 0) + errno = exc.err; + return exc.retval; + } else + return z; + } + if(x==0.0){ + if(y==0.0) { + /* pow(0.0,0.0) */ + /* error only if _LIB_VERSION == _SVID_ */ + exc.type = DOMAIN; + exc.name = "pow"; + exc.err = 0; + exc.arg1 = x; + exc.arg2 = y; + exc.retval = 0.0; + if (_LIB_VERSION != _SVID_) exc.retval = 1.0; + else if (!matherr(&exc)) { + errno = EDOM; + } + if (exc.err != 0) + errno = exc.err; + return exc.retval; + } + if(finite(y)&&y<0.0) { + /* 0**neg */ + exc.type = DOMAIN; + exc.name = "pow"; + exc.err = 0; + exc.arg1 = x; + exc.arg2 = y; + if (_LIB_VERSION == _SVID_) + exc.retval = 0.0; + else + exc.retval = -HUGE_VAL; + if (_LIB_VERSION == _POSIX_) + errno = EDOM; + else if (!matherr(&exc)) { + errno = EDOM; + } + if (exc.err != 0) + errno = exc.err; + return exc.retval; + } + return z; + } + if(!finite(z)) { + if(finite(x)&&finite(y)) { + if(isnan(z)) { + /* neg**non-integral */ + exc.type = DOMAIN; + exc.name = "pow"; + exc.err = 0; + exc.arg1 = x; + exc.arg2 = y; + if (_LIB_VERSION == _SVID_) + exc.retval = 0.0; + else + exc.retval = 0.0/0.0; /* X/Open allow NaN */ + if (_LIB_VERSION == _POSIX_) + errno = EDOM; + else if (!matherr(&exc)) { + errno = EDOM; + } + if (exc.err != 0) + errno = exc.err; + return exc.retval; + } else { + /* pow(x,y) overflow */ + exc.type = OVERFLOW; + exc.name = "pow"; + exc.err = 0; + exc.arg1 = x; + exc.arg2 = y; + if (_LIB_VERSION == _SVID_) { + exc.retval = HUGE; + y *= 0.5; + if(x<0.0&&rint(y)!=y) exc.retval = -HUGE; + } else { + exc.retval = HUGE_VAL; + y *= 0.5; + if(x<0.0&&rint(y)!=y) exc.retval = -HUGE_VAL; + } + if (_LIB_VERSION == _POSIX_) + errno = ERANGE; + else if (!matherr(&exc)) { + errno = ERANGE; + } + if (exc.err != 0) + errno = exc.err; + return exc.retval; + } + } + } + if(z==0.0&&finite(x)&&finite(y)) { + /* pow(x,y) underflow */ + exc.type = UNDERFLOW; + exc.name = "pow"; + exc.err = 0; + exc.arg1 = x; + exc.arg2 = y; + exc.retval = 0.0; + if (_LIB_VERSION == _POSIX_) + errno = ERANGE; + else if (!matherr(&exc)) { + errno = ERANGE; + } + if (exc.err != 0) + errno = exc.err; + return exc.retval; + } + return z; +#endif +} + +#endif /* defined(_DOUBLE_IS_32BITS) */ + + + + + + + + + + + + + + diff --git a/newlib/libm/math/wf_acos.c b/newlib/libm/math/wf_acos.c new file mode 100644 index 00000000000..38817b82b21 --- /dev/null +++ b/newlib/libm/math/wf_acos.c @@ -0,0 +1,69 @@ +/* wf_acos.c -- float version of w_acos.c. + * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com. + */ + +/* + * ==================================================== + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * + * Developed at SunPro, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + * ==================================================== + */ + +/* + * wrap_acosf(x) + */ + +#include "fdlibm.h" +#include <errno.h> + +#ifdef _HAVE_STDC + float acosf(float x) /* wrapper acosf */ +#else + float acosf(x) /* wrapper acosf */ + float x; +#endif +{ +#ifdef _IEEE_LIBM + return __ieee754_acosf(x); +#else + float z; + struct exception exc; + z = __ieee754_acosf(x); + if(_LIB_VERSION == _IEEE_ || isnanf(x)) return z; + if(fabsf(x)>(float)1.0) { + /* acosf(|x|>1) */ + exc.type = DOMAIN; + exc.name = "acosf"; + exc.err = 0; + exc.arg1 = exc.arg2 = (double)x; + exc.retval = nan(""); + if (_LIB_VERSION == _POSIX_) + errno = EDOM; + else if (!matherr(&exc)) { + errno = EDOM; + } + if (exc.err != 0) + errno = exc.err; + return (float)exc.retval; + } else + return z; +#endif +} + +#ifdef _DOUBLE_IS_32BITS + +#ifdef __STDC__ + double acos(double x) +#else + double acos(x) + double x; +#endif +{ + return (double) acosf((float) x); +} + +#endif /* defined(_DOUBLE_IS_32BITS) */ diff --git a/newlib/libm/math/wf_asin.c b/newlib/libm/math/wf_asin.c new file mode 100644 index 00000000000..fc39e977c08 --- /dev/null +++ b/newlib/libm/math/wf_asin.c @@ -0,0 +1,71 @@ +/* wf_asin.c -- float version of w_asin.c. + * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com. + */ + +/* + * ==================================================== + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * + * Developed at SunPro, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + * ==================================================== + * + */ + +/* + * wrapper asinf(x) + */ + + +#include "fdlibm.h" +#include <errno.h> + +#ifdef __STDC__ + float asinf(float x) /* wrapper asinf */ +#else + float asinf(x) /* wrapper asinf */ + float x; +#endif +{ +#ifdef _IEEE_LIBM + return __ieee754_asinf(x); +#else + float z; + struct exception exc; + z = __ieee754_asinf(x); + if(_LIB_VERSION == _IEEE_ || isnanf(x)) return z; + if(fabsf(x)>(float)1.0) { + /* asinf(|x|>1) */ + exc.type = DOMAIN; + exc.name = "asinf"; + exc.err = 0; + exc.arg1 = exc.arg2 = (double)x; + exc.retval = nan(""); + if(_LIB_VERSION == _POSIX_) + errno = EDOM; + else if (!matherr(&exc)) { + errno = EDOM; + } + if (exc.err != 0) + errno = exc.err; + return (float)exc.retval; + } else + return z; +#endif +} + +#ifdef _DOUBLE_IS_32BITS + +#ifdef __STDC__ + double asin(double x) +#else + double asin(x) + double x; +#endif +{ + return (double) asinf((float) x); +} + +#endif /* defined(_DOUBLE_IS_32BITS) */ diff --git a/newlib/libm/math/wf_atan2.c b/newlib/libm/math/wf_atan2.c new file mode 100644 index 00000000000..eb2a76b1fb0 --- /dev/null +++ b/newlib/libm/math/wf_atan2.c @@ -0,0 +1,46 @@ +/* wf_atan2.c -- float version of w_atan2.c. + * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com. + */ + +/* + * ==================================================== + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * + * Developed at SunPro, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + * ==================================================== + * + */ + +/* + * wrapper atan2f(y,x) + */ + +#include "fdlibm.h" +#include <errno.h> + +#ifdef __STDC__ + float atan2f(float y, float x) /* wrapper atan2f */ +#else + float atan2f(y,x) /* wrapper atan2 */ + float y,x; +#endif +{ + return __ieee754_atan2f(y,x); +} + +#ifdef _DOUBLE_IS_32BITS + +#ifdef __STDC__ + double atan2(double y, double x) +#else + double atan2(y,x) + double y,x; +#endif +{ + return (double) atan2f((float) y, (float) x); +} + +#endif /* defined(_DOUBLE_IS_32BITS) */ diff --git a/newlib/libm/math/wf_log.c b/newlib/libm/math/wf_log.c new file mode 100644 index 00000000000..369ef32614f --- /dev/null +++ b/newlib/libm/math/wf_log.c @@ -0,0 +1,86 @@ +/* wf_log.c -- float version of w_log.c. + * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com. + */ + +/* + * ==================================================== + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * + * Developed at SunPro, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + * ==================================================== + */ + +/* + * wrapper logf(x) + */ + +#include "fdlibm.h" +#include <errno.h> + +#ifdef __STDC__ + float logf(float x) /* wrapper logf */ +#else + float logf(x) /* wrapper logf */ + float x; +#endif +{ +#ifdef _IEEE_LIBM + return __ieee754_logf(x); +#else + float z; + struct exception exc; + z = __ieee754_logf(x); + if(_LIB_VERSION == _IEEE_ || isnanf(x) || x > (float)0.0) return z; +#ifndef HUGE_VAL +#define HUGE_VAL inf + double inf = 0.0; + + SET_HIGH_WORD(inf,0x7ff00000); /* set inf to infinite */ +#endif + exc.name = "logf"; + exc.err = 0; + exc.arg1 = exc.arg2 = (double)x; + if (_LIB_VERSION == _SVID_) + exc.retval = -HUGE; + else + exc.retval = -HUGE_VAL; + if(x==(float)0.0) { + /* logf(0) */ + exc.type = SING; + if (_LIB_VERSION == _POSIX_) + errno = ERANGE; + else if (!matherr(&exc)) { + errno = EDOM; + } + } else { + /* logf(x<0) */ + exc.type = DOMAIN; + if (_LIB_VERSION == _POSIX_) + errno = EDOM; + else if (!matherr(&exc)) { + errno = EDOM; + } + exc.retval = nan(""); + } + if (exc.err != 0) + errno = exc.err; + return (float)exc.retval; +#endif +} + +#ifdef _DOUBLE_IS_32BITS + +#ifdef __STDC__ + double log(double x) +#else + double log(x) + double x; +#endif +{ + return (double) logf((float) x); +} + +#endif /* defined(_DOUBLE_IS_32BITS) */ diff --git a/newlib/libm/math/wf_log10.c b/newlib/libm/math/wf_log10.c new file mode 100644 index 00000000000..728913500b3 --- /dev/null +++ b/newlib/libm/math/wf_log10.c @@ -0,0 +1,89 @@ +/* wf_log10.c -- float version of w_log10.c. + * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com. + */ + +/* + * ==================================================== + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * + * Developed at SunPro, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + * ==================================================== + */ + +/* + * wrapper log10f(X) + */ + +#include "fdlibm.h" +#include <errno.h> + +#ifdef __STDC__ + float log10f(float x) /* wrapper log10f */ +#else + float log10f(x) /* wrapper log10f */ + float x; +#endif +{ +#ifdef _IEEE_LIBM + return __ieee754_log10f(x); +#else + float z; + struct exception exc; + z = __ieee754_log10f(x); + if(_LIB_VERSION == _IEEE_ || isnanf(x)) return z; + if(x<=(float)0.0) { +#ifndef HUGE_VAL +#define HUGE_VAL inf + double inf = 0.0; + + SET_HIGH_WORD(inf,0x7ff00000); /* set inf to infinite */ +#endif + exc.name = "log10f"; + exc.err = 0; + exc.arg1 = exc.arg2 = (double)x; + if (_LIB_VERSION == _SVID_) + exc.retval = -HUGE; + else + exc.retval = -HUGE_VAL; + if(x==(float)0.0) { + /* log10f(0) */ + exc.type = SING; + if (_LIB_VERSION == _POSIX_) + errno = ERANGE; + else if (!matherr(&exc)) { + errno = EDOM; + } + } else { + /* log10f(x<0) */ + exc.type = DOMAIN; + if (_LIB_VERSION == _POSIX_) + errno = EDOM; + else if (!matherr(&exc)) { + errno = EDOM; + } + exc.retval = nan(""); + } + if (exc.err != 0) + errno = exc.err; + return (float)exc.retval; + } else + return z; +#endif +} + +#ifdef _DOUBLE_IS_32BITS + +#ifdef __STDC__ + double log10(double x) +#else + double log10(x) + double x; +#endif +{ + return (double) log10f((float) x); +} + +#endif /* defined(_DOUBLE_IS_32BITS) */ diff --git a/newlib/libm/math/wf_pow.c b/newlib/libm/math/wf_pow.c new file mode 100644 index 00000000000..eaeed85ab7b --- /dev/null +++ b/newlib/libm/math/wf_pow.c @@ -0,0 +1,179 @@ +/* wf_pow.c -- float version of w_pow.c. + * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com. + */ + +/* + * ==================================================== + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * + * Developed at SunPro, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + * ==================================================== + */ + +/* + * wrapper powf(x,y) return x**y + */ + +#include "fdlibm.h" +#include <errno.h> + +#ifdef __STDC__ + float powf(float x, float y) /* wrapper powf */ +#else + float powf(x,y) /* wrapper powf */ + float x,y; +#endif +{ +#ifdef _IEEE_LIBM + return __ieee754_powf(x,y); +#else + float z; + struct exception exc; + z=__ieee754_powf(x,y); + if(_LIB_VERSION == _IEEE_|| isnanf(y)) return z; + if(isnanf(x)) { + if(y==(float)0.0) { + /* powf(NaN,0.0) */ + /* error only if _LIB_VERSION == _SVID_ & _XOPEN_ */ + exc.type = DOMAIN; + exc.name = "powf"; + exc.err = 0; + exc.arg1 = (double)x; + exc.arg2 = (double)y; + exc.retval = 1.0; + if (_LIB_VERSION == _IEEE_ || + _LIB_VERSION == _POSIX_) exc.retval = 1.0; + else if (!matherr(&exc)) { + errno = EDOM; + } + if (exc.err != 0) + errno = exc.err; + return (float)exc.retval; + } else + return z; + } + if(x==(float)0.0){ + if(y==(float)0.0) { + /* powf(0.0,0.0) */ + /* error only if _LIB_VERSION == _SVID_ */ + exc.type = DOMAIN; + exc.name = "powf"; + exc.err = 0; + exc.arg1 = (double)x; + exc.arg2 = (double)y; + exc.retval = 0.0; + if (_LIB_VERSION != _SVID_) exc.retval = 1.0; + else if (!matherr(&exc)) { + errno = EDOM; + } + if (exc.err != 0) + errno = exc.err; + return (float)exc.retval; + } + if(finitef(y)&&y<(float)0.0) { + /* 0**neg */ + exc.type = DOMAIN; + exc.name = "powf"; + exc.err = 0; + exc.arg1 = (double)x; + exc.arg2 = (double)y; + if (_LIB_VERSION == _SVID_) + exc.retval = 0.0; + else + exc.retval = -HUGE_VAL; + if (_LIB_VERSION == _POSIX_) + errno = EDOM; + else if (!matherr(&exc)) { + errno = EDOM; + } + if (exc.err != 0) + errno = exc.err; + return (float)exc.retval; + } + return z; + } + if(!finitef(z)) { + if(finitef(x)&&finitef(y)) { + if(isnanf(z)) { + /* neg**non-integral */ + exc.type = DOMAIN; + exc.name = "powf"; + exc.err = 0; + exc.arg1 = (double)x; + exc.arg2 = (double)y; + if (_LIB_VERSION == _SVID_) + exc.retval = 0.0; + else + exc.retval = 0.0/0.0; /* X/Open allow NaN */ + if (_LIB_VERSION == _POSIX_) + errno = EDOM; + else if (!matherr(&exc)) { + errno = EDOM; + } + if (exc.err != 0) + errno = exc.err; + return (float)exc.retval; + } else { + /* powf(x,y) overflow */ + exc.type = OVERFLOW; + exc.name = "powf"; + exc.err = 0; + exc.arg1 = (double)x; + exc.arg2 = (double)y; + if (_LIB_VERSION == _SVID_) { + exc.retval = HUGE; + y *= 0.5; + if(x<0.0&&rint(y)!=y) exc.retval = -HUGE; + } else { + exc.retval = HUGE_VAL; + y *= 0.5; + if(x<0.0&&rint(y)!=y) exc.retval = -HUGE_VAL; + } + if (_LIB_VERSION == _POSIX_) + errno = ERANGE; + else if (!matherr(&exc)) { + errno = ERANGE; + } + if (exc.err != 0) + errno = exc.err; + return (float)exc.retval; + } + } + } + if(z==(float)0.0&&finitef(x)&&finitef(y)) { + /* powf(x,y) underflow */ + exc.type = UNDERFLOW; + exc.name = "powf"; + exc.err = 0; + exc.arg1 = (double)x; + exc.arg2 = (double)y; + exc.retval = 0.0; + if (_LIB_VERSION == _POSIX_) + errno = ERANGE; + else if (!matherr(&exc)) { + errno = ERANGE; + } + if (exc.err != 0) + errno = exc.err; + return (float)exc.retval; + } + return z; +#endif +} + +#ifdef _DOUBLE_IS_32BITS + +#ifdef __STDC__ + double pow(double x, double y) +#else + double pow(x,y) + double x,y; +#endif +{ + return (double) powf((float) x, (float) y); +} + +#endif /* defined(_DOUBLE_IS_32BITS) */ |