mirror of
https://github.com/adtools/clib2.git
synced 2025-12-08 14:59:05 +00:00
- Implemented fmin()/fminf(), fmax()/fmaxf(), fdim()/fdimf() for C99.
- Ported acosf(), asinf(), atan2f(), atanf(), ceilf(), expf(), floorf(), fmodf(), frexpf(), ldexpf(), log10f(), logbf(), logf(), modff(), powf(), sqrtf(), scalbn() and scalbnf() for C99. - Ported cbrt(), cbrtf(), erf(), erff(), erfc(), erfcf(), expm1(), expm1f(), ilogb(), ilogbf(), log1p() and log1pf() for C99. git-svn-id: file:///Users/olsen/Code/migration-svn-zu-git/logical-line-staging/clib2/trunk@14963 87f5fb63-7c3d-0410-a384-fd976d0f7a62
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
#
|
||||
# $Id: GNUmakefile.68k,v 1.55 2005-05-14 10:52:31 obarthel Exp $
|
||||
# $Id: GNUmakefile.68k,v 1.56 2005-05-29 14:45:28 obarthel Exp $
|
||||
#
|
||||
# :ts=8
|
||||
#
|
||||
@@ -520,45 +520,75 @@ MATH_LIB = \
|
||||
complex_crealf.o \
|
||||
complex_creall.o \
|
||||
math_acos.o \
|
||||
math_acosf.o \
|
||||
math_asin.o \
|
||||
math_asinf.o \
|
||||
math_atan.o \
|
||||
math_atan2.o \
|
||||
math_atan2f.o \
|
||||
math_atanf.o \
|
||||
math_cbrt.o \
|
||||
math_cbrtf.o \
|
||||
math_ceil.o \
|
||||
math_cos.o \
|
||||
math_cosh.o \
|
||||
math_ceilf.o \
|
||||
math_copysign.o \
|
||||
math_copysignf.o \
|
||||
math_cos.o \
|
||||
math_cosh.o \
|
||||
math_erf.o \
|
||||
math_erfc.o \
|
||||
math_erfcf.o \
|
||||
math_erff.o \
|
||||
math_exp.o \
|
||||
math_expf.o \
|
||||
math_expm1.o \
|
||||
math_expm1f.o \
|
||||
math_fabs.o \
|
||||
math_fabsf.o \
|
||||
math_floor.o \
|
||||
math_floorf.o \
|
||||
math_fmod.o \
|
||||
math_fmodf.o \
|
||||
math_fpclassify.o \
|
||||
math_inf.o \
|
||||
math_inff.o \
|
||||
math_isfinite.o \
|
||||
math_isunordered.o \
|
||||
math_signbit.o \
|
||||
math_frexp.o \
|
||||
math_frexpf.o \
|
||||
math_huge_val.o \
|
||||
math_huge_valf.o \
|
||||
math_hypot.o \
|
||||
math_ilogb.o \
|
||||
math_ilogbf.o \
|
||||
math_inf.o \
|
||||
math_inff.o \
|
||||
math_init_exit.o \
|
||||
math_isfinite.o \
|
||||
math_isunordered.o \
|
||||
math_ldexp.o \
|
||||
math_ldexpf.o \
|
||||
math_log.o \
|
||||
math_log10.o \
|
||||
math_log10f.o \
|
||||
math_log1p.o \
|
||||
math_log1pf.o \
|
||||
math_logb.o \
|
||||
math_logbf.o \
|
||||
math_logf.o \
|
||||
math_modf.o \
|
||||
math_modff.o \
|
||||
math_nan.o \
|
||||
math_nanf.o \
|
||||
math_nextafter.o \
|
||||
math_nextafterf.o \
|
||||
math_pow.o \
|
||||
math_powf.o \
|
||||
math_rint.o \
|
||||
math_rintf.o \
|
||||
math_scalbn.o \
|
||||
math_scalbnf.o \
|
||||
math_signbit.o \
|
||||
math_sin.o \
|
||||
math_sinh.o \
|
||||
math_sqrt.o \
|
||||
math_sqrtf.o \
|
||||
math_tan.o \
|
||||
math_tanh.o \
|
||||
stdio_asprintf.o \
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#
|
||||
# $Id: GNUmakefile.os4,v 1.59 2005-05-14 10:52:31 obarthel Exp $
|
||||
# $Id: GNUmakefile.os4,v 1.60 2005-05-29 14:45:29 obarthel Exp $
|
||||
#
|
||||
# :ts=8
|
||||
#
|
||||
@@ -520,53 +520,83 @@ MATH_LIB = \
|
||||
complex_crealf.o \
|
||||
complex_creall.o \
|
||||
math_acos.o \
|
||||
math_acosf.o \
|
||||
math_asin.o \
|
||||
math_asinf.o \
|
||||
math_atan.o \
|
||||
math_atan2.o \
|
||||
math_atan2f.o \
|
||||
math_atanf.o \
|
||||
math_cbrt.o \
|
||||
math_cbrtf.o \
|
||||
math_ceil.o \
|
||||
math_cos.o \
|
||||
math_cosh.o \
|
||||
math_ceilf.o \
|
||||
math_copysign.o \
|
||||
math_copysignf.o \
|
||||
math_cos.o \
|
||||
math_cosh.o \
|
||||
math_erf.o \
|
||||
math_erfc.o \
|
||||
math_erfcf.o \
|
||||
math_erff.o \
|
||||
math_exp.o \
|
||||
math_expf.o \
|
||||
math_expm1.o \
|
||||
math_expm1f.o \
|
||||
math_fabs.o \
|
||||
math_fabsf.o \
|
||||
math_floor.o \
|
||||
math_floorf.o \
|
||||
math_fmod.o \
|
||||
math_fmodf.o \
|
||||
math_fpclassify.o \
|
||||
math_inf.o \
|
||||
math_inff.o \
|
||||
math_isfinite.o \
|
||||
math_isunordered.o \
|
||||
math_signbit.o \
|
||||
math_frexp.o \
|
||||
math_frexpf.o \
|
||||
math_huge_val.o \
|
||||
math_huge_valf.o \
|
||||
math_hypot.o \
|
||||
math_ilogb.o \
|
||||
math_ilogbf.o \
|
||||
math_inf.o \
|
||||
math_inff.o \
|
||||
math_init_exit.o \
|
||||
math_isfinite.o \
|
||||
math_isunordered.o \
|
||||
math_kernel_cos.o \
|
||||
math_kernel_expm1.o \
|
||||
math_kernel_rem_pio2.o \
|
||||
math_kernel_scalbn.o \
|
||||
math_kernel_sin.o \
|
||||
math_kernel_tan.o \
|
||||
math_ldexp.o \
|
||||
math_ldexpf.o \
|
||||
math_log.o \
|
||||
math_log10.o \
|
||||
math_log10f.o \
|
||||
math_log1p.o \
|
||||
math_log1pf.o \
|
||||
math_logb.o \
|
||||
math_logbf.o \
|
||||
math_logf.o \
|
||||
math_modf.o \
|
||||
math_modff.o \
|
||||
math_nan.o \
|
||||
math_nanf.o \
|
||||
math_nextafter.o \
|
||||
math_nextafterf.o \
|
||||
math_pow.o \
|
||||
math_powf.o \
|
||||
math_rint.o \
|
||||
math_rintf.o \
|
||||
math_scalbn.o \
|
||||
math_scalbnf.o \
|
||||
math_signbit.o \
|
||||
math_sin.o \
|
||||
math_sinh.o \
|
||||
math_sqrt.o \
|
||||
math_sqrtf.o \
|
||||
math_tan.o \
|
||||
math_tanh.o \
|
||||
math_kernel_expm1.o \
|
||||
math_kernel_scalbn.o \
|
||||
math_kernel_tan.o \
|
||||
math_kernel_cos.o \
|
||||
math_kernel_rem_pio2.o \
|
||||
math_kernel_sin.o \
|
||||
stdio_asprintf.o \
|
||||
stdio_flush.o \
|
||||
stdio_flush_all_files.o \
|
||||
|
||||
44
library/TODO
44
library/TODO
@@ -1,51 +1,43 @@
|
||||
C99 math functions:
|
||||
|
||||
("float"-versions of existing "double" functions)
|
||||
acosf
|
||||
asinf
|
||||
atan2f
|
||||
atanf
|
||||
ceilf
|
||||
cosf
|
||||
expf
|
||||
floorf
|
||||
fmodf
|
||||
frexpf
|
||||
hypotf
|
||||
ldexpf
|
||||
log10f
|
||||
logbf
|
||||
logf
|
||||
modff
|
||||
powf
|
||||
sinf
|
||||
sqrtf
|
||||
tanf
|
||||
|
||||
(functions generally missing, plus their "float" counterparts)
|
||||
(functions generally missing, including their "float" counterparts)
|
||||
acosh
|
||||
acoshf
|
||||
asinh
|
||||
cbrt
|
||||
erfc
|
||||
asinhf
|
||||
exp2
|
||||
expm1
|
||||
fdim
|
||||
exp2f
|
||||
fma
|
||||
fmax
|
||||
fmin
|
||||
ilogb
|
||||
fmaf
|
||||
lgamma
|
||||
log1p
|
||||
lgammaf
|
||||
log2
|
||||
log2f
|
||||
lrint
|
||||
lrintf
|
||||
lround
|
||||
lroundf
|
||||
nearbyint
|
||||
nearbyintf
|
||||
nexttoward
|
||||
nexttowardf
|
||||
remainder
|
||||
remainderf
|
||||
remquo
|
||||
remquof
|
||||
round
|
||||
scalbn
|
||||
roundf
|
||||
sinh
|
||||
sinhf
|
||||
tanh
|
||||
tanhf
|
||||
tgamma
|
||||
tgammaf
|
||||
trunc
|
||||
truncf
|
||||
|
||||
@@ -61,7 +61,15 @@
|
||||
tanhf(), tgamma(), tgammaf(), trunc() and truncf(), to be filled in
|
||||
later...
|
||||
|
||||
- Implemented fmin()/fminf(), fmax()/fmaxf(), fdim()/fdimf() (C99).
|
||||
- Implemented fmin()/fminf(), fmax()/fmaxf(), fdim()/fdimf() for C99.
|
||||
|
||||
- Ported acosf(), asinf(), atan2f(), atanf(), ceilf(), expf(), floorf(),
|
||||
fmodf(), frexpf(), ldexpf(), log10f(), logbf(), logf(), modff(), powf(), sqrtf(),
|
||||
scalbn() and scalbnf() for C99.
|
||||
|
||||
- Ported cbrt(), cbrtf(), erf(), erff(), erfc(), erfcf(), expm1(),
|
||||
expm1f(), ilogb(), ilogbf(), log1p() and log1pf() for C99.
|
||||
|
||||
|
||||
|
||||
c.lib 1.192 (12.5.2005)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: math.h,v 1.12 2005-05-29 12:41:04 obarthel Exp $
|
||||
* $Id: math.h,v 1.13 2005-05-29 14:45:33 obarthel Exp $
|
||||
*
|
||||
* :ts=4
|
||||
*
|
||||
@@ -224,7 +224,25 @@ extern int __isunordered_double(double x,double y);
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
extern float acosf(float x);
|
||||
extern float asinf(float x);
|
||||
extern float atanf(float x);
|
||||
extern float atan2f(float y, float x);
|
||||
extern float ceilf(float x);
|
||||
|
||||
|
||||
extern float expf(float x);
|
||||
extern float fabsf(float x);
|
||||
extern float floorf(float x);
|
||||
extern float fmodf(float x, float y);
|
||||
extern float frexpf(float x, int *eptr);
|
||||
extern float ldexp(float x,int exp);
|
||||
extern float logf(float x);
|
||||
extern float log10f(float x);
|
||||
extern float logbf(float x);
|
||||
extern float modff(float x, float *iptr);
|
||||
extern float powf(float x, float y);
|
||||
extern float sqrtf(float x);
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
@@ -258,6 +276,41 @@ extern double fmax(double x,double y);
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
extern float scalbnf (float x, int n);
|
||||
extern double scalbn (double x, int n);
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
extern float cbrtf(float x);
|
||||
extern double cbrt(double x);
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
extern float erff(float x);
|
||||
extern double erf(double x);
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
extern float erfcf(float x);
|
||||
extern double erfc(double x);
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
extern float expm1f(float x);
|
||||
extern double expm1(double x);
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
extern int ilogbf(float x);
|
||||
extern int ilogb(double x);
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
extern float log1pf(float x);
|
||||
extern double log1p(double x);
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
#define FLT_EVAL_METHOD 0
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: math_acosf.c,v 1.1 2005-05-29 11:19:00 obarthel Exp $
|
||||
* $Id: math_acosf.c,v 1.2 2005-05-29 14:45:29 obarthel Exp $
|
||||
*
|
||||
* :ts=4
|
||||
*
|
||||
@@ -29,6 +29,18 @@
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*
|
||||
* PowerPC math library based in part on work by Sun Microsystems
|
||||
* 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.
|
||||
*
|
||||
*
|
||||
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
|
||||
*/
|
||||
|
||||
#ifndef _MATH_HEADERS_H
|
||||
@@ -41,11 +53,64 @@
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
static const float
|
||||
one = 1.0000000000e+00, /* 0x3F800000 */
|
||||
pi = 3.1415925026e+00, /* 0x40490fda */
|
||||
pio2_hi = 1.5707962513e+00, /* 0x3fc90fda */
|
||||
pio2_lo = 7.5497894159e-08, /* 0x33a22168 */
|
||||
pS0 = 1.6666667163e-01, /* 0x3e2aaaab */
|
||||
pS1 = -3.2556581497e-01, /* 0xbea6b090 */
|
||||
pS2 = 2.0121252537e-01, /* 0x3e4e0aa8 */
|
||||
pS3 = -4.0055535734e-02, /* 0xbd241146 */
|
||||
pS4 = 7.9153501429e-04, /* 0x3a4f7f04 */
|
||||
pS5 = 3.4793309169e-05, /* 0x3811ef08 */
|
||||
qS1 = -2.4033949375e+00, /* 0xc019d139 */
|
||||
qS2 = 2.0209457874e+00, /* 0x4001572d */
|
||||
qS3 = -6.8828397989e-01, /* 0xbf303361 */
|
||||
qS4 = 7.7038154006e-02; /* 0x3d9dc62e */
|
||||
|
||||
float
|
||||
acosf(float x)
|
||||
{
|
||||
/* ZZZ unimplemented */
|
||||
return(0);
|
||||
float z,p,q,r,w,s,c,df;
|
||||
LONG hx,ix;
|
||||
GET_FLOAT_WORD(hx,x);
|
||||
ix = hx&0x7fffffff;
|
||||
if(ix==0x3f800000) { /* |x|==1 */
|
||||
if(hx>0) return 0.0; /* acos(1) = 0 */
|
||||
else return pi+(float)2.0*pio2_lo; /* acos(-1)= pi */
|
||||
} else if(ix>0x3f800000) { /* |x| >= 1 */
|
||||
return (x-x)/(x-x); /* acos(|x|>1) is NaN */
|
||||
}
|
||||
if(ix<0x3f000000) { /* |x| < 0.5 */
|
||||
if(ix<=0x23000000) return pio2_hi+pio2_lo;/*if|x|<2**-57*/
|
||||
z = x*x;
|
||||
p = z*(pS0+z*(pS1+z*(pS2+z*(pS3+z*(pS4+z*pS5)))));
|
||||
q = one+z*(qS1+z*(qS2+z*(qS3+z*qS4)));
|
||||
r = p/q;
|
||||
return pio2_hi - (x - (pio2_lo-x*r));
|
||||
} else if (hx<0) { /* x < -0.5 */
|
||||
z = (one+x)*(float)0.5;
|
||||
p = z*(pS0+z*(pS1+z*(pS2+z*(pS3+z*(pS4+z*pS5)))));
|
||||
q = one+z*(qS1+z*(qS2+z*(qS3+z*qS4)));
|
||||
s = sqrtf(z);
|
||||
r = p/q;
|
||||
w = r*s-pio2_lo;
|
||||
return pi - (float)2.0*(s+w);
|
||||
} else { /* x > 0.5 */
|
||||
LONG idf;
|
||||
z = (one-x)*(float)0.5;
|
||||
s = sqrtf(z);
|
||||
df = s;
|
||||
GET_FLOAT_WORD(idf,df);
|
||||
SET_FLOAT_WORD(df,idf&0xfffff000U);
|
||||
c = (z-df*df)/(s+df);
|
||||
p = z*(pS0+z*(pS1+z*(pS2+z*(pS3+z*(pS4+z*pS5)))));
|
||||
q = one+z*(qS1+z*(qS2+z*(qS3+z*qS4)));
|
||||
r = p/q;
|
||||
w = r*s+c;
|
||||
return (float)2.0*(df+w);
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: math_asinf.c,v 1.1 2005-05-29 11:19:00 obarthel Exp $
|
||||
* $Id: math_asinf.c,v 1.2 2005-05-29 14:45:29 obarthel Exp $
|
||||
*
|
||||
* :ts=4
|
||||
*
|
||||
@@ -29,6 +29,18 @@
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*
|
||||
* PowerPC math library based in part on work by Sun Microsystems
|
||||
* 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.
|
||||
*
|
||||
*
|
||||
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
|
||||
*/
|
||||
|
||||
#ifndef _MATH_HEADERS_H
|
||||
@@ -41,11 +53,67 @@
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
static const float
|
||||
one = 1.0000000000e+00, /* 0x3F800000 */
|
||||
huge = 1.000e+30,
|
||||
pio2_hi = 1.5707962513e+00, /* 0x3fc90fda */
|
||||
pio2_lo = 7.5497894159e-08, /* 0x33a22168 */
|
||||
pio4_hi = 7.8539818525e-01, /* 0x3f490fdb */
|
||||
/* coefficient for R(x^2) */
|
||||
pS0 = 1.6666667163e-01, /* 0x3e2aaaab */
|
||||
pS1 = -3.2556581497e-01, /* 0xbea6b090 */
|
||||
pS2 = 2.0121252537e-01, /* 0x3e4e0aa8 */
|
||||
pS3 = -4.0055535734e-02, /* 0xbd241146 */
|
||||
pS4 = 7.9153501429e-04, /* 0x3a4f7f04 */
|
||||
pS5 = 3.4793309169e-05, /* 0x3811ef08 */
|
||||
qS1 = -2.4033949375e+00, /* 0xc019d139 */
|
||||
qS2 = 2.0209457874e+00, /* 0x4001572d */
|
||||
qS3 = -6.8828397989e-01, /* 0xbf303361 */
|
||||
qS4 = 7.7038154006e-02; /* 0x3d9dc62e */
|
||||
|
||||
float
|
||||
asinf(float x)
|
||||
{
|
||||
/* ZZZ unimplemented */
|
||||
return(0);
|
||||
float t=0.0,w,p,q,c,r,s;
|
||||
LONG hx,ix;
|
||||
GET_FLOAT_WORD(hx,x);
|
||||
ix = hx&0x7fffffff;
|
||||
if(ix==0x3f800000) {
|
||||
/* asin(1)=+-pi/2 with inexact */
|
||||
return x*pio2_hi+x*pio2_lo;
|
||||
} else if(ix> 0x3f800000) { /* |x|>= 1 */
|
||||
return (x-x)/(x-x); /* asin(|x|>1) is NaN */
|
||||
} else if (ix<0x3f000000) { /* |x|<0.5 */
|
||||
if(ix<0x32000000) { /* if |x| < 2**-27 */
|
||||
if(huge+x>one) return x;/* return x with inexact if x!=0*/
|
||||
} else
|
||||
t = x*x;
|
||||
p = t*(pS0+t*(pS1+t*(pS2+t*(pS3+t*(pS4+t*pS5)))));
|
||||
q = one+t*(qS1+t*(qS2+t*(qS3+t*qS4)));
|
||||
w = p/q;
|
||||
return x+x*w;
|
||||
}
|
||||
/* 1> |x|>= 0.5 */
|
||||
w = one-fabsf(x);
|
||||
t = w*(float)0.5;
|
||||
p = t*(pS0+t*(pS1+t*(pS2+t*(pS3+t*(pS4+t*pS5)))));
|
||||
q = one+t*(qS1+t*(qS2+t*(qS3+t*qS4)));
|
||||
s = sqrtf(t);
|
||||
if(ix>=0x3F79999A) { /* if |x| > 0.975 */
|
||||
w = p/q;
|
||||
t = pio2_hi-((float)2.0*(s+s*w)-pio2_lo);
|
||||
} else {
|
||||
LONG iw;
|
||||
w = s;
|
||||
GET_FLOAT_WORD(iw,w);
|
||||
SET_FLOAT_WORD(w,iw&0xfffff000U);
|
||||
c = (t-w*w)/(s+w);
|
||||
r = p/q;
|
||||
p = (float)2.0*s*r-(pio2_lo-(float)2.0*c);
|
||||
q = pio4_hi-(float)2.0*w;
|
||||
t = pio4_hi-(p-q);
|
||||
}
|
||||
if(hx>0) return t; else return -t;
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: math_atan2f.c,v 1.1 2005-05-29 11:19:00 obarthel Exp $
|
||||
* $Id: math_atan2f.c,v 1.2 2005-05-29 14:45:29 obarthel Exp $
|
||||
*
|
||||
* :ts=4
|
||||
*
|
||||
@@ -29,6 +29,18 @@
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*
|
||||
* PowerPC math library based in part on work by Sun Microsystems
|
||||
* 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.
|
||||
*
|
||||
*
|
||||
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
|
||||
*/
|
||||
|
||||
#ifndef _MATH_HEADERS_H
|
||||
@@ -41,11 +53,87 @@
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
static const float
|
||||
tiny = 1.0e-30,
|
||||
zero = 0.0,
|
||||
pi_o_4 = 7.8539818525e-01, /* 0x3f490fdb */
|
||||
pi_o_2 = 1.5707963705e+00, /* 0x3fc90fdb */
|
||||
pi = 3.1415925026e+00, /* 0x40490fda */
|
||||
pi_lo = 1.5099578832e-07; /* 0x34222168 */
|
||||
|
||||
float
|
||||
atan2f(float y,float x)
|
||||
atan2f(float y, float x)
|
||||
{
|
||||
/* ZZZ unimplemented */
|
||||
return(0);
|
||||
float z;
|
||||
LONG k,m,hx,hy,ix,iy;
|
||||
|
||||
GET_FLOAT_WORD(hx,x);
|
||||
ix = hx&0x7fffffff;
|
||||
GET_FLOAT_WORD(hy,y);
|
||||
iy = hy&0x7fffffff;
|
||||
if((ix>0x7f800000)||
|
||||
(iy>0x7f800000)) /* x or y is NaN */
|
||||
return x+y;
|
||||
if(hx==0x3f800000) return atanf(y); /* x=1.0 */
|
||||
m = ((hy>>31)&1)|((hx>>30)&2); /* 2*sign(x)+sign(y) */
|
||||
|
||||
/* when y = 0 */
|
||||
if(iy==0) {
|
||||
switch(m) {
|
||||
case 0:
|
||||
case 1: return y; /* atan(+-0,+anything)=+-0 */
|
||||
case 2: return pi+tiny;/* atan(+0,-anything) = pi */
|
||||
case 3: return -pi-tiny;/* atan(-0,-anything) =-pi */
|
||||
}
|
||||
}
|
||||
/* when x = 0 */
|
||||
if(ix==0) return (hy<0)? -pi_o_2-tiny: pi_o_2+tiny;
|
||||
|
||||
/* when x is INF */
|
||||
if(ix==0x7f800000) {
|
||||
if(iy==0x7f800000) {
|
||||
switch(m) {
|
||||
case 0: return pi_o_4+tiny;/* atan(+INF,+INF) */
|
||||
case 1: return -pi_o_4-tiny;/* atan(-INF,+INF) */
|
||||
case 2: return (float)3.0*pi_o_4+tiny;/*atan(+INF,-INF)*/
|
||||
case 3: return (float)-3.0*pi_o_4-tiny;/*atan(-INF,-INF)*/
|
||||
}
|
||||
} else {
|
||||
switch(m) {
|
||||
case 0: return zero ; /* atan(+...,+INF) */
|
||||
case 1: /* atan(-...,+INF) */
|
||||
{
|
||||
/* Make sure we return -0, not +0. If we
|
||||
say "return -zero;", GCC might optimize
|
||||
that with FLDZ, which we don't want. */
|
||||
return copysignf(zero, -1);
|
||||
}
|
||||
|
||||
case 2: return pi+tiny ; /* atan(+...,-INF) */
|
||||
case 3: return -pi-tiny ; /* atan(-...,-INF) */
|
||||
}
|
||||
}
|
||||
}
|
||||
/* when y is INF */
|
||||
if(iy==0x7f800000) return (hy<0)? -pi_o_2-tiny: pi_o_2+tiny;
|
||||
|
||||
/* compute y/x */
|
||||
k = (iy-ix)>>23;
|
||||
if(k > 60) z=pi_o_2+(float)0.5*pi_lo; /* |y/x| > 2**60 */
|
||||
else if(hx<0&&k<-60) z=0.0; /* |y|/x < -2**60 */
|
||||
else z=atanf(fabsf(y/x)); /* safe to do y/x */
|
||||
switch (m) {
|
||||
case 0: return z ; /* atan(+,+) */
|
||||
case 1: {
|
||||
__uint32_t zh;
|
||||
GET_FLOAT_WORD(zh,z);
|
||||
SET_FLOAT_WORD(z,zh ^ 0x80000000U);
|
||||
}
|
||||
return z ; /* atan(-,+) */
|
||||
case 2: return pi-(z-pi_lo);/* atan(+,-) */
|
||||
default: /* case 3 */
|
||||
return (z-pi_lo)-pi;/* atan(-,-) */
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: math_atanf.c,v 1.1 2005-05-29 11:19:00 obarthel Exp $
|
||||
* $Id: math_atanf.c,v 1.2 2005-05-29 14:45:29 obarthel Exp $
|
||||
*
|
||||
* :ts=4
|
||||
*
|
||||
@@ -29,6 +29,18 @@
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*
|
||||
* PowerPC math library based in part on work by Sun Microsystems
|
||||
* 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.
|
||||
*
|
||||
*
|
||||
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
|
||||
*/
|
||||
|
||||
#ifndef _MATH_HEADERS_H
|
||||
@@ -41,11 +53,82 @@
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
static const float atanhi[] = {
|
||||
4.6364760399e-01, /* atan(0.5)hi 0x3eed6338 */
|
||||
7.8539812565e-01, /* atan(1.0)hi 0x3f490fda */
|
||||
9.8279368877e-01, /* atan(1.5)hi 0x3f7b985e */
|
||||
1.5707962513e+00, /* atan(inf)hi 0x3fc90fda */
|
||||
};
|
||||
|
||||
static const float atanlo[] = {
|
||||
5.0121582440e-09, /* atan(0.5)lo 0x31ac3769 */
|
||||
3.7748947079e-08, /* atan(1.0)lo 0x33222168 */
|
||||
3.4473217170e-08, /* atan(1.5)lo 0x33140fb4 */
|
||||
7.5497894159e-08, /* atan(inf)lo 0x33a22168 */
|
||||
};
|
||||
|
||||
static const float aT[] = {
|
||||
3.3333334327e-01, /* 0x3eaaaaaa */
|
||||
-2.0000000298e-01, /* 0xbe4ccccd */
|
||||
1.4285714924e-01, /* 0x3e124925 */
|
||||
-1.1111110449e-01, /* 0xbde38e38 */
|
||||
9.0908870101e-02, /* 0x3dba2e6e */
|
||||
-7.6918758452e-02, /* 0xbd9d8795 */
|
||||
6.6610731184e-02, /* 0x3d886b35 */
|
||||
-5.8335702866e-02, /* 0xbd6ef16b */
|
||||
4.9768779427e-02, /* 0x3d4bda59 */
|
||||
-3.6531571299e-02, /* 0xbd15a221 */
|
||||
1.6285819933e-02, /* 0x3c8569d7 */
|
||||
};
|
||||
|
||||
static const float
|
||||
one = 1.0,
|
||||
huge = 1.0e30;
|
||||
|
||||
float
|
||||
atanf(float x)
|
||||
{
|
||||
/* ZZZ unimplemented */
|
||||
return(0);
|
||||
float w,s1,s2,z;
|
||||
LONG ix,hx,id;
|
||||
|
||||
GET_FLOAT_WORD(hx,x);
|
||||
ix = hx&0x7fffffff;
|
||||
if(ix>=0x50800000) { /* if |x| >= 2^34 */
|
||||
if(ix>0x7f800000)
|
||||
return x+x; /* NaN */
|
||||
if(hx>0) return atanhi[3]+atanlo[3];
|
||||
else return -atanhi[3]-atanlo[3];
|
||||
} if (ix < 0x3ee00000) { /* |x| < 0.4375 */
|
||||
if (ix < 0x31000000) { /* |x| < 2^-29 */
|
||||
if(huge+x>one) return x; /* raise inexact */
|
||||
}
|
||||
id = -1;
|
||||
} else {
|
||||
x = fabsf(x);
|
||||
if (ix < 0x3f980000) { /* |x| < 1.1875 */
|
||||
if (ix < 0x3f300000) { /* 7/16 <=|x|<11/16 */
|
||||
id = 0; x = ((float)2.0*x-one)/((float)2.0+x);
|
||||
} else { /* 11/16<=|x|< 19/16 */
|
||||
id = 1; x = (x-one)/(x+one);
|
||||
}
|
||||
} else {
|
||||
if (ix < 0x401c0000) { /* |x| < 2.4375 */
|
||||
id = 2; x = (x-(float)1.5)/(one+(float)1.5*x);
|
||||
} else { /* 2.4375 <= |x| < 2^66 */
|
||||
id = 3; x = -(float)1.0/x;
|
||||
}
|
||||
}}
|
||||
/* end of argument reduction */
|
||||
z = x*x;
|
||||
w = z*z;
|
||||
/* break sum from i=0 to 10 aT[i]z**(i+1) into odd and even poly */
|
||||
s1 = z*(aT[0]+w*(aT[2]+w*(aT[4]+w*(aT[6]+w*(aT[8]+w*aT[10])))));
|
||||
s2 = w*(aT[1]+w*(aT[3]+w*(aT[5]+w*(aT[7]+w*aT[9]))));
|
||||
if (id<0) return x - x*(s1+s2);
|
||||
else {
|
||||
z = atanhi[id] - ((x*(s1+s2) - atanlo[id]) - x);
|
||||
return (hx<0)? -z:z;
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: math_cbrt.c,v 1.1 2005-05-29 11:19:00 obarthel Exp $
|
||||
* $Id: math_cbrt.c,v 1.2 2005-05-29 14:45:29 obarthel Exp $
|
||||
*
|
||||
* :ts=4
|
||||
*
|
||||
@@ -29,6 +29,15 @@
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*
|
||||
* PowerPC math library based in part on work by Sun Microsystems
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef _MATH_HEADERS_H
|
||||
@@ -41,11 +50,64 @@
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
static const ULONG
|
||||
B1 = 715094163, /* B1 = (682-0.03306235651)*2**20 */
|
||||
B2 = 696219795; /* B2 = (664-0.03306235651)*2**20 */
|
||||
|
||||
static const double
|
||||
C = 5.42857142857142815906e-01, /* 19/35 = 0x3FE15F15, 0xF15F15F1 */
|
||||
D = -7.05306122448979611050e-01, /* -864/1225 = 0xBFE691DE, 0x2532C834 */
|
||||
E = 1.41428571428571436819e+00, /* 99/70 = 0x3FF6A0EA, 0x0EA0EA0F */
|
||||
F = 1.60714285714285720630e+00, /* 45/28 = 0x3FF9B6DB, 0x6DB6DB6E */
|
||||
G = 3.57142857142857150787e-01; /* 5/14 = 0x3FD6DB6D, 0xB6DB6DB7 */
|
||||
|
||||
double
|
||||
cbrt(double x)
|
||||
{
|
||||
/* ZZZ unimplemented */
|
||||
return(0);
|
||||
LONG hx;
|
||||
double r,s,t=0.0,w;
|
||||
ULONG sign;
|
||||
ULONG high,low;
|
||||
|
||||
GET_HIGH_WORD(hx,x);
|
||||
sign=hx&0x80000000U; /* sign= sign(x) */
|
||||
hx ^=sign;
|
||||
if(hx>=0x7ff00000) return(x+x); /* cbrt(NaN,INF) is itself */
|
||||
GET_LOW_WORD(low,x);
|
||||
if((hx|low)==0)
|
||||
return(x); /* cbrt(0) is itself */
|
||||
|
||||
SET_HIGH_WORD(x,hx); /* x <- |x| */
|
||||
/* rough cbrt to 5 bits */
|
||||
if(hx<0x00100000) /* subnormal number */
|
||||
{SET_HIGH_WORD(t,0x43500000); /* set t= 2**54 */
|
||||
t*=x; GET_HIGH_WORD(high,t); SET_HIGH_WORD(t,high/3+B2);
|
||||
}
|
||||
else
|
||||
SET_HIGH_WORD(t,hx/3+B1);
|
||||
|
||||
|
||||
/* new cbrt to 23 bits, may be implemented in single precision */
|
||||
r=t*t/x;
|
||||
s=C+r*t;
|
||||
t*=G+F/(s+E+D/s);
|
||||
|
||||
/* chopped to 20 bits and make it larger than cbrt(x) */
|
||||
GET_HIGH_WORD(high,t);
|
||||
INSERT_WORDS(t,high+0x00000001,0);
|
||||
|
||||
|
||||
/* one step newton iteration to 53 bits with error less than 0.667 ulps */
|
||||
s=t*t; /* t*t is exact */
|
||||
r=x/s;
|
||||
w=t+t;
|
||||
r=(r-t)/(w+r); /* r-s is exact */
|
||||
t=t+t*r;
|
||||
|
||||
/* retore the sign bit */
|
||||
GET_HIGH_WORD(high,t);
|
||||
SET_HIGH_WORD(t,high|sign);
|
||||
return(t);
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: math_cbrtf.c,v 1.1 2005-05-29 11:19:00 obarthel Exp $
|
||||
* $Id: math_cbrtf.c,v 1.2 2005-05-29 14:45:29 obarthel Exp $
|
||||
*
|
||||
* :ts=4
|
||||
*
|
||||
@@ -29,6 +29,18 @@
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*
|
||||
* PowerPC math library based in part on work by Sun Microsystems
|
||||
* 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.
|
||||
*
|
||||
*
|
||||
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
|
||||
*/
|
||||
|
||||
#ifndef _MATH_HEADERS_H
|
||||
@@ -41,11 +53,50 @@
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
static const ULONG
|
||||
B1 = 709958130, /* B1 = (84+2/3-0.03306235651)*2**23 */
|
||||
B2 = 642849266; /* B2 = (76+2/3-0.03306235651)*2**23 */
|
||||
|
||||
static const float
|
||||
C = 5.4285717010e-01, /* 19/35 = 0x3f0af8b0 */
|
||||
D = -7.0530611277e-01, /* -864/1225 = 0xbf348ef1 */
|
||||
E = 1.4142856598e+00, /* 99/70 = 0x3fb50750 */
|
||||
F = 1.6071428061e+00, /* 45/28 = 0x3fcdb6db */
|
||||
G = 3.5714286566e-01; /* 5/14 = 0x3eb6db6e */
|
||||
|
||||
float
|
||||
cbrtf(float x)
|
||||
{
|
||||
/* ZZZ unimplemented */
|
||||
return(0);
|
||||
LONG hx;
|
||||
float r,s,t;
|
||||
ULONG sign;
|
||||
ULONG high;
|
||||
|
||||
GET_FLOAT_WORD(hx,x);
|
||||
sign=hx&0x80000000U; /* sign= sign(x) */
|
||||
hx ^=sign;
|
||||
if(hx>=0x7f800000) return(x+x); /* cbrt(NaN,INF) is itself */
|
||||
if(hx==0)
|
||||
return(x); /* cbrt(0) is itself */
|
||||
|
||||
SET_FLOAT_WORD(x,hx); /* x <- |x| */
|
||||
/* rough cbrt to 5 bits */
|
||||
if(hx<0x00800000) /* subnormal number */
|
||||
{SET_FLOAT_WORD(t,0x4b800000); /* set t= 2**24 */
|
||||
t*=x; GET_FLOAT_WORD(high,t); SET_FLOAT_WORD(t,high/3+B2);
|
||||
}
|
||||
else
|
||||
SET_FLOAT_WORD(t,hx/3+B1);
|
||||
|
||||
/* new cbrt to 23 bits */
|
||||
r=t*t/x;
|
||||
s=C+r*t;
|
||||
t*=G+F/(s+E+D/s);
|
||||
|
||||
/* retore the sign bit */
|
||||
GET_FLOAT_WORD(high,t);
|
||||
SET_FLOAT_WORD(t,high|sign);
|
||||
return(t);
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: math_ceilf.c,v 1.1 2005-05-29 11:19:00 obarthel Exp $
|
||||
* $Id: math_ceilf.c,v 1.2 2005-05-29 14:45:29 obarthel Exp $
|
||||
*
|
||||
* :ts=4
|
||||
*
|
||||
@@ -29,6 +29,18 @@
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*
|
||||
* PowerPC math library based in part on work by Sun Microsystems
|
||||
* 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.
|
||||
*
|
||||
*
|
||||
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
|
||||
*/
|
||||
|
||||
#ifndef _MATH_HEADERS_H
|
||||
@@ -41,11 +53,35 @@
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
static const float huge = 1.0e30;
|
||||
|
||||
float
|
||||
ceilf(float x)
|
||||
{
|
||||
/* ZZZ unimplemented */
|
||||
return(0);
|
||||
LONG i0,j_0;
|
||||
ULONG i;
|
||||
GET_FLOAT_WORD(i0,x);
|
||||
j_0 = ((i0>>23)&0xff)-0x7f;
|
||||
if(j_0<23) {
|
||||
if(j_0<0) { /* raise inexact if x != 0 */
|
||||
if(huge+x>(float)0.0) {/* return 0*sign(x) if |x|<1 */
|
||||
if(i0<0) {i0=0x80000000U;}
|
||||
else if(i0!=0) { i0=0x3f800000;}
|
||||
}
|
||||
} else {
|
||||
i = (0x007fffff)>>j_0;
|
||||
if((i0&i)==0) return x; /* x is integral */
|
||||
if(huge+x>(float)0.0) { /* raise inexact flag */
|
||||
if(i0>0) i0 += (0x00800000)>>j_0;
|
||||
i0 &= (~i);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if(j_0==0x80) return x+x; /* inf or NaN */
|
||||
else return x; /* x is integral */
|
||||
}
|
||||
SET_FLOAT_WORD(x,i0);
|
||||
return x;
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: math_erf.c,v 1.1 2005-05-29 11:19:00 obarthel Exp $
|
||||
* $Id: math_erf.c,v 1.2 2005-05-29 14:45:29 obarthel Exp $
|
||||
*
|
||||
* :ts=4
|
||||
*
|
||||
@@ -29,6 +29,15 @@
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*
|
||||
* PowerPC math library based in part on work by Sun Microsystems
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef _MATH_HEADERS_H
|
||||
@@ -41,11 +50,131 @@
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
static const double
|
||||
tiny = 1e-300,
|
||||
half= 5.00000000000000000000e-01, /* 0x3FE00000, 0x00000000 */
|
||||
one = 1.00000000000000000000e+00, /* 0x3FF00000, 0x00000000 */
|
||||
two = 2.00000000000000000000e+00, /* 0x40000000, 0x00000000 */
|
||||
/* c = (float)0.84506291151 */
|
||||
erx = 8.45062911510467529297e-01, /* 0x3FEB0AC1, 0x60000000 */
|
||||
/*
|
||||
* Coefficients for approximation to erf on [0,0.84375]
|
||||
*/
|
||||
efx = 1.28379167095512586316e-01, /* 0x3FC06EBA, 0x8214DB69 */
|
||||
efx8= 1.02703333676410069053e+00, /* 0x3FF06EBA, 0x8214DB69 */
|
||||
pp0 = 1.28379167095512558561e-01, /* 0x3FC06EBA, 0x8214DB68 */
|
||||
pp1 = -3.25042107247001499370e-01, /* 0xBFD4CD7D, 0x691CB913 */
|
||||
pp2 = -2.84817495755985104766e-02, /* 0xBF9D2A51, 0xDBD7194F */
|
||||
pp3 = -5.77027029648944159157e-03, /* 0xBF77A291, 0x236668E4 */
|
||||
pp4 = -2.37630166566501626084e-05, /* 0xBEF8EAD6, 0x120016AC */
|
||||
qq1 = 3.97917223959155352819e-01, /* 0x3FD97779, 0xCDDADC09 */
|
||||
qq2 = 6.50222499887672944485e-02, /* 0x3FB0A54C, 0x5536CEBA */
|
||||
qq3 = 5.08130628187576562776e-03, /* 0x3F74D022, 0xC4D36B0F */
|
||||
qq4 = 1.32494738004321644526e-04, /* 0x3F215DC9, 0x221C1A10 */
|
||||
qq5 = -3.96022827877536812320e-06, /* 0xBED09C43, 0x42A26120 */
|
||||
/*
|
||||
* Coefficients for approximation to erf in [0.84375,1.25]
|
||||
*/
|
||||
pa0 = -2.36211856075265944077e-03, /* 0xBF6359B8, 0xBEF77538 */
|
||||
pa1 = 4.14856118683748331666e-01, /* 0x3FDA8D00, 0xAD92B34D */
|
||||
pa2 = -3.72207876035701323847e-01, /* 0xBFD7D240, 0xFBB8C3F1 */
|
||||
pa3 = 3.18346619901161753674e-01, /* 0x3FD45FCA, 0x805120E4 */
|
||||
pa4 = -1.10894694282396677476e-01, /* 0xBFBC6398, 0x3D3E28EC */
|
||||
pa5 = 3.54783043256182359371e-02, /* 0x3FA22A36, 0x599795EB */
|
||||
pa6 = -2.16637559486879084300e-03, /* 0xBF61BF38, 0x0A96073F */
|
||||
qa1 = 1.06420880400844228286e-01, /* 0x3FBB3E66, 0x18EEE323 */
|
||||
qa2 = 5.40397917702171048937e-01, /* 0x3FE14AF0, 0x92EB6F33 */
|
||||
qa3 = 7.18286544141962662868e-02, /* 0x3FB2635C, 0xD99FE9A7 */
|
||||
qa4 = 1.26171219808761642112e-01, /* 0x3FC02660, 0xE763351F */
|
||||
qa5 = 1.36370839120290507362e-02, /* 0x3F8BEDC2, 0x6B51DD1C */
|
||||
qa6 = 1.19844998467991074170e-02, /* 0x3F888B54, 0x5735151D */
|
||||
/*
|
||||
* Coefficients for approximation to erfc in [1.25,1/0.35]
|
||||
*/
|
||||
ra0 = -9.86494403484714822705e-03, /* 0xBF843412, 0x600D6435 */
|
||||
ra1 = -6.93858572707181764372e-01, /* 0xBFE63416, 0xE4BA7360 */
|
||||
ra2 = -1.05586262253232909814e+01, /* 0xC0251E04, 0x41B0E726 */
|
||||
ra3 = -6.23753324503260060396e+01, /* 0xC04F300A, 0xE4CBA38D */
|
||||
ra4 = -1.62396669462573470355e+02, /* 0xC0644CB1, 0x84282266 */
|
||||
ra5 = -1.84605092906711035994e+02, /* 0xC067135C, 0xEBCCABB2 */
|
||||
ra6 = -8.12874355063065934246e+01, /* 0xC0545265, 0x57E4D2F2 */
|
||||
ra7 = -9.81432934416914548592e+00, /* 0xC023A0EF, 0xC69AC25C */
|
||||
sa1 = 1.96512716674392571292e+01, /* 0x4033A6B9, 0xBD707687 */
|
||||
sa2 = 1.37657754143519042600e+02, /* 0x4061350C, 0x526AE721 */
|
||||
sa3 = 4.34565877475229228821e+02, /* 0x407B290D, 0xD58A1A71 */
|
||||
sa4 = 6.45387271733267880336e+02, /* 0x40842B19, 0x21EC2868 */
|
||||
sa5 = 4.29008140027567833386e+02, /* 0x407AD021, 0x57700314 */
|
||||
sa6 = 1.08635005541779435134e+02, /* 0x405B28A3, 0xEE48AE2C */
|
||||
sa7 = 6.57024977031928170135e+00, /* 0x401A47EF, 0x8E484A93 */
|
||||
sa8 = -6.04244152148580987438e-02, /* 0xBFAEEFF2, 0xEE749A62 */
|
||||
/*
|
||||
* Coefficients for approximation to erfc in [1/.35,28]
|
||||
*/
|
||||
rb0 = -9.86494292470009928597e-03, /* 0xBF843412, 0x39E86F4A */
|
||||
rb1 = -7.99283237680523006574e-01, /* 0xBFE993BA, 0x70C285DE */
|
||||
rb2 = -1.77579549177547519889e+01, /* 0xC031C209, 0x555F995A */
|
||||
rb3 = -1.60636384855821916062e+02, /* 0xC064145D, 0x43C5ED98 */
|
||||
rb4 = -6.37566443368389627722e+02, /* 0xC083EC88, 0x1375F228 */
|
||||
rb5 = -1.02509513161107724954e+03, /* 0xC0900461, 0x6A2E5992 */
|
||||
rb6 = -4.83519191608651397019e+02, /* 0xC07E384E, 0x9BDC383F */
|
||||
sb1 = 3.03380607434824582924e+01, /* 0x403E568B, 0x261D5190 */
|
||||
sb2 = 3.25792512996573918826e+02, /* 0x40745CAE, 0x221B9F0A */
|
||||
sb3 = 1.53672958608443695994e+03, /* 0x409802EB, 0x189D5118 */
|
||||
sb4 = 3.19985821950859553908e+03, /* 0x40A8FFB7, 0x688C246A */
|
||||
sb5 = 2.55305040643316442583e+03, /* 0x40A3F219, 0xCEDF3BE6 */
|
||||
sb6 = 4.74528541206955367215e+02, /* 0x407DA874, 0xE79FE763 */
|
||||
sb7 = -2.24409524465858183362e+01; /* 0xC03670E2, 0x42712D62 */
|
||||
|
||||
double
|
||||
erf(double x)
|
||||
{
|
||||
/* ZZZ unimplemented */
|
||||
return(0);
|
||||
LONG hx,ix,i;
|
||||
double R,S,P,Q,s,y,z,r;
|
||||
GET_HIGH_WORD(hx,x);
|
||||
ix = hx&0x7fffffff;
|
||||
if(ix>=0x7ff00000) { /* erf(nan)=nan */
|
||||
i = ((__uint32_t)hx>>31)<<1;
|
||||
return (double)(1-i)+one/x; /* erf(+-inf)=+-1 */
|
||||
}
|
||||
|
||||
if(ix < 0x3feb0000) { /* |x|<0.84375 */
|
||||
if(ix < 0x3e300000) { /* |x|<2**-28 */
|
||||
if (ix < 0x00800000)
|
||||
return 0.125*(8.0*x+efx8*x); /*avoid underflow */
|
||||
return x + efx*x;
|
||||
}
|
||||
z = x*x;
|
||||
r = pp0+z*(pp1+z*(pp2+z*(pp3+z*pp4)));
|
||||
s = one+z*(qq1+z*(qq2+z*(qq3+z*(qq4+z*qq5))));
|
||||
y = r/s;
|
||||
return x + x*y;
|
||||
}
|
||||
if(ix < 0x3ff40000) { /* 0.84375 <= |x| < 1.25 */
|
||||
s = fabs(x)-one;
|
||||
P = pa0+s*(pa1+s*(pa2+s*(pa3+s*(pa4+s*(pa5+s*pa6)))));
|
||||
Q = one+s*(qa1+s*(qa2+s*(qa3+s*(qa4+s*(qa5+s*qa6)))));
|
||||
if(hx>=0) return erx + P/Q; else return -erx - P/Q;
|
||||
}
|
||||
if (ix >= 0x40180000) { /* inf>|x|>=6 */
|
||||
if(hx>=0) return one-tiny; else return tiny-one;
|
||||
}
|
||||
x = fabs(x);
|
||||
s = one/(x*x);
|
||||
if(ix< 0x4006DB6E) { /* |x| < 1/0.35 */
|
||||
R=ra0+s*(ra1+s*(ra2+s*(ra3+s*(ra4+s*(
|
||||
ra5+s*(ra6+s*ra7))))));
|
||||
S=one+s*(sa1+s*(sa2+s*(sa3+s*(sa4+s*(
|
||||
sa5+s*(sa6+s*(sa7+s*sa8)))))));
|
||||
} else { /* |x| >= 1/0.35 */
|
||||
R=rb0+s*(rb1+s*(rb2+s*(rb3+s*(rb4+s*(
|
||||
rb5+s*rb6)))));
|
||||
S=one+s*(sb1+s*(sb2+s*(sb3+s*(sb4+s*(
|
||||
sb5+s*(sb6+s*sb7))))));
|
||||
}
|
||||
z = x;
|
||||
SET_LOW_WORD(z,0);
|
||||
r = exp(-z*z-0.5625)*exp((z-x)*(z+x)+R/S);
|
||||
if(hx>=0) return one-r/x; else return r/x-one;
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: math_erfc.c,v 1.1 2005-05-29 11:19:00 obarthel Exp $
|
||||
* $Id: math_erfc.c,v 1.2 2005-05-29 14:45:29 obarthel Exp $
|
||||
*
|
||||
* :ts=4
|
||||
*
|
||||
@@ -29,6 +29,15 @@
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*
|
||||
* PowerPC math library based in part on work by Sun Microsystems
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef _MATH_HEADERS_H
|
||||
@@ -41,11 +50,141 @@
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
static const double
|
||||
tiny = 1e-300,
|
||||
half= 5.00000000000000000000e-01, /* 0x3FE00000, 0x00000000 */
|
||||
one = 1.00000000000000000000e+00, /* 0x3FF00000, 0x00000000 */
|
||||
two = 2.00000000000000000000e+00, /* 0x40000000, 0x00000000 */
|
||||
/* c = (float)0.84506291151 */
|
||||
erx = 8.45062911510467529297e-01, /* 0x3FEB0AC1, 0x60000000 */
|
||||
/*
|
||||
* Coefficients for approximation to erf on [0,0.84375]
|
||||
*/
|
||||
efx = 1.28379167095512586316e-01, /* 0x3FC06EBA, 0x8214DB69 */
|
||||
efx8= 1.02703333676410069053e+00, /* 0x3FF06EBA, 0x8214DB69 */
|
||||
pp0 = 1.28379167095512558561e-01, /* 0x3FC06EBA, 0x8214DB68 */
|
||||
pp1 = -3.25042107247001499370e-01, /* 0xBFD4CD7D, 0x691CB913 */
|
||||
pp2 = -2.84817495755985104766e-02, /* 0xBF9D2A51, 0xDBD7194F */
|
||||
pp3 = -5.77027029648944159157e-03, /* 0xBF77A291, 0x236668E4 */
|
||||
pp4 = -2.37630166566501626084e-05, /* 0xBEF8EAD6, 0x120016AC */
|
||||
qq1 = 3.97917223959155352819e-01, /* 0x3FD97779, 0xCDDADC09 */
|
||||
qq2 = 6.50222499887672944485e-02, /* 0x3FB0A54C, 0x5536CEBA */
|
||||
qq3 = 5.08130628187576562776e-03, /* 0x3F74D022, 0xC4D36B0F */
|
||||
qq4 = 1.32494738004321644526e-04, /* 0x3F215DC9, 0x221C1A10 */
|
||||
qq5 = -3.96022827877536812320e-06, /* 0xBED09C43, 0x42A26120 */
|
||||
/*
|
||||
* Coefficients for approximation to erf in [0.84375,1.25]
|
||||
*/
|
||||
pa0 = -2.36211856075265944077e-03, /* 0xBF6359B8, 0xBEF77538 */
|
||||
pa1 = 4.14856118683748331666e-01, /* 0x3FDA8D00, 0xAD92B34D */
|
||||
pa2 = -3.72207876035701323847e-01, /* 0xBFD7D240, 0xFBB8C3F1 */
|
||||
pa3 = 3.18346619901161753674e-01, /* 0x3FD45FCA, 0x805120E4 */
|
||||
pa4 = -1.10894694282396677476e-01, /* 0xBFBC6398, 0x3D3E28EC */
|
||||
pa5 = 3.54783043256182359371e-02, /* 0x3FA22A36, 0x599795EB */
|
||||
pa6 = -2.16637559486879084300e-03, /* 0xBF61BF38, 0x0A96073F */
|
||||
qa1 = 1.06420880400844228286e-01, /* 0x3FBB3E66, 0x18EEE323 */
|
||||
qa2 = 5.40397917702171048937e-01, /* 0x3FE14AF0, 0x92EB6F33 */
|
||||
qa3 = 7.18286544141962662868e-02, /* 0x3FB2635C, 0xD99FE9A7 */
|
||||
qa4 = 1.26171219808761642112e-01, /* 0x3FC02660, 0xE763351F */
|
||||
qa5 = 1.36370839120290507362e-02, /* 0x3F8BEDC2, 0x6B51DD1C */
|
||||
qa6 = 1.19844998467991074170e-02, /* 0x3F888B54, 0x5735151D */
|
||||
/*
|
||||
* Coefficients for approximation to erfc in [1.25,1/0.35]
|
||||
*/
|
||||
ra0 = -9.86494403484714822705e-03, /* 0xBF843412, 0x600D6435 */
|
||||
ra1 = -6.93858572707181764372e-01, /* 0xBFE63416, 0xE4BA7360 */
|
||||
ra2 = -1.05586262253232909814e+01, /* 0xC0251E04, 0x41B0E726 */
|
||||
ra3 = -6.23753324503260060396e+01, /* 0xC04F300A, 0xE4CBA38D */
|
||||
ra4 = -1.62396669462573470355e+02, /* 0xC0644CB1, 0x84282266 */
|
||||
ra5 = -1.84605092906711035994e+02, /* 0xC067135C, 0xEBCCABB2 */
|
||||
ra6 = -8.12874355063065934246e+01, /* 0xC0545265, 0x57E4D2F2 */
|
||||
ra7 = -9.81432934416914548592e+00, /* 0xC023A0EF, 0xC69AC25C */
|
||||
sa1 = 1.96512716674392571292e+01, /* 0x4033A6B9, 0xBD707687 */
|
||||
sa2 = 1.37657754143519042600e+02, /* 0x4061350C, 0x526AE721 */
|
||||
sa3 = 4.34565877475229228821e+02, /* 0x407B290D, 0xD58A1A71 */
|
||||
sa4 = 6.45387271733267880336e+02, /* 0x40842B19, 0x21EC2868 */
|
||||
sa5 = 4.29008140027567833386e+02, /* 0x407AD021, 0x57700314 */
|
||||
sa6 = 1.08635005541779435134e+02, /* 0x405B28A3, 0xEE48AE2C */
|
||||
sa7 = 6.57024977031928170135e+00, /* 0x401A47EF, 0x8E484A93 */
|
||||
sa8 = -6.04244152148580987438e-02, /* 0xBFAEEFF2, 0xEE749A62 */
|
||||
/*
|
||||
* Coefficients for approximation to erfc in [1/.35,28]
|
||||
*/
|
||||
rb0 = -9.86494292470009928597e-03, /* 0xBF843412, 0x39E86F4A */
|
||||
rb1 = -7.99283237680523006574e-01, /* 0xBFE993BA, 0x70C285DE */
|
||||
rb2 = -1.77579549177547519889e+01, /* 0xC031C209, 0x555F995A */
|
||||
rb3 = -1.60636384855821916062e+02, /* 0xC064145D, 0x43C5ED98 */
|
||||
rb4 = -6.37566443368389627722e+02, /* 0xC083EC88, 0x1375F228 */
|
||||
rb5 = -1.02509513161107724954e+03, /* 0xC0900461, 0x6A2E5992 */
|
||||
rb6 = -4.83519191608651397019e+02, /* 0xC07E384E, 0x9BDC383F */
|
||||
sb1 = 3.03380607434824582924e+01, /* 0x403E568B, 0x261D5190 */
|
||||
sb2 = 3.25792512996573918826e+02, /* 0x40745CAE, 0x221B9F0A */
|
||||
sb3 = 1.53672958608443695994e+03, /* 0x409802EB, 0x189D5118 */
|
||||
sb4 = 3.19985821950859553908e+03, /* 0x40A8FFB7, 0x688C246A */
|
||||
sb5 = 2.55305040643316442583e+03, /* 0x40A3F219, 0xCEDF3BE6 */
|
||||
sb6 = 4.74528541206955367215e+02, /* 0x407DA874, 0xE79FE763 */
|
||||
sb7 = -2.24409524465858183362e+01; /* 0xC03670E2, 0x42712D62 */
|
||||
|
||||
double
|
||||
erfc(double x)
|
||||
{
|
||||
/* ZZZ unimplemented */
|
||||
return(0);
|
||||
LONG hx,ix;
|
||||
double R,S,P,Q,s,y,z,r;
|
||||
GET_HIGH_WORD(hx,x);
|
||||
ix = hx&0x7fffffff;
|
||||
if(ix>=0x7ff00000) { /* erfc(nan)=nan */
|
||||
/* erfc(+-inf)=0,2 */
|
||||
return (double)(((ULONG)hx>>31)<<1)+one/x;
|
||||
}
|
||||
|
||||
if(ix < 0x3feb0000) { /* |x|<0.84375 */
|
||||
if(ix < 0x3c700000) /* |x|<2**-56 */
|
||||
return one-x;
|
||||
z = x*x;
|
||||
r = pp0+z*(pp1+z*(pp2+z*(pp3+z*pp4)));
|
||||
s = one+z*(qq1+z*(qq2+z*(qq3+z*(qq4+z*qq5))));
|
||||
y = r/s;
|
||||
if(hx < 0x3fd00000) { /* x<1/4 */
|
||||
return one-(x+x*y);
|
||||
} else {
|
||||
r = x*y;
|
||||
r += (x-half);
|
||||
return half - r ;
|
||||
}
|
||||
}
|
||||
if(ix < 0x3ff40000) { /* 0.84375 <= |x| < 1.25 */
|
||||
s = fabs(x)-one;
|
||||
P = pa0+s*(pa1+s*(pa2+s*(pa3+s*(pa4+s*(pa5+s*pa6)))));
|
||||
Q = one+s*(qa1+s*(qa2+s*(qa3+s*(qa4+s*(qa5+s*qa6)))));
|
||||
if(hx>=0) {
|
||||
z = one-erx; return z - P/Q;
|
||||
} else {
|
||||
z = erx+P/Q; return one+z;
|
||||
}
|
||||
}
|
||||
if (ix < 0x403c0000) { /* |x|<28 */
|
||||
x = fabs(x);
|
||||
s = one/(x*x);
|
||||
if(ix< 0x4006DB6D) { /* |x| < 1/.35 ~ 2.857143*/
|
||||
R=ra0+s*(ra1+s*(ra2+s*(ra3+s*(ra4+s*(
|
||||
ra5+s*(ra6+s*ra7))))));
|
||||
S=one+s*(sa1+s*(sa2+s*(sa3+s*(sa4+s*(
|
||||
sa5+s*(sa6+s*(sa7+s*sa8)))))));
|
||||
} else { /* |x| >= 1/.35 ~ 2.857143 */
|
||||
if(hx<0&&ix>=0x40180000) return two-tiny;/* x < -6 */
|
||||
R=rb0+s*(rb1+s*(rb2+s*(rb3+s*(rb4+s*(
|
||||
rb5+s*rb6)))));
|
||||
S=one+s*(sb1+s*(sb2+s*(sb3+s*(sb4+s*(
|
||||
sb5+s*(sb6+s*sb7))))));
|
||||
}
|
||||
z = x;
|
||||
SET_LOW_WORD(z,0);
|
||||
r = exp(-z*z-0.5625)*
|
||||
exp((z-x)*(z+x)+R/S);
|
||||
if(hx>0) return r/x; else return two-r/x;
|
||||
} else {
|
||||
if(hx>0) return tiny*tiny; else return two-tiny;
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: math_erfcf.c,v 1.1 2005-05-29 11:19:00 obarthel Exp $
|
||||
* $Id: math_erfcf.c,v 1.2 2005-05-29 14:45:29 obarthel Exp $
|
||||
*
|
||||
* :ts=4
|
||||
*
|
||||
@@ -29,6 +29,18 @@
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*
|
||||
* PowerPC math library based in part on work by Sun Microsystems
|
||||
* 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.
|
||||
*
|
||||
*
|
||||
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
|
||||
*/
|
||||
|
||||
#ifndef _MATH_HEADERS_H
|
||||
@@ -41,11 +53,141 @@
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
static const float
|
||||
tiny = 1e-30,
|
||||
half= 5.0000000000e-01, /* 0x3F000000 */
|
||||
one = 1.0000000000e+00, /* 0x3F800000 */
|
||||
two = 2.0000000000e+00, /* 0x40000000 */
|
||||
/* c = (subfloat)0.84506291151 */
|
||||
erx = 8.4506291151e-01, /* 0x3f58560b */
|
||||
/*
|
||||
* Coefficients for approximation to erf on [0,0.84375]
|
||||
*/
|
||||
efx = 1.2837916613e-01, /* 0x3e0375d4 */
|
||||
efx8= 1.0270333290e+00, /* 0x3f8375d4 */
|
||||
pp0 = 1.2837916613e-01, /* 0x3e0375d4 */
|
||||
pp1 = -3.2504209876e-01, /* 0xbea66beb */
|
||||
pp2 = -2.8481749818e-02, /* 0xbce9528f */
|
||||
pp3 = -5.7702702470e-03, /* 0xbbbd1489 */
|
||||
pp4 = -2.3763017452e-05, /* 0xb7c756b1 */
|
||||
qq1 = 3.9791721106e-01, /* 0x3ecbbbce */
|
||||
qq2 = 6.5022252500e-02, /* 0x3d852a63 */
|
||||
qq3 = 5.0813062117e-03, /* 0x3ba68116 */
|
||||
qq4 = 1.3249473704e-04, /* 0x390aee49 */
|
||||
qq5 = -3.9602282413e-06, /* 0xb684e21a */
|
||||
/*
|
||||
* Coefficients for approximation to erf in [0.84375,1.25]
|
||||
*/
|
||||
pa0 = -2.3621185683e-03, /* 0xbb1acdc6 */
|
||||
pa1 = 4.1485610604e-01, /* 0x3ed46805 */
|
||||
pa2 = -3.7220788002e-01, /* 0xbebe9208 */
|
||||
pa3 = 3.1834661961e-01, /* 0x3ea2fe54 */
|
||||
pa4 = -1.1089469492e-01, /* 0xbde31cc2 */
|
||||
pa5 = 3.5478305072e-02, /* 0x3d1151b3 */
|
||||
pa6 = -2.1663755178e-03, /* 0xbb0df9c0 */
|
||||
qa1 = 1.0642088205e-01, /* 0x3dd9f331 */
|
||||
qa2 = 5.4039794207e-01, /* 0x3f0a5785 */
|
||||
qa3 = 7.1828655899e-02, /* 0x3d931ae7 */
|
||||
qa4 = 1.2617121637e-01, /* 0x3e013307 */
|
||||
qa5 = 1.3637083583e-02, /* 0x3c5f6e13 */
|
||||
qa6 = 1.1984500103e-02, /* 0x3c445aa3 */
|
||||
/*
|
||||
* Coefficients for approximation to erfc in [1.25,1/0.35]
|
||||
*/
|
||||
ra0 = -9.8649440333e-03, /* 0xbc21a093 */
|
||||
ra1 = -6.9385856390e-01, /* 0xbf31a0b7 */
|
||||
ra2 = -1.0558626175e+01, /* 0xc128f022 */
|
||||
ra3 = -6.2375331879e+01, /* 0xc2798057 */
|
||||
ra4 = -1.6239666748e+02, /* 0xc322658c */
|
||||
ra5 = -1.8460508728e+02, /* 0xc3389ae7 */
|
||||
ra6 = -8.1287437439e+01, /* 0xc2a2932b */
|
||||
ra7 = -9.8143291473e+00, /* 0xc11d077e */
|
||||
sa1 = 1.9651271820e+01, /* 0x419d35ce */
|
||||
sa2 = 1.3765776062e+02, /* 0x4309a863 */
|
||||
sa3 = 4.3456588745e+02, /* 0x43d9486f */
|
||||
sa4 = 6.4538726807e+02, /* 0x442158c9 */
|
||||
sa5 = 4.2900814819e+02, /* 0x43d6810b */
|
||||
sa6 = 1.0863500214e+02, /* 0x42d9451f */
|
||||
sa7 = 6.5702495575e+00, /* 0x40d23f7c */
|
||||
sa8 = -6.0424413532e-02, /* 0xbd777f97 */
|
||||
/*
|
||||
* Coefficients for approximation to erfc in [1/.35,28]
|
||||
*/
|
||||
rb0 = -9.8649431020e-03, /* 0xbc21a092 */
|
||||
rb1 = -7.9928326607e-01, /* 0xbf4c9dd4 */
|
||||
rb2 = -1.7757955551e+01, /* 0xc18e104b */
|
||||
rb3 = -1.6063638306e+02, /* 0xc320a2ea */
|
||||
rb4 = -6.3756646729e+02, /* 0xc41f6441 */
|
||||
rb5 = -1.0250950928e+03, /* 0xc480230b */
|
||||
rb6 = -4.8351919556e+02, /* 0xc3f1c275 */
|
||||
sb1 = 3.0338060379e+01, /* 0x41f2b459 */
|
||||
sb2 = 3.2579251099e+02, /* 0x43a2e571 */
|
||||
sb3 = 1.5367296143e+03, /* 0x44c01759 */
|
||||
sb4 = 3.1998581543e+03, /* 0x4547fdbb */
|
||||
sb5 = 2.5530502930e+03, /* 0x451f90ce */
|
||||
sb6 = 4.7452853394e+02, /* 0x43ed43a7 */
|
||||
sb7 = -2.2440952301e+01; /* 0xc1b38712 */
|
||||
|
||||
float
|
||||
erfcf(float x)
|
||||
{
|
||||
/* ZZZ unimplemented */
|
||||
return(0);
|
||||
LONG hx,ix;
|
||||
float R,S,P,Q,s,y,z,r;
|
||||
GET_FLOAT_WORD(hx,x);
|
||||
ix = hx&0x7fffffff;
|
||||
if(ix>=0x7f800000) { /* erfc(nan)=nan */
|
||||
/* erfc(+-inf)=0,2 */
|
||||
return (float)(((ULONG)hx>>31)<<1)+one/x;
|
||||
}
|
||||
|
||||
if(ix < 0x3f580000) { /* |x|<0.84375 */
|
||||
if(ix < 0x23800000) /* |x|<2**-56 */
|
||||
return one-x;
|
||||
z = x*x;
|
||||
r = pp0+z*(pp1+z*(pp2+z*(pp3+z*pp4)));
|
||||
s = one+z*(qq1+z*(qq2+z*(qq3+z*(qq4+z*qq5))));
|
||||
y = r/s;
|
||||
if(hx < 0x3e800000) { /* x<1/4 */
|
||||
return one-(x+x*y);
|
||||
} else {
|
||||
r = x*y;
|
||||
r += (x-half);
|
||||
return half - r ;
|
||||
}
|
||||
}
|
||||
if(ix < 0x3fa00000) { /* 0.84375 <= |x| < 1.25 */
|
||||
s = fabsf(x)-one;
|
||||
P = pa0+s*(pa1+s*(pa2+s*(pa3+s*(pa4+s*(pa5+s*pa6)))));
|
||||
Q = one+s*(qa1+s*(qa2+s*(qa3+s*(qa4+s*(qa5+s*qa6)))));
|
||||
if(hx>=0) {
|
||||
z = one-erx; return z - P/Q;
|
||||
} else {
|
||||
z = erx+P/Q; return one+z;
|
||||
}
|
||||
}
|
||||
if (ix < 0x41e00000) { /* |x|<28 */
|
||||
x = fabsf(x);
|
||||
s = one/(x*x);
|
||||
if(ix< 0x4036DB6D) { /* |x| < 1/.35 ~ 2.857143*/
|
||||
R=ra0+s*(ra1+s*(ra2+s*(ra3+s*(ra4+s*(
|
||||
ra5+s*(ra6+s*ra7))))));
|
||||
S=one+s*(sa1+s*(sa2+s*(sa3+s*(sa4+s*(
|
||||
sa5+s*(sa6+s*(sa7+s*sa8)))))));
|
||||
} else { /* |x| >= 1/.35 ~ 2.857143 */
|
||||
if(hx<0&&ix>=0x40c00000) return two-tiny;/* x < -6 */
|
||||
R=rb0+s*(rb1+s*(rb2+s*(rb3+s*(rb4+s*(
|
||||
rb5+s*rb6)))));
|
||||
S=one+s*(sb1+s*(sb2+s*(sb3+s*(sb4+s*(
|
||||
sb5+s*(sb6+s*sb7))))));
|
||||
}
|
||||
GET_FLOAT_WORD(ix,x);
|
||||
SET_FLOAT_WORD(z,ix&0xfffff000U);
|
||||
r = expf(-z*z-(float)0.5625)*
|
||||
expf((z-x)*(z+x)+R/S);
|
||||
if(hx>0) return r/x; else return two-r/x;
|
||||
} else {
|
||||
if(hx>0) return tiny*tiny; else return two-tiny;
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: math_erff.c,v 1.1 2005-05-29 11:19:00 obarthel Exp $
|
||||
* $Id: math_erff.c,v 1.2 2005-05-29 14:45:29 obarthel Exp $
|
||||
*
|
||||
* :ts=4
|
||||
*
|
||||
@@ -29,6 +29,18 @@
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*
|
||||
* PowerPC math library based in part on work by Sun Microsystems
|
||||
* 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.
|
||||
*
|
||||
*
|
||||
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
|
||||
*/
|
||||
|
||||
#ifndef _MATH_HEADERS_H
|
||||
@@ -41,11 +53,132 @@
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
static const float
|
||||
tiny = 1e-30,
|
||||
half= 5.0000000000e-01, /* 0x3F000000 */
|
||||
one = 1.0000000000e+00, /* 0x3F800000 */
|
||||
two = 2.0000000000e+00, /* 0x40000000 */
|
||||
/* c = (subfloat)0.84506291151 */
|
||||
erx = 8.4506291151e-01, /* 0x3f58560b */
|
||||
/*
|
||||
* Coefficients for approximation to erf on [0,0.84375]
|
||||
*/
|
||||
efx = 1.2837916613e-01, /* 0x3e0375d4 */
|
||||
efx8= 1.0270333290e+00, /* 0x3f8375d4 */
|
||||
pp0 = 1.2837916613e-01, /* 0x3e0375d4 */
|
||||
pp1 = -3.2504209876e-01, /* 0xbea66beb */
|
||||
pp2 = -2.8481749818e-02, /* 0xbce9528f */
|
||||
pp3 = -5.7702702470e-03, /* 0xbbbd1489 */
|
||||
pp4 = -2.3763017452e-05, /* 0xb7c756b1 */
|
||||
qq1 = 3.9791721106e-01, /* 0x3ecbbbce */
|
||||
qq2 = 6.5022252500e-02, /* 0x3d852a63 */
|
||||
qq3 = 5.0813062117e-03, /* 0x3ba68116 */
|
||||
qq4 = 1.3249473704e-04, /* 0x390aee49 */
|
||||
qq5 = -3.9602282413e-06, /* 0xb684e21a */
|
||||
/*
|
||||
* Coefficients for approximation to erf in [0.84375,1.25]
|
||||
*/
|
||||
pa0 = -2.3621185683e-03, /* 0xbb1acdc6 */
|
||||
pa1 = 4.1485610604e-01, /* 0x3ed46805 */
|
||||
pa2 = -3.7220788002e-01, /* 0xbebe9208 */
|
||||
pa3 = 3.1834661961e-01, /* 0x3ea2fe54 */
|
||||
pa4 = -1.1089469492e-01, /* 0xbde31cc2 */
|
||||
pa5 = 3.5478305072e-02, /* 0x3d1151b3 */
|
||||
pa6 = -2.1663755178e-03, /* 0xbb0df9c0 */
|
||||
qa1 = 1.0642088205e-01, /* 0x3dd9f331 */
|
||||
qa2 = 5.4039794207e-01, /* 0x3f0a5785 */
|
||||
qa3 = 7.1828655899e-02, /* 0x3d931ae7 */
|
||||
qa4 = 1.2617121637e-01, /* 0x3e013307 */
|
||||
qa5 = 1.3637083583e-02, /* 0x3c5f6e13 */
|
||||
qa6 = 1.1984500103e-02, /* 0x3c445aa3 */
|
||||
/*
|
||||
* Coefficients for approximation to erfc in [1.25,1/0.35]
|
||||
*/
|
||||
ra0 = -9.8649440333e-03, /* 0xbc21a093 */
|
||||
ra1 = -6.9385856390e-01, /* 0xbf31a0b7 */
|
||||
ra2 = -1.0558626175e+01, /* 0xc128f022 */
|
||||
ra3 = -6.2375331879e+01, /* 0xc2798057 */
|
||||
ra4 = -1.6239666748e+02, /* 0xc322658c */
|
||||
ra5 = -1.8460508728e+02, /* 0xc3389ae7 */
|
||||
ra6 = -8.1287437439e+01, /* 0xc2a2932b */
|
||||
ra7 = -9.8143291473e+00, /* 0xc11d077e */
|
||||
sa1 = 1.9651271820e+01, /* 0x419d35ce */
|
||||
sa2 = 1.3765776062e+02, /* 0x4309a863 */
|
||||
sa3 = 4.3456588745e+02, /* 0x43d9486f */
|
||||
sa4 = 6.4538726807e+02, /* 0x442158c9 */
|
||||
sa5 = 4.2900814819e+02, /* 0x43d6810b */
|
||||
sa6 = 1.0863500214e+02, /* 0x42d9451f */
|
||||
sa7 = 6.5702495575e+00, /* 0x40d23f7c */
|
||||
sa8 = -6.0424413532e-02, /* 0xbd777f97 */
|
||||
/*
|
||||
* Coefficients for approximation to erfc in [1/.35,28]
|
||||
*/
|
||||
rb0 = -9.8649431020e-03, /* 0xbc21a092 */
|
||||
rb1 = -7.9928326607e-01, /* 0xbf4c9dd4 */
|
||||
rb2 = -1.7757955551e+01, /* 0xc18e104b */
|
||||
rb3 = -1.6063638306e+02, /* 0xc320a2ea */
|
||||
rb4 = -6.3756646729e+02, /* 0xc41f6441 */
|
||||
rb5 = -1.0250950928e+03, /* 0xc480230b */
|
||||
rb6 = -4.8351919556e+02, /* 0xc3f1c275 */
|
||||
sb1 = 3.0338060379e+01, /* 0x41f2b459 */
|
||||
sb2 = 3.2579251099e+02, /* 0x43a2e571 */
|
||||
sb3 = 1.5367296143e+03, /* 0x44c01759 */
|
||||
sb4 = 3.1998581543e+03, /* 0x4547fdbb */
|
||||
sb5 = 2.5530502930e+03, /* 0x451f90ce */
|
||||
sb6 = 4.7452853394e+02, /* 0x43ed43a7 */
|
||||
sb7 = -2.2440952301e+01; /* 0xc1b38712 */
|
||||
|
||||
float
|
||||
erff(float x)
|
||||
{
|
||||
/* ZZZ unimplemented */
|
||||
return(0);
|
||||
LONG hx,ix,i;
|
||||
float R,S,P,Q,s,y,z,r;
|
||||
GET_FLOAT_WORD(hx,x);
|
||||
ix = hx&0x7fffffff;
|
||||
if(ix>=0x7f800000) { /* erf(nan)=nan */
|
||||
i = ((ULONG)hx>>31)<<1;
|
||||
return (float)(1-i)+one/x; /* erf(+-inf)=+-1 */
|
||||
}
|
||||
|
||||
if(ix < 0x3f580000) { /* |x|<0.84375 */
|
||||
if(ix < 0x31800000) { /* |x|<2**-28 */
|
||||
if (ix < 0x04000000)
|
||||
/*avoid underflow */
|
||||
return (float)0.125*((float)8.0*x+efx8*x);
|
||||
return x + efx*x;
|
||||
}
|
||||
z = x*x;
|
||||
r = pp0+z*(pp1+z*(pp2+z*(pp3+z*pp4)));
|
||||
s = one+z*(qq1+z*(qq2+z*(qq3+z*(qq4+z*qq5))));
|
||||
y = r/s;
|
||||
return x + x*y;
|
||||
}
|
||||
if(ix < 0x3fa00000) { /* 0.84375 <= |x| < 1.25 */
|
||||
s = fabsf(x)-one;
|
||||
P = pa0+s*(pa1+s*(pa2+s*(pa3+s*(pa4+s*(pa5+s*pa6)))));
|
||||
Q = one+s*(qa1+s*(qa2+s*(qa3+s*(qa4+s*(qa5+s*qa6)))));
|
||||
if(hx>=0) return erx + P/Q; else return -erx - P/Q;
|
||||
}
|
||||
if (ix >= 0x40c00000) { /* inf>|x|>=6 */
|
||||
if(hx>=0) return one-tiny; else return tiny-one;
|
||||
}
|
||||
x = fabsf(x);
|
||||
s = one/(x*x);
|
||||
if(ix< 0x4036DB6E) { /* |x| < 1/0.35 */
|
||||
R=ra0+s*(ra1+s*(ra2+s*(ra3+s*(ra4+s*(
|
||||
ra5+s*(ra6+s*ra7))))));
|
||||
S=one+s*(sa1+s*(sa2+s*(sa3+s*(sa4+s*(
|
||||
sa5+s*(sa6+s*(sa7+s*sa8)))))));
|
||||
} else { /* |x| >= 1/0.35 */
|
||||
R=rb0+s*(rb1+s*(rb2+s*(rb3+s*(rb4+s*(
|
||||
rb5+s*rb6)))));
|
||||
S=one+s*(sb1+s*(sb2+s*(sb3+s*(sb4+s*(
|
||||
sb5+s*(sb6+s*sb7))))));
|
||||
}
|
||||
GET_FLOAT_WORD(ix,x);
|
||||
SET_FLOAT_WORD(z,ix&0xfffff000U);
|
||||
r = expf(-z*z-(float)0.5625)*expf((z-x)*(z+x)+R/S);
|
||||
if(hx>=0) return one-r/x; else return r/x-one;
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: math_expf.c,v 1.1 2005-05-29 11:19:00 obarthel Exp $
|
||||
* $Id: math_expf.c,v 1.2 2005-05-29 14:45:29 obarthel Exp $
|
||||
*
|
||||
* :ts=4
|
||||
*
|
||||
@@ -29,6 +29,18 @@
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*
|
||||
* PowerPC math library based in part on work by Sun Microsystems
|
||||
* 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.
|
||||
*
|
||||
*
|
||||
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
|
||||
*/
|
||||
|
||||
#ifndef _MATH_HEADERS_H
|
||||
@@ -41,11 +53,82 @@
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
static const float
|
||||
one = 1.0,
|
||||
halF[2] = {0.5,-0.5,},
|
||||
huge = 1.0e+30,
|
||||
twom100 = 7.8886090522e-31, /* 2**-100=0x0d800000 */
|
||||
o_threshold= 8.872283911e+01, /* 0x42b17218 */
|
||||
u_threshold= -1.0397208405e+02, /* 0xc2cff1b5 */
|
||||
ln2HI[2] ={ 6.9313812256e-01, /* 0x3f317180 */
|
||||
-6.9313812256e-01,}, /* 0xbf317180 */
|
||||
ln2LO[2] ={ 9.0580006145e-06, /* 0x3717f7d1 */
|
||||
-9.0580006145e-06,}, /* 0xb717f7d1 */
|
||||
invln2 = 1.4426950216e+00, /* 0x3fb8aa3b */
|
||||
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 */
|
||||
|
||||
float
|
||||
expf(float x)
|
||||
{
|
||||
/* ZZZ unimplemented */
|
||||
return(0);
|
||||
float y,hi=0.0,lo=0.0,c,t;
|
||||
LONG k=0,xsb;
|
||||
ULONG hx;
|
||||
|
||||
GET_FLOAT_WORD(hx,x);
|
||||
xsb = (hx>>31)&1; /* sign bit of x */
|
||||
hx &= 0x7fffffff; /* high word of |x| */
|
||||
|
||||
/* filter out non-finite argument */
|
||||
if(hx >= 0x42b17218) { /* if |x|>=88.721... */
|
||||
if(hx == 0x42b17218) { /* if |x| == 88.7228... */
|
||||
if (xsb == 0)
|
||||
return FLT_MAX;
|
||||
}
|
||||
if(hx>0x7f800000)
|
||||
return x+x; /* NaN */
|
||||
if(hx==0x7f800000)
|
||||
return (xsb==0)? x:0.0; /* exp(+-inf)={inf,0} */
|
||||
if(x > o_threshold) return huge*huge; /* overflow */
|
||||
if(x < u_threshold) return twom100*twom100; /* underflow */
|
||||
}
|
||||
|
||||
/* argument reduction */
|
||||
if(hx > 0x3eb17218) { /* if |x| > 0.5 ln2 */
|
||||
if(hx < 0x3F851592) { /* and |x| < 1.5 ln2 */
|
||||
hi = x-ln2HI[xsb]; lo=ln2LO[xsb]; k = 1-xsb-xsb;
|
||||
} else {
|
||||
k = invln2*x+halF[xsb];
|
||||
t = k;
|
||||
hi = x - t*ln2HI[0]; /* t*ln2HI is exact here */
|
||||
lo = t*ln2LO[0];
|
||||
}
|
||||
x = hi - lo;
|
||||
}
|
||||
else if(hx < 0x31800000) { /* when |x|<2**-28 */
|
||||
if(huge+x>one) return one+x;/* trigger inexact */
|
||||
}
|
||||
else k = 0;
|
||||
|
||||
/* x is now in primary range */
|
||||
t = x*x;
|
||||
c = x - t*(P1+t*(P2+t*(P3+t*(P4+t*P5))));
|
||||
if(k==0) return one-((x*c)/(c-(float)2.0)-x);
|
||||
else y = one-((lo-(x*c)/((float)2.0-c))-hi);
|
||||
if(k >= -125) {
|
||||
ULONG hy;
|
||||
GET_FLOAT_WORD(hy,y);
|
||||
SET_FLOAT_WORD(y,hy+(k<<23)); /* add k to y's exponent */
|
||||
return y;
|
||||
} else {
|
||||
ULONG hy;
|
||||
GET_FLOAT_WORD(hy,y);
|
||||
SET_FLOAT_WORD(y,hy+((k+100)<<23)); /* add k to y's exponent */
|
||||
return y*twom100;
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: math_expm1.c,v 1.1 2005-05-29 11:19:00 obarthel Exp $
|
||||
* $Id: math_expm1.c,v 1.2 2005-05-29 14:45:32 obarthel Exp $
|
||||
*
|
||||
* :ts=4
|
||||
*
|
||||
@@ -29,6 +29,15 @@
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*
|
||||
* PowerPC math library based in part on work by Sun Microsystems
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef _MATH_HEADERS_H
|
||||
@@ -41,11 +50,112 @@
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
static const double
|
||||
one = 1.0,
|
||||
huge = 1.0e+300,
|
||||
tiny = 1.0e-300,
|
||||
o_threshold = 7.09782712893383973096e+02,/* 0x40862E42, 0xFEFA39EF */
|
||||
ln2_hi = 6.93147180369123816490e-01,/* 0x3fe62e42, 0xfee00000 */
|
||||
ln2_lo = 1.90821492927058770002e-10,/* 0x3dea39ef, 0x35793c76 */
|
||||
invln2 = 1.44269504088896338700e+00,/* 0x3ff71547, 0x652b82fe */
|
||||
/* scaled coefficients related to expm1 */
|
||||
Q1 = -3.33333333333331316428e-02, /* BFA11111 111110F4 */
|
||||
Q2 = 1.58730158725481460165e-03, /* 3F5A01A0 19FE5585 */
|
||||
Q3 = -7.93650757867487942473e-05, /* BF14CE19 9EAADBB7 */
|
||||
Q4 = 4.00821782732936239552e-06, /* 3ED0CFCA 86E65239 */
|
||||
Q5 = -2.01099218183624371326e-07; /* BE8AFDB7 6E09C32D */
|
||||
|
||||
double
|
||||
expm1(double x)
|
||||
{
|
||||
/* ZZZ unimplemented */
|
||||
return(0);
|
||||
double y,hi,lo,c=0.0,t,e,hxs,hfx,r1;
|
||||
LONG k,xsb;
|
||||
ULONG hx;
|
||||
|
||||
GET_HIGH_WORD(hx,x);
|
||||
xsb = hx&0x80000000U; /* sign bit of x */
|
||||
if(xsb==0) y=x; else y= -x; /* y = |x| */
|
||||
hx &= 0x7fffffff; /* high word of |x| */
|
||||
|
||||
/* filter out huge and non-finite argument */
|
||||
if(hx >= 0x4043687A) { /* if |x|>=56*ln2 */
|
||||
if(hx >= 0x40862E42) { /* if |x|>=709.78... */
|
||||
if(hx>=0x7ff00000) {
|
||||
ULONG low;
|
||||
GET_LOW_WORD(low,x);
|
||||
if(((hx&0xfffff)|low)!=0)
|
||||
return x+x; /* NaN */
|
||||
else return (xsb==0)? x:-1.0;/* exp(+-inf)={inf,-1} */
|
||||
}
|
||||
if(x > o_threshold) return huge*huge; /* overflow */
|
||||
}
|
||||
if(xsb!=0) { /* x < -56*ln2, return -1.0 with inexact */
|
||||
if(x+tiny<0.0) /* raise inexact */
|
||||
return tiny-one; /* return -1 */
|
||||
}
|
||||
}
|
||||
|
||||
/* argument reduction */
|
||||
if(hx > 0x3fd62e42) { /* if |x| > 0.5 ln2 */
|
||||
if(hx < 0x3FF0A2B2) { /* and |x| < 1.5 ln2 */
|
||||
if(xsb==0)
|
||||
{hi = x - ln2_hi; lo = ln2_lo; k = 1;}
|
||||
else
|
||||
{hi = x + ln2_hi; lo = -ln2_lo; k = -1;}
|
||||
} else {
|
||||
k = invln2*x+((xsb==0)?0.5:-0.5);
|
||||
t = k;
|
||||
hi = x - t*ln2_hi; /* t*ln2_hi is exact here */
|
||||
lo = t*ln2_lo;
|
||||
}
|
||||
x = hi - lo;
|
||||
c = (hi-x)-lo;
|
||||
}
|
||||
else if(hx < 0x3c900000) { /* when |x|<2**-54, return x */
|
||||
t = huge+x; /* return x with inexact flags when x!=0 */
|
||||
return x - (t-(huge+x));
|
||||
}
|
||||
else k = 0;
|
||||
|
||||
/* x is now in primary range */
|
||||
hfx = 0.5*x;
|
||||
hxs = x*hfx;
|
||||
r1 = one+hxs*(Q1+hxs*(Q2+hxs*(Q3+hxs*(Q4+hxs*Q5))));
|
||||
t = 3.0-r1*hfx;
|
||||
e = hxs*((r1-t)/(6.0 - x*t));
|
||||
if(k==0) return x - (x*e-hxs); /* c is 0 */
|
||||
else {
|
||||
e = (x*(e-c)-c);
|
||||
e -= hxs;
|
||||
if(k== -1) return 0.5*(x-e)-0.5;
|
||||
if(k==1) {
|
||||
if(x < -0.25) return -2.0*(e-(x+0.5));
|
||||
else return one+2.0*(x-e);
|
||||
}
|
||||
if (k <= -2 || k>56) { /* suffice to return exp(x)-1 */
|
||||
ULONG high;
|
||||
y = one-(e-x);
|
||||
GET_HIGH_WORD(high,y);
|
||||
SET_HIGH_WORD(y,high+(k<<20)); /* add k to y's exponent */
|
||||
return y-one;
|
||||
}
|
||||
t = one;
|
||||
if(k<20) {
|
||||
ULONG high;
|
||||
SET_HIGH_WORD(t,0x3ff00000 - (0x200000>>k)); /* t=1-2^-k */
|
||||
y = t-(e-x);
|
||||
GET_HIGH_WORD(high,y);
|
||||
SET_HIGH_WORD(y,high+(k<<20)); /* add k to y's exponent */
|
||||
} else {
|
||||
ULONG high;
|
||||
SET_HIGH_WORD(t,((0x3ff-k)<<20)); /* 2^-k */
|
||||
y = x-(e+t);
|
||||
y += one;
|
||||
GET_HIGH_WORD(high,y);
|
||||
SET_HIGH_WORD(y,high+(k<<20)); /* add k to y's exponent */
|
||||
}
|
||||
}
|
||||
return y;
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: math_expm1f.c,v 1.1 2005-05-29 11:19:00 obarthel Exp $
|
||||
* $Id: math_expm1f.c,v 1.2 2005-05-29 14:45:32 obarthel Exp $
|
||||
*
|
||||
* :ts=4
|
||||
*
|
||||
@@ -29,6 +29,18 @@
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*
|
||||
* PowerPC math library based in part on work by Sun Microsystems
|
||||
* 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.
|
||||
*
|
||||
*
|
||||
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
|
||||
*/
|
||||
|
||||
#ifndef _MATH_HEADERS_H
|
||||
@@ -41,11 +53,109 @@
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
static const float
|
||||
one = 1.0,
|
||||
huge = 1.0e+30,
|
||||
tiny = 1.0e-30,
|
||||
o_threshold = 8.8721679688e+01,/* 0x42b17180 */
|
||||
ln2_hi = 6.9313812256e-01,/* 0x3f317180 */
|
||||
ln2_lo = 9.0580006145e-06,/* 0x3717f7d1 */
|
||||
invln2 = 1.4426950216e+00,/* 0x3fb8aa3b */
|
||||
/* scaled coefficients related to expm1 */
|
||||
Q1 = -3.3333335072e-02, /* 0xbd088889 */
|
||||
Q2 = 1.5873016091e-03, /* 0x3ad00d01 */
|
||||
Q3 = -7.9365076090e-05, /* 0xb8a670cd */
|
||||
Q4 = 4.0082177293e-06, /* 0x36867e54 */
|
||||
Q5 = -2.0109921195e-07; /* 0xb457edbb */
|
||||
|
||||
float
|
||||
expm1f(float x)
|
||||
{
|
||||
/* ZZZ unimplemented */
|
||||
return(0);
|
||||
float y,hi,lo,c=0.0,t,e,hxs,hfx,r1;
|
||||
LONG k,xsb;
|
||||
ULONG hx;
|
||||
|
||||
GET_FLOAT_WORD(hx,x);
|
||||
xsb = hx&0x80000000U; /* sign bit of x */
|
||||
if(xsb==0) y=x; else y= -x; /* y = |x| */
|
||||
hx &= 0x7fffffff; /* high word of |x| */
|
||||
|
||||
/* filter out huge and non-finite argument */
|
||||
if(hx >= 0x4195b844) { /* if |x|>=27*ln2 */
|
||||
if(hx >= 0x42b17218) { /* if |x|>=88.721... */
|
||||
if(hx>0x7f800000)
|
||||
return x+x; /* NaN */
|
||||
if(hx==0x7f800000)
|
||||
return (xsb==0)? x:-1.0;/* exp(+-inf)={inf,-1} */
|
||||
if(x > o_threshold) return huge*huge; /* overflow */
|
||||
}
|
||||
if(xsb!=0) { /* x < -27*ln2, return -1.0 with inexact */
|
||||
if(x+tiny<(float)0.0) /* raise inexact */
|
||||
return tiny-one; /* return -1 */
|
||||
}
|
||||
}
|
||||
|
||||
/* argument reduction */
|
||||
if(hx > 0x3eb17218) { /* if |x| > 0.5 ln2 */
|
||||
if(hx < 0x3F851592) { /* and |x| < 1.5 ln2 */
|
||||
if(xsb==0)
|
||||
{hi = x - ln2_hi; lo = ln2_lo; k = 1;}
|
||||
else
|
||||
{hi = x + ln2_hi; lo = -ln2_lo; k = -1;}
|
||||
} else {
|
||||
k = invln2*x+((xsb==0)?(float)0.5:(float)-0.5);
|
||||
t = k;
|
||||
hi = x - t*ln2_hi; /* t*ln2_hi is exact here */
|
||||
lo = t*ln2_lo;
|
||||
}
|
||||
x = hi - lo;
|
||||
c = (hi-x)-lo;
|
||||
}
|
||||
else if(hx < 0x33000000) { /* when |x|<2**-25, return x */
|
||||
t = huge+x; /* return x with inexact flags when x!=0 */
|
||||
return x - (t-(huge+x));
|
||||
}
|
||||
else k = 0;
|
||||
|
||||
/* x is now in primary range */
|
||||
hfx = (float)0.5*x;
|
||||
hxs = x*hfx;
|
||||
r1 = one+hxs*(Q1+hxs*(Q2+hxs*(Q3+hxs*(Q4+hxs*Q5))));
|
||||
t = (float)3.0-r1*hfx;
|
||||
e = hxs*((r1-t)/((float)6.0 - x*t));
|
||||
if(k==0) return x - (x*e-hxs); /* c is 0 */
|
||||
else {
|
||||
e = (x*(e-c)-c);
|
||||
e -= hxs;
|
||||
if(k== -1) return (float)0.5*(x-e)-(float)0.5;
|
||||
if(k==1) {
|
||||
if(x < (float)-0.25) return -(float)2.0*(e-(x+(float)0.5));
|
||||
else return one+(float)2.0*(x-e);
|
||||
}
|
||||
if (k <= -2 || k>56) { /* suffice to return exp(x)-1 */
|
||||
LONG i;
|
||||
y = one-(e-x);
|
||||
GET_FLOAT_WORD(i,y);
|
||||
SET_FLOAT_WORD(y,i+(k<<23)); /* add k to y's exponent */
|
||||
return y-one;
|
||||
}
|
||||
t = one;
|
||||
if(k<23) {
|
||||
LONG i;
|
||||
SET_FLOAT_WORD(t,0x3f800000 - (0x1000000>>k)); /* t=1-2^-k */
|
||||
y = t-(e-x);
|
||||
GET_FLOAT_WORD(i,y);
|
||||
SET_FLOAT_WORD(y,i+(k<<23)); /* add k to y's exponent */
|
||||
} else {
|
||||
LONG i;
|
||||
SET_FLOAT_WORD(t,((0x7f-k)<<23)); /* 2^-k */
|
||||
y = x-(e+t);
|
||||
y += one;
|
||||
GET_FLOAT_WORD(i,y);
|
||||
SET_FLOAT_WORD(y,i+(k<<23)); /* add k to y's exponent */
|
||||
}
|
||||
}
|
||||
return y;
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: math_floorf.c,v 1.1 2005-05-29 11:19:01 obarthel Exp $
|
||||
* $Id: math_floorf.c,v 1.2 2005-05-29 14:45:32 obarthel Exp $
|
||||
*
|
||||
* :ts=4
|
||||
*
|
||||
@@ -41,11 +41,36 @@
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
static const float huge = 1.0e30;
|
||||
|
||||
float
|
||||
floorf(float x)
|
||||
{
|
||||
/* ZZZ unimplemented */
|
||||
return(0);
|
||||
LONG i0,j_0;
|
||||
ULONG i;
|
||||
GET_FLOAT_WORD(i0,x);
|
||||
j_0 = ((i0>>23)&0xff)-0x7f;
|
||||
if(j_0<23) {
|
||||
if(j_0<0) { /* raise inexact if x != 0 */
|
||||
if(huge+x>(float)0.0) {/* return 0*sign(x) if |x|<1 */
|
||||
if(i0>=0) {i0=0;}
|
||||
else if((i0&0x7fffffff)!=0)
|
||||
{ i0=0xbf800000U;}
|
||||
}
|
||||
} else {
|
||||
i = (0x007fffff)>>j_0;
|
||||
if((i0&i)==0) return x; /* x is integral */
|
||||
if(huge+x>(float)0.0) { /* raise inexact flag */
|
||||
if(i0<0) i0 += (0x00800000)>>j_0;
|
||||
i0 &= (~i);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if(j_0==0x80) return x+x; /* inf or NaN */
|
||||
else return x; /* x is integral */
|
||||
}
|
||||
SET_FLOAT_WORD(x,i0);
|
||||
return x;
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: math_fmodf.c,v 1.1 2005-05-29 11:19:01 obarthel Exp $
|
||||
* $Id: math_fmodf.c,v 1.2 2005-05-29 14:45:32 obarthel Exp $
|
||||
*
|
||||
* :ts=4
|
||||
*
|
||||
@@ -29,6 +29,18 @@
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*
|
||||
* PowerPC math library based in part on work by Sun Microsystems
|
||||
* 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.
|
||||
*
|
||||
*
|
||||
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
|
||||
*/
|
||||
|
||||
#ifndef _MATH_HEADERS_H
|
||||
@@ -41,11 +53,39 @@
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
static const float one = 1.0;
|
||||
|
||||
float
|
||||
fmodf(float x,float y)
|
||||
modff(float x, float *iptr)
|
||||
{
|
||||
/* ZZZ unimplemented */
|
||||
return(0);
|
||||
LONG i0,j_0;
|
||||
ULONG i;
|
||||
GET_FLOAT_WORD(i0,x);
|
||||
j_0 = ((i0>>23)&0xff)-0x7f; /* exponent of x */
|
||||
if(j_0<23) { /* integer part in x */
|
||||
if(j_0<0) { /* |x|<1 */
|
||||
SET_FLOAT_WORD(*iptr,i0&0x80000000U); /* *iptr = +-0 */
|
||||
return x;
|
||||
} else {
|
||||
i = (0x007fffff)>>j_0;
|
||||
if((i0&i)==0) { /* x is integral */
|
||||
ULONG ix;
|
||||
*iptr = x;
|
||||
GET_FLOAT_WORD(ix,x);
|
||||
SET_FLOAT_WORD(x,ix&0x80000000U); /* return +-0 */
|
||||
return x;
|
||||
} else {
|
||||
SET_FLOAT_WORD(*iptr,i0&(~i));
|
||||
return x - *iptr;
|
||||
}
|
||||
}
|
||||
} else { /* no fraction part */
|
||||
ULONG ix;
|
||||
*iptr = x*one;
|
||||
GET_FLOAT_WORD(ix,x);
|
||||
SET_FLOAT_WORD(x,ix&0x80000000U); /* return +-0 */
|
||||
return x;
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: math_frexpf.c,v 1.1 2005-05-29 11:19:01 obarthel Exp $
|
||||
* $Id: math_frexpf.c,v 1.2 2005-05-29 14:45:32 obarthel Exp $
|
||||
*
|
||||
* :ts=4
|
||||
*
|
||||
@@ -29,6 +29,18 @@
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*
|
||||
* PowerPC math library based in part on work by Sun Microsystems
|
||||
* 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.
|
||||
*
|
||||
*
|
||||
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
|
||||
*/
|
||||
|
||||
#ifndef _MATH_HEADERS_H
|
||||
@@ -41,11 +53,26 @@
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
static const float two25 = 3.3554432000e+07; /* 0x4c000000 */
|
||||
|
||||
float
|
||||
frexpf(float value,int * exp)
|
||||
frexpf(float x, int *eptr)
|
||||
{
|
||||
/* ZZZ unimplemented */
|
||||
return(0);
|
||||
LONG hx, ix;
|
||||
GET_FLOAT_WORD(hx,x);
|
||||
ix = 0x7fffffff&hx;
|
||||
*eptr = 0;
|
||||
if(ix>=0x7f800000||(ix==0)) return x; /* 0,inf,nan */
|
||||
if (ix<0x00800000) { /* subnormal */
|
||||
x *= two25;
|
||||
GET_FLOAT_WORD(hx,x);
|
||||
ix = hx&0x7fffffff;
|
||||
*eptr = -25;
|
||||
}
|
||||
*eptr += (ix>>23)-126;
|
||||
hx = (hx&0x807fffffU)|0x3f000000;
|
||||
SET_FLOAT_WORD(x,hx);
|
||||
return x;
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: math_ilogb.c,v 1.1 2005-05-29 11:19:01 obarthel Exp $
|
||||
* $Id: math_ilogb.c,v 1.2 2005-05-29 14:45:32 obarthel Exp $
|
||||
*
|
||||
* :ts=4
|
||||
*
|
||||
@@ -29,6 +29,15 @@
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*
|
||||
* PowerPC math library based in part on work by Sun Microsystems
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef _MATH_HEADERS_H
|
||||
@@ -41,11 +50,26 @@
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
double
|
||||
int
|
||||
ilogb(double x)
|
||||
{
|
||||
/* ZZZ unimplemented */
|
||||
return(0);
|
||||
LONG hx,lx,ix;
|
||||
|
||||
EXTRACT_WORDS(hx,lx,x);
|
||||
hx &= 0x7fffffff;
|
||||
if(hx<0x00100000) {
|
||||
if((hx|lx)==0)
|
||||
return - INT_MAX; /* ilogb(0) = 0x80000001 */
|
||||
else /* subnormal x */
|
||||
if(hx==0) {
|
||||
for (ix = -1043; lx>0; lx<<=1) ix -=1;
|
||||
} else {
|
||||
for (ix = -1022,hx<<=11; hx>0; hx<<=1) ix -=1;
|
||||
}
|
||||
return ix;
|
||||
}
|
||||
else if (hx<0x7ff00000) return (hx>>20)-1023;
|
||||
else return INT_MAX;
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: math_ilogbf.c,v 1.1 2005-05-29 11:19:01 obarthel Exp $
|
||||
* $Id: math_ilogbf.c,v 1.2 2005-05-29 14:45:32 obarthel Exp $
|
||||
*
|
||||
* :ts=4
|
||||
*
|
||||
@@ -29,6 +29,18 @@
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*
|
||||
* PowerPC math library based in part on work by Sun Microsystems
|
||||
* 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.
|
||||
*
|
||||
*
|
||||
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
|
||||
*/
|
||||
|
||||
#ifndef _MATH_HEADERS_H
|
||||
@@ -41,11 +53,22 @@
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
float
|
||||
int
|
||||
ilogbf(float x)
|
||||
{
|
||||
/* ZZZ unimplemented */
|
||||
return(0);
|
||||
LONG hx,ix;
|
||||
|
||||
GET_FLOAT_WORD(hx,x);
|
||||
hx &= 0x7fffffff;
|
||||
if(hx<0x00800000) {
|
||||
if(hx==0)
|
||||
return - INT_MAX; /* ilogb(0) = 0x80000001 */
|
||||
else /* subnormal x */
|
||||
for (ix = -126,hx<<=8; hx>0; hx<<=1) ix -=1;
|
||||
return ix;
|
||||
}
|
||||
else if (hx<0x7f800000) return (hx>>23)-127;
|
||||
else return INT_MAX;
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: math_ldexpf.c,v 1.1 2005-05-29 11:19:01 obarthel Exp $
|
||||
* $Id: math_ldexpf.c,v 1.2 2005-05-29 14:45:32 obarthel Exp $
|
||||
*
|
||||
* :ts=4
|
||||
*
|
||||
@@ -44,8 +44,21 @@
|
||||
float
|
||||
ldexpf(float x,int exp)
|
||||
{
|
||||
/* ZZZ unimplemented */
|
||||
return(0);
|
||||
float result;
|
||||
|
||||
if(isinf(x) || fpclassify(x) == FP_ZERO)
|
||||
{
|
||||
result = x;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = scalbnf(x,exp);
|
||||
|
||||
if(isinf(result) || (result < FLT_MIN || result > -FLT_MIN))
|
||||
__set_errno(ERANGE);
|
||||
}
|
||||
|
||||
return(result);
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: math_log10f.c,v 1.1 2005-05-29 11:19:01 obarthel Exp $
|
||||
* $Id: math_log10f.c,v 1.2 2005-05-29 14:45:32 obarthel Exp $
|
||||
*
|
||||
* :ts=4
|
||||
*
|
||||
@@ -29,6 +29,18 @@
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*
|
||||
* PowerPC math library based in part on work by Sun Microsystems
|
||||
* 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.
|
||||
*
|
||||
*
|
||||
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
|
||||
*/
|
||||
|
||||
#ifndef _MATH_HEADERS_H
|
||||
@@ -41,11 +53,38 @@
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
static const float
|
||||
two25 = 3.3554432000e+07, /* 0x4c000000 */
|
||||
ivln10 = 4.3429449201e-01, /* 0x3ede5bd9 */
|
||||
log10_2hi = 3.0102920532e-01, /* 0x3e9a2080 */
|
||||
log10_2lo = 7.9034151668e-07; /* 0x355427db */
|
||||
|
||||
static const float zero = 0.0;
|
||||
|
||||
float
|
||||
log10f(float x)
|
||||
{
|
||||
/* ZZZ unimplemented */
|
||||
return(0);
|
||||
float y,z;
|
||||
LONG i,k,hx;
|
||||
|
||||
GET_FLOAT_WORD(hx,x);
|
||||
|
||||
k=0;
|
||||
if (hx < 0x00800000) { /* x < 2**-126 */
|
||||
if ((hx&0x7fffffff)==0)
|
||||
return -two25/zero; /* log(+-0)=-inf */
|
||||
if (hx<0) return (x-x)/zero; /* log(-#) = NaN */
|
||||
k -= 25; x *= two25; /* subnormal number, scale up x */
|
||||
GET_FLOAT_WORD(hx,x);
|
||||
}
|
||||
if (hx >= 0x7f800000) return x+x;
|
||||
k += (hx>>23)-127;
|
||||
i = ((ULONG)k&0x80000000U)>>31;
|
||||
hx = (hx&0x007fffff)|((0x7f-i)<<23);
|
||||
y = (float)(k+i);
|
||||
SET_FLOAT_WORD(x,hx);
|
||||
z = y*log10_2lo + ivln10*logf(x);
|
||||
return z+y*log10_2hi;
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: math_log1p.c,v 1.1 2005-05-29 11:19:01 obarthel Exp $
|
||||
* $Id: math_log1p.c,v 1.2 2005-05-29 14:45:32 obarthel Exp $
|
||||
*
|
||||
* :ts=4
|
||||
*
|
||||
@@ -29,6 +29,15 @@
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*
|
||||
* PowerPC math library based in part on work by Sun Microsystems
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef _MATH_HEADERS_H
|
||||
@@ -41,11 +50,82 @@
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
static const double
|
||||
ln2_hi = 6.93147180369123816490e-01, /* 3fe62e42 fee00000 */
|
||||
ln2_lo = 1.90821492927058770002e-10, /* 3dea39ef 35793c76 */
|
||||
two54 = 1.80143985094819840000e+16, /* 43500000 00000000 */
|
||||
Lp1 = 6.666666666666735130e-01, /* 3FE55555 55555593 */
|
||||
Lp2 = 3.999999999940941908e-01, /* 3FD99999 9997FA04 */
|
||||
Lp3 = 2.857142874366239149e-01, /* 3FD24924 94229359 */
|
||||
Lp4 = 2.222219843214978396e-01, /* 3FCC71C5 1D8E78AF */
|
||||
Lp5 = 1.818357216161805012e-01, /* 3FC74664 96CB03DE */
|
||||
Lp6 = 1.531383769920937332e-01, /* 3FC39A09 D078C69F */
|
||||
Lp7 = 1.479819860511658591e-01; /* 3FC2F112 DF3E5244 */
|
||||
|
||||
static const double zero = 0.0;
|
||||
|
||||
double
|
||||
log1p(double x)
|
||||
{
|
||||
/* ZZZ unimplemented */
|
||||
return(0);
|
||||
double hfsq,f=0.0,c=0.0,s,z,R;
|
||||
volatile double u; /* so GCC never optimizes it away */
|
||||
LONG k,hx,hu=0.0,ax;
|
||||
|
||||
GET_HIGH_WORD(hx,x);
|
||||
ax = hx&0x7fffffff;
|
||||
|
||||
k = 1;
|
||||
if (hx < 0x3FDA827A) { /* x < 0.41422 */
|
||||
if(ax>=0x3ff00000) /* x <= -1.0 */
|
||||
return log(1+x); /* log1p(-1) */
|
||||
if(ax<0x3e200000) { /* |x| < 2**-29 */
|
||||
if(two54+x>zero /* raise inexact */
|
||||
&&ax<0x3c900000) /* |x| < 2**-54 */
|
||||
return x;
|
||||
else
|
||||
return x - x*x*0.5;
|
||||
}
|
||||
if(hx>0||hx<=((LONG)0xbfd2bec3U)) {
|
||||
k=0;f=x;hu=1;} /* -0.2929<x<0.41422 */
|
||||
}
|
||||
if (hx >= 0x7ff00000) return x+x;
|
||||
if(k!=0) {
|
||||
if(hx<0x43400000) {
|
||||
u = 1.0+x;
|
||||
GET_HIGH_WORD(hu,u);
|
||||
k = (hu>>20)-1023;
|
||||
c = (k>0)? 1.0-(u-x):x-(u-1.0);/* correction term */
|
||||
c /= u;
|
||||
} else {
|
||||
u = x;
|
||||
GET_HIGH_WORD(hu,u);
|
||||
k = (hu>>20)-1023;
|
||||
c = 0;
|
||||
}
|
||||
hu &= 0x000fffff;
|
||||
if(hu<0x6a09e) {
|
||||
SET_HIGH_WORD(u,hu|0x3ff00000); /* normalize u */
|
||||
} else {
|
||||
k += 1;
|
||||
SET_HIGH_WORD(u,hu|0x3fe00000); /* normalize u/2 */
|
||||
hu = (0x00100000-hu)>>2;
|
||||
}
|
||||
f = u-1.0;
|
||||
}
|
||||
hfsq=0.5*f*f;
|
||||
if(hu==0) { /* |f| < 2**-20 */
|
||||
if(f==zero) { if(k==0) return zero;
|
||||
else {c += k*ln2_lo; return k*ln2_hi+c;}
|
||||
}
|
||||
R = hfsq*(1.0-0.66666666666666666*f);
|
||||
if(k==0) return f-R; else
|
||||
return k*ln2_hi-((R-(k*ln2_lo+c))-f);
|
||||
}
|
||||
s = f/(2.0+f);
|
||||
z = s*s;
|
||||
R = z*(Lp1+z*(Lp2+z*(Lp3+z*(Lp4+z*(Lp5+z*(Lp6+z*Lp7))))));
|
||||
if(k==0) return f-(hfsq-s*(hfsq+R)); else
|
||||
return k*ln2_hi-((hfsq-(s*(hfsq+R)+(k*ln2_lo+c)))-f);
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: math_log1pf.c,v 1.1 2005-05-29 11:19:01 obarthel Exp $
|
||||
* $Id: math_log1pf.c,v 1.2 2005-05-29 14:45:32 obarthel Exp $
|
||||
*
|
||||
* :ts=4
|
||||
*
|
||||
@@ -29,6 +29,18 @@
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*
|
||||
* PowerPC math library based in part on work by Sun Microsystems
|
||||
* 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.
|
||||
*
|
||||
*
|
||||
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
|
||||
*/
|
||||
|
||||
#ifndef _MATH_HEADERS_H
|
||||
@@ -41,11 +53,83 @@
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
static const float
|
||||
ln2_hi = 6.9313812256e-01, /* 0x3f317180 */
|
||||
ln2_lo = 9.0580006145e-06, /* 0x3717f7d1 */
|
||||
two25 = 3.355443200e+07, /* 0x4c000000 */
|
||||
Lp1 = 6.6666668653e-01, /* 3F2AAAAB */
|
||||
Lp2 = 4.0000000596e-01, /* 3ECCCCCD */
|
||||
Lp3 = 2.8571429849e-01, /* 3E924925 */
|
||||
Lp4 = 2.2222198546e-01, /* 3E638E29 */
|
||||
Lp5 = 1.8183572590e-01, /* 3E3A3325 */
|
||||
Lp6 = 1.5313838422e-01, /* 3E1CD04F */
|
||||
Lp7 = 1.4798198640e-01; /* 3E178897 */
|
||||
|
||||
static const float zero = 0.0;
|
||||
|
||||
float
|
||||
log1pf(float x)
|
||||
{
|
||||
/* ZZZ unimplemented */
|
||||
return(0);
|
||||
float hfsq,f=0.0,c=0.0,s,z,R;
|
||||
volatile float u; /* so GCC doesn't optimize it away */
|
||||
LONG k,hx,hu=0.0,ax;
|
||||
|
||||
GET_FLOAT_WORD(hx,x);
|
||||
ax = hx&0x7fffffff;
|
||||
|
||||
k = 1;
|
||||
if (hx < 0x3ed413d7) { /* x < 0.41422 */
|
||||
if(ax>=0x3f800000) /* x <= -1.0 */
|
||||
return logf(1+x); /* log1p(x<=-1) */
|
||||
if(ax<0x31000000) { /* |x| < 2**-29 */
|
||||
if(two25+x>zero /* raise inexact */
|
||||
&&ax<0x24800000) /* |x| < 2**-54 */
|
||||
return x;
|
||||
else
|
||||
return x - x*x*(float)0.5;
|
||||
}
|
||||
if(hx>0||hx<=((LONG)0xbe95f61fU)) {
|
||||
k=0;f=x;hu=1;} /* -0.2929<x<0.41422 */
|
||||
}
|
||||
if (hx >= 0x7f800000) return x+x;
|
||||
if(k!=0) {
|
||||
if(hx<0x5a000000) {
|
||||
u = (float)1.0+x;
|
||||
GET_FLOAT_WORD(hu,u);
|
||||
k = (hu>>23)-127;
|
||||
/* correction term */
|
||||
c = (k>0)? (float)1.0-(u-x):x-(u-(float)1.0);
|
||||
c /= u;
|
||||
} else {
|
||||
u = x;
|
||||
GET_FLOAT_WORD(hu,u);
|
||||
k = (hu>>23)-127;
|
||||
c = 0;
|
||||
}
|
||||
hu &= 0x007fffff;
|
||||
if(hu<0x3504f7) {
|
||||
SET_FLOAT_WORD(u,hu|0x3f800000);/* normalize u */
|
||||
} else {
|
||||
k += 1;
|
||||
SET_FLOAT_WORD(u,hu|0x3f000000); /* normalize u/2 */
|
||||
hu = (0x00800000-hu)>>2;
|
||||
}
|
||||
f = u-(float)1.0;
|
||||
}
|
||||
hfsq=(float)0.5*f*f;
|
||||
if(hu==0) { /* |f| < 2**-20 */
|
||||
if(f==zero) { if(k==0) return zero;
|
||||
else {c += k*ln2_lo; return k*ln2_hi+c;}
|
||||
}
|
||||
R = hfsq*((float)1.0-(float)0.66666666666666666*f);
|
||||
if(k==0) return f-R; else
|
||||
return k*ln2_hi-((R-(k*ln2_lo+c))-f);
|
||||
}
|
||||
s = f/((float)2.0+f);
|
||||
z = s*s;
|
||||
R = z*(Lp1+z*(Lp2+z*(Lp3+z*(Lp4+z*(Lp5+z*(Lp6+z*Lp7))))));
|
||||
if(k==0) return f-(hfsq-s*(hfsq+R)); else
|
||||
return k*ln2_hi-((hfsq-(s*(hfsq+R)+(k*ln2_lo+c)))-f);
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: math_logbf.c,v 1.1 2005-05-29 11:19:01 obarthel Exp $
|
||||
* $Id: math_logbf.c,v 1.2 2005-05-29 14:45:32 obarthel Exp $
|
||||
*
|
||||
* :ts=4
|
||||
*
|
||||
@@ -29,6 +29,18 @@
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*
|
||||
* PowerPC math library based in part on work by Sun Microsystems
|
||||
* 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.
|
||||
*
|
||||
*
|
||||
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
|
||||
*/
|
||||
|
||||
#ifndef _MATH_HEADERS_H
|
||||
@@ -44,8 +56,15 @@
|
||||
float
|
||||
logbf(float x)
|
||||
{
|
||||
/* ZZZ unimplemented */
|
||||
return(0);
|
||||
LONG ix;
|
||||
GET_FLOAT_WORD(ix,x);
|
||||
ix &= 0x7fffffff; /* high |x| */
|
||||
if(ix==0) return (float)-1.0/fabsf(x);
|
||||
if(ix>=0x7f800000) return x*x;
|
||||
if((ix>>=23)==0) /* IEEE 754 logb */
|
||||
return -126.0;
|
||||
else
|
||||
return (float) (ix-127);
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: math_logf.c,v 1.1 2005-05-29 11:19:01 obarthel Exp $
|
||||
* $Id: math_logf.c,v 1.2 2005-05-29 14:45:32 obarthel Exp $
|
||||
*
|
||||
* :ts=4
|
||||
*
|
||||
@@ -29,6 +29,18 @@
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*
|
||||
* PowerPC math library based in part on work by Sun Microsystems
|
||||
* 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.
|
||||
*
|
||||
*
|
||||
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
|
||||
*/
|
||||
|
||||
#ifndef _MATH_HEADERS_H
|
||||
@@ -41,11 +53,69 @@
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
static const float
|
||||
ln2_hi = 6.9313812256e-01, /* 0x3f317180 */
|
||||
ln2_lo = 9.0580006145e-06, /* 0x3717f7d1 */
|
||||
two25 = 3.355443200e+07, /* 0x4c000000 */
|
||||
Lg1 = 6.6666668653e-01, /* 3F2AAAAB */
|
||||
Lg2 = 4.0000000596e-01, /* 3ECCCCCD */
|
||||
Lg3 = 2.8571429849e-01, /* 3E924925 */
|
||||
Lg4 = 2.2222198546e-01, /* 3E638E29 */
|
||||
Lg5 = 1.8183572590e-01, /* 3E3A3325 */
|
||||
Lg6 = 1.5313838422e-01, /* 3E1CD04F */
|
||||
Lg7 = 1.4798198640e-01; /* 3E178897 */
|
||||
|
||||
static const float zero = 0.0;
|
||||
|
||||
float
|
||||
logf(float x)
|
||||
{
|
||||
/* ZZZ unimplemented */
|
||||
return(0);
|
||||
float hfsq,f,s,z,R,w,t1,t2,dk;
|
||||
LONG k,ix,i,j;
|
||||
|
||||
GET_FLOAT_WORD(ix,x);
|
||||
|
||||
k=0;
|
||||
if (ix < 0x00800000) { /* x < 2**-126 */
|
||||
if ((ix&0x7fffffff)==0)
|
||||
return -two25/zero; /* log(+-0)=-inf */
|
||||
if (ix<0) return (x-x)/zero; /* log(-#) = NaN */
|
||||
k -= 25; x *= two25; /* subnormal number, scale up x */
|
||||
GET_FLOAT_WORD(ix,x);
|
||||
}
|
||||
if (ix >= 0x7f800000) return x+x;
|
||||
k += (ix>>23)-127;
|
||||
ix &= 0x007fffff;
|
||||
i = (ix+(0x95f64<<3))&0x800000;
|
||||
SET_FLOAT_WORD(x,ix|(i^0x3f800000)); /* normalize x or x/2 */
|
||||
k += (i>>23);
|
||||
f = x-(float)1.0;
|
||||
if((0x007fffff&(15+ix))<16) { /* |f| < 2**-20 */
|
||||
if(f==zero) { if(k==0) return zero; else {dk=(float)k;
|
||||
return dk*ln2_hi+dk*ln2_lo;}
|
||||
}
|
||||
R = f*f*((float)0.5-(float)0.33333333333333333*f);
|
||||
if(k==0) return f-R; else {dk=(float)k;
|
||||
return dk*ln2_hi-((R-dk*ln2_lo)-f);}
|
||||
}
|
||||
s = f/((float)2.0+f);
|
||||
dk = (float)k;
|
||||
z = s*s;
|
||||
i = ix-(0x6147a<<3);
|
||||
w = z*z;
|
||||
j = (0x6b851<<3)-ix;
|
||||
t1= w*(Lg2+w*(Lg4+w*Lg6));
|
||||
t2= z*(Lg1+w*(Lg3+w*(Lg5+w*Lg7)));
|
||||
i |= j;
|
||||
R = t2+t1;
|
||||
if(i>0) {
|
||||
hfsq=(float)0.5*f*f;
|
||||
if(k==0) return f-(hfsq-s*(hfsq+R)); else
|
||||
return dk*ln2_hi-((hfsq-(s*(hfsq+R)+dk*ln2_lo))-f);
|
||||
} else {
|
||||
if(k==0) return f-s*(f-R); else
|
||||
return dk*ln2_hi-((s*(f-R)-dk*ln2_lo)-f);
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: math_modff.c,v 1.1 2005-05-29 11:19:01 obarthel Exp $
|
||||
* $Id: math_modff.c,v 1.2 2005-05-29 14:45:32 obarthel Exp $
|
||||
*
|
||||
* :ts=4
|
||||
*
|
||||
@@ -29,6 +29,18 @@
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*
|
||||
* PowerPC math library based in part on work by Sun Microsystems
|
||||
* 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.
|
||||
*
|
||||
*
|
||||
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
|
||||
*/
|
||||
|
||||
#ifndef _MATH_HEADERS_H
|
||||
@@ -41,11 +53,82 @@
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
static const float one = 1.0, Zero[] = {0.0, -0.0,};
|
||||
|
||||
float
|
||||
modff(float value,float *nptr)
|
||||
fmodf(float x, float y)
|
||||
{
|
||||
/* ZZZ unimplemented */
|
||||
return(0);
|
||||
LONG n,hx,hy,hz,ix,iy,sx,i;
|
||||
|
||||
GET_FLOAT_WORD(hx,x);
|
||||
GET_FLOAT_WORD(hy,y);
|
||||
sx = hx&0x80000000U; /* sign of x */
|
||||
hx ^=sx; /* |x| */
|
||||
hy &= 0x7fffffff; /* |y| */
|
||||
|
||||
/* purge off exception values */
|
||||
if(hy==0||(hx>=0x7f800000)|| /* y=0,or x not finite */
|
||||
(hy>0x7f800000)) /* or y is NaN */
|
||||
return (x*y)/(x*y);
|
||||
if(hx<hy) return x; /* |x|<|y| return x */
|
||||
if(hx==hy)
|
||||
return Zero[(ULONG)sx>>31]; /* |x|=|y| return x*0*/
|
||||
|
||||
/* determine ix = ilogb(x) */
|
||||
if(hx<0x00800000) { /* subnormal x */
|
||||
for (ix = -126,i=(hx<<8); i>0; i<<=1) ix -=1;
|
||||
} else ix = (hx>>23)-127;
|
||||
|
||||
/* determine iy = ilogb(y) */
|
||||
if(hy<0x00800000) { /* subnormal y */
|
||||
for (iy = -126,i=(hy<<8); i>=0; i<<=1) iy -=1;
|
||||
} else iy = (hy>>23)-127;
|
||||
|
||||
/* set up {hx,lx}, {hy,ly} and align y to x */
|
||||
if(ix >= -126)
|
||||
hx = 0x00800000|(0x007fffff&hx);
|
||||
else { /* subnormal x, shift x to normal */
|
||||
n = -126-ix;
|
||||
hx = hx<<n;
|
||||
}
|
||||
if(iy >= -126)
|
||||
hy = 0x00800000|(0x007fffff&hy);
|
||||
else { /* subnormal y, shift y to normal */
|
||||
n = -126-iy;
|
||||
hy = hy<<n;
|
||||
}
|
||||
|
||||
/* fix point fmod */
|
||||
n = ix - iy;
|
||||
while(n--) {
|
||||
hz=hx-hy;
|
||||
if(hz<0){hx = hx+hx;}
|
||||
else {
|
||||
if(hz==0) /* return sign(x)*0 */
|
||||
return Zero[(ULONG)sx>>31];
|
||||
hx = hz+hz;
|
||||
}
|
||||
}
|
||||
hz=hx-hy;
|
||||
if(hz>=0) {hx=hz;}
|
||||
|
||||
/* convert back to floating value and restore the sign */
|
||||
if(hx==0) /* return sign(x)*0 */
|
||||
return Zero[(ULONG)sx>>31];
|
||||
while(hx<0x00800000) { /* normalize x */
|
||||
hx = hx+hx;
|
||||
iy -= 1;
|
||||
}
|
||||
if(iy>= -126) { /* normalize output */
|
||||
hx = ((hx-0x00800000)|((iy+127)<<23));
|
||||
SET_FLOAT_WORD(x,hx|sx);
|
||||
} else { /* subnormal output */
|
||||
n = -126 - iy;
|
||||
hx >>= n;
|
||||
SET_FLOAT_WORD(x,hx|sx);
|
||||
x *= one; /* create necessary signal */
|
||||
}
|
||||
return x; /* exact output */
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: math_powf.c,v 1.1 2005-05-29 11:19:01 obarthel Exp $
|
||||
* $Id: math_powf.c,v 1.2 2005-05-29 14:45:32 obarthel Exp $
|
||||
*
|
||||
* :ts=4
|
||||
*
|
||||
@@ -29,6 +29,18 @@
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*
|
||||
* PowerPC math library based in part on work by Sun Microsystems
|
||||
* 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.
|
||||
*
|
||||
*
|
||||
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
|
||||
*/
|
||||
|
||||
#ifndef _MATH_HEADERS_H
|
||||
@@ -41,11 +53,229 @@
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
static const float
|
||||
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*/
|
||||
|
||||
float
|
||||
powf(float x,float y)
|
||||
powf(float x, float y)
|
||||
{
|
||||
/* ZZZ unimplemented */
|
||||
return(0);
|
||||
volatile float z; /* prevent optimizing it out of existence */
|
||||
float ax,z_h,z_l,p_h,p_l;
|
||||
float y_1,t1,t2,r,s,t,u,v,w;
|
||||
LONG i,j,k,yisint,n;
|
||||
LONG 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(iy==0) return one;
|
||||
|
||||
/* +-NaN return x+y */
|
||||
if(ix > 0x7f800000 ||
|
||||
iy > 0x7f800000)
|
||||
return x+y;
|
||||
|
||||
/* 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 (iy==0x7f800000) { /* y is +-inf */
|
||||
if (ix==0x3f800000)
|
||||
return y - y; /* inf**+-1 is NaN */
|
||||
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 sqrtf(x);
|
||||
}
|
||||
|
||||
ax = fabsf(x);
|
||||
/* special value of x */
|
||||
if(ix==0x7f800000||ix==0||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(((((ULONG)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 = x-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&0xfffff000U);
|
||||
t2 = v-(t1-u);
|
||||
} else {
|
||||
float s2,s_h,s_l,t_h,t_l;
|
||||
n = 0;
|
||||
/* take care subnormal number */
|
||||
if(ix<0x00800000)
|
||||
{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&0xfffff000U);
|
||||
/* 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&0xfffff000U);
|
||||
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&0xfffff000U);
|
||||
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&0xfffff000U);
|
||||
t2 = z_l-(((t1-t)-dp_h[k])-z_h);
|
||||
}
|
||||
|
||||
s = one; /* s (sign of result -ve**odd) = -1 else = 1 */
|
||||
if(((((ULONG)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(y_1,is&0xfffff000U);
|
||||
p_l = (y-y_1)*t1+y*t2;
|
||||
p_h = y_1*t1;
|
||||
z = p_l+p_h;
|
||||
GET_FLOAT_WORD(j,z);
|
||||
if (j>0x43000000) /* if z > 128 */
|
||||
return s*huge*huge; /* overflow */
|
||||
else if (j==0x43000000) { /* if z == 128 */
|
||||
if(p_l+ovt>z-p_h) return s*huge*huge; /* overflow */
|
||||
}
|
||||
else if ((j&0x7fffffff)>0x43160000) /* z <= -150 */
|
||||
return s*tiny*tiny; /* underflow */
|
||||
else if (j==(LONG)0xc3160000U){ /* z == -150 */
|
||||
if(p_l<=z-p_h) return s*tiny*tiny; /* underflow */
|
||||
}
|
||||
/*
|
||||
* compute 2**(p_h+p_l)
|
||||
*/
|
||||
i = j&0x7fffffff;
|
||||
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&0xfffff000U);
|
||||
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;
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: math_scalbn.c,v 1.1 2005-05-29 11:19:01 obarthel Exp $
|
||||
* $Id: math_scalbn.c,v 1.2 2005-05-29 14:45:32 obarthel Exp $
|
||||
*
|
||||
* :ts=4
|
||||
*
|
||||
@@ -29,6 +29,15 @@
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*
|
||||
* PowerPC math library based in part on work by Sun Microsystems
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef _MATH_HEADERS_H
|
||||
@@ -41,11 +50,38 @@
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
static const double
|
||||
two54 = 1.80143985094819840000e+16, /* 0x43500000, 0x00000000 */
|
||||
twom54 = 5.55111512312578270212e-17, /* 0x3C900000, 0x00000000 */
|
||||
huge = 1.0e+300,
|
||||
tiny = 1.0e-300;
|
||||
|
||||
double
|
||||
scalbn(double x,int n)
|
||||
scalbn (double x, int n)
|
||||
{
|
||||
/* ZZZ unimplemented */
|
||||
return(0);
|
||||
LONG k,hx,lx;
|
||||
EXTRACT_WORDS(hx,lx,x);
|
||||
k = (hx&0x7ff00000)>>20; /* extract exponent */
|
||||
if (k==0) { /* 0 or subnormal x */
|
||||
if ((lx|(hx&0x7fffffff))==0) return x; /* +-0 */
|
||||
x *= two54;
|
||||
GET_HIGH_WORD(hx,x);
|
||||
k = ((hx&0x7ff00000)>>20) - 54;
|
||||
if (n< -50000) return tiny*x; /*underflow*/
|
||||
}
|
||||
if (k==0x7ff) return x+x; /* NaN or Inf */
|
||||
k = k+n;
|
||||
if (k > 0x7fe) return copysign(HUGE_VAL,x); /* overflow */
|
||||
if (k > 0) /* normal result */
|
||||
{SET_HIGH_WORD(x,(hx&0x800fffffU)|(k<<20)); return x;}
|
||||
if (k <= -54) {
|
||||
if (n > 50000) /* in case integer overflow in n+k */
|
||||
return copysign(HUGE_VAL,x); /*overflow*/
|
||||
else return tiny*copysign(tiny,x); /*underflow*/
|
||||
}
|
||||
k += 54; /* subnormal result */
|
||||
SET_HIGH_WORD(x,(hx&0x800fffffU)|(k<<20));
|
||||
return x*twom54;
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: math_scalbnf.c,v 1.1 2005-05-29 11:19:01 obarthel Exp $
|
||||
* $Id: math_scalbnf.c,v 1.2 2005-05-29 14:45:32 obarthel Exp $
|
||||
*
|
||||
* :ts=4
|
||||
*
|
||||
@@ -29,6 +29,18 @@
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*
|
||||
* PowerPC math library based in part on work by Sun Microsystems
|
||||
* 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.
|
||||
*
|
||||
*
|
||||
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
|
||||
*/
|
||||
|
||||
#ifndef _MATH_HEADERS_H
|
||||
@@ -41,11 +53,44 @@
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
#if INT_MAX > 50000
|
||||
#define OVERFLOW_INT 50000
|
||||
#else
|
||||
#define OVERFLOW_INT 30000
|
||||
#endif
|
||||
|
||||
static const float
|
||||
two25 = 3.355443200e+07, /* 0x4c000000 */
|
||||
twom25 = 2.9802322388e-08, /* 0x33000000 */
|
||||
huge = 1.0e+30,
|
||||
tiny = 1.0e-30;
|
||||
|
||||
float
|
||||
scalbnf(float x,int n)
|
||||
scalbnf (float x, int n)
|
||||
{
|
||||
/* ZZZ unimplemented */
|
||||
return(0);
|
||||
LONG k,ix;
|
||||
GET_FLOAT_WORD(ix,x);
|
||||
k = (ix&0x7f800000)>>23; /* extract exponent */
|
||||
if (k==0) { /* 0 or subnormal x */
|
||||
if ((ix&0x7fffffff)==0) return x; /* +-0 */
|
||||
x *= two25;
|
||||
GET_FLOAT_WORD(ix,x);
|
||||
k = ((ix&0x7f800000)>>23) - 25;
|
||||
if (n< -50000) return tiny*x; /*underflow*/
|
||||
}
|
||||
if (k==0xff) return x+x; /* NaN or Inf */
|
||||
k = k+n;
|
||||
if (k > 0xfe) return copysignf(__inff(),x); /* overflow */
|
||||
if (k > 0) /* normal result */
|
||||
{SET_FLOAT_WORD(x,(ix&0x807fffffU)|(k<<23)); return x;}
|
||||
if (k <= -25) {
|
||||
if (n > OVERFLOW_INT) /* in case integer overflow in n+k */
|
||||
return copysignf(__inff(),x);/*overflow*/
|
||||
else return tiny*copysignf(tiny,x); /*underflow*/
|
||||
}
|
||||
k += 25; /* subnormal result */
|
||||
SET_FLOAT_WORD(x,(ix&0x807fffffU)|(k<<23));
|
||||
return x*twom25;
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: math_sqrtf.c,v 1.1 2005-05-29 11:19:01 obarthel Exp $
|
||||
* $Id: math_sqrtf.c,v 1.2 2005-05-29 14:45:32 obarthel Exp $
|
||||
*
|
||||
* :ts=4
|
||||
*
|
||||
@@ -29,6 +29,18 @@
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*
|
||||
* PowerPC math library based in part on work by Sun Microsystems
|
||||
* 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.
|
||||
*
|
||||
*
|
||||
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
|
||||
*/
|
||||
|
||||
#ifndef _MATH_HEADERS_H
|
||||
@@ -41,11 +53,72 @@
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
static const float one = 1.0, tiny=1.0e-30;
|
||||
|
||||
float
|
||||
sqrtf(float x)
|
||||
{
|
||||
/* ZZZ unimplemented */
|
||||
return(0);
|
||||
volatile float z; /* to prevent GCC from optimizing it away */
|
||||
LONG sign = (LONG)0x80000000U;
|
||||
ULONG r;
|
||||
LONG ix,s,q,m,t,i;
|
||||
|
||||
GET_FLOAT_WORD(ix,x);
|
||||
|
||||
/* take care of Inf and NaN */
|
||||
if((ix&0x7f800000)==0x7f800000) {
|
||||
return x*x+x; /* sqrt(NaN)=NaN, sqrt(+inf)=+inf
|
||||
sqrt(-inf)=sNaN */
|
||||
}
|
||||
/* take care of zero */
|
||||
if(ix<=0) {
|
||||
if((ix&(~sign))==0) return x;/* sqrt(+-0) = +-0 */
|
||||
else if(ix<0)
|
||||
return (x-x)/(x-x); /* sqrt(-ve) = sNaN */
|
||||
}
|
||||
/* normalize x */
|
||||
m = (ix>>23);
|
||||
if(m==0) { /* subnormal x */
|
||||
for(i=0;(ix&0x00800000)==0;i++) ix<<=1;
|
||||
m -= i-1;
|
||||
}
|
||||
m -= 127; /* unbias exponent */
|
||||
ix = (ix&0x007fffff)|0x00800000;
|
||||
if(m&1) /* odd m, double x to make it even */
|
||||
ix += ix;
|
||||
m >>= 1; /* m = [m/2] */
|
||||
|
||||
/* generate sqrt(x) bit by bit */
|
||||
ix += ix;
|
||||
q = s = 0; /* q = sqrt(x) */
|
||||
r = 0x01000000; /* r = moving bit from right to left */
|
||||
|
||||
while(r!=0) {
|
||||
t = s+r;
|
||||
if(t<=ix) {
|
||||
s = t+r;
|
||||
ix -= t;
|
||||
q += r;
|
||||
}
|
||||
ix += ix;
|
||||
r>>=1;
|
||||
}
|
||||
|
||||
/* use floating add to find out rounding direction */
|
||||
if(ix!=0) {
|
||||
z = one-tiny; /* trigger inexact flag */
|
||||
if (z>=one) {
|
||||
z = one+tiny;
|
||||
if (z>one)
|
||||
q += 2;
|
||||
else
|
||||
q += (q&1);
|
||||
}
|
||||
}
|
||||
ix = (q>>1)+0x3f000000;
|
||||
ix += (m <<23);
|
||||
SET_FLOAT_WORD(z,ix);
|
||||
return z;
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#
|
||||
# $Id: smakefile,v 1.43 2005-05-14 10:52:31 obarthel Exp $
|
||||
# $Id: smakefile,v 1.44 2005-05-29 14:45:32 obarthel Exp $
|
||||
#
|
||||
# :ts=8
|
||||
#
|
||||
@@ -180,45 +180,62 @@ LOCALE_OBJ = \
|
||||
|
||||
MATH_OBJ = \
|
||||
math_acos.o \
|
||||
math_acosf.o \
|
||||
math_asin.o \
|
||||
math_asinf.o \
|
||||
math_atan.o \
|
||||
math_atan2.o \
|
||||
math_atan2f.o \
|
||||
math_atanf.o \
|
||||
math_ceil.o \
|
||||
math_cos.o \
|
||||
math_cosh.o \
|
||||
math_ceilf.o \
|
||||
math_copysign.o \
|
||||
math_copysignf.o \
|
||||
math_cos.o \
|
||||
math_cosh.o \
|
||||
math_exp.o \
|
||||
math_expf.o \
|
||||
math_fabs.o \
|
||||
math_fabsf.o \
|
||||
math_floor.o \
|
||||
math_floorf.o \
|
||||
math_fmod.o \
|
||||
math_fmodf.o \
|
||||
math_fpclassify.o \
|
||||
math_inf.o \
|
||||
math_inff.o \
|
||||
math_isfinite.o \
|
||||
math_isunordered.o \
|
||||
math_signbit.o \
|
||||
math_frexp.o \
|
||||
math_frexpf.o \
|
||||
math_huge_val.o \
|
||||
math_huge_valf.o \
|
||||
math_hypot.o \
|
||||
math_inf.o \
|
||||
math_inff.o \
|
||||
math_init_exit.o \
|
||||
math_isfinite.o \
|
||||
math_isunordered.o \
|
||||
math_ldexp.o \
|
||||
math_log.o \
|
||||
math_log10.o \
|
||||
math_log10f.o \
|
||||
math_logb.o \
|
||||
math_logbf.o \
|
||||
math_logf.o \
|
||||
math_modf.o \
|
||||
math_modff.o \
|
||||
math_nan.o \
|
||||
math_nanf.o \
|
||||
math_nextafter.o \
|
||||
math_nextafterf.o \
|
||||
math_pow.o \
|
||||
math_powf.o \
|
||||
math_rint.o \
|
||||
math_rintf.o \
|
||||
math_scalbn.o \
|
||||
math_scalbnf.o \
|
||||
math_signbit.o \
|
||||
math_sin.o \
|
||||
math_sinh.o \
|
||||
math_sqrt.o \
|
||||
math_sqrtf.o \
|
||||
math_tan.o \
|
||||
math_tanh.o
|
||||
|
||||
|
||||
Reference in New Issue
Block a user