Subversion Repositories Kolibri OS

Compare Revisions

Regard whitespace Rev 3361 → Rev 3362

/programs/develop/libraries/newlib/Makefile
9,7 → 9,7
 
NAME:= libc
 
DEFINES:=
DEFINES:= -D_IEEE_LIBM
 
INCLUDES:= -I $(LIBC_INCLUDES)
 
253,26 → 253,39
sscanf.c
 
 
MATH_SRCS = acosf.c acosh.c acoshf.c acoshl.c acosl.c asinf.c asinh.c asinhf.c asinhl.c \
asinl.c atan2f.c atan2l.c atanf.c atanh.c atanhf.c atanhl.c atanl.c cbrt.c \
cbrtf.c cbrtl.c coshf.c coshl.c erfl.c expf.c expl.c expm1.c expm1f.c expm1l.c\
fabs.c fabsf.c fabsl.c fdim.c fdimf.c fdiml.c fmal.c fmax.c fmaxf.c fmaxl.c\
fmin.c fminf.c fminl.c fmodf.c fmodl.c fp_consts.c fp_constsf.c fp_constsl.c\
fpclassify.c fpclassifyf.c fpclassifyl.c frexpf.c fucom.c hypotf.c isnan.c \
isnanf.c isnanl.c ldexp.c ldexpf.c ldexpl.c lgamma.c lgammaf.c lgammal.c \
llrint.c llrintf.c llrintl.c logb.c logbf.c logbl.c lrint.c lrintf.c lrintl.c\
lround_generic.c modff.c modfl.c nextafterf.c nextafterl.c nexttoward.c \
nexttowardf.c pow.c powf.c powi.c powif.c powil.c powl.c rint.c rintf.c \
rintl.c round_generic.c s_erf.c sf_erf.c signbit.c signbitf.c signbitl.c \
sinhf.c sinhl.c sqrtf.c sqrtl.c tanhf.c tanhl.c tgamma.c tgammaf.c tgammal.c \
trunc.c truncf.c truncl.c e_sqrt.c e_sinh.c e_cosh.c e_hypot.c s_tanh.c \
s_roundf.c s_fpclassify.c s_isnand.c w_hypot.c s_modf.c e_atan2.c w_atan2.c\
ceil.S ceilf.S ceill.S copysign.S copysignf.S copysignl.S cos.S cosf.S cosl.S exp.S exp2.S \
exp2f.S exp2l.S floor.S floorf.S floorl.S fma.S fmaf.S frexp.S frexpl.S ilogb.S ilogbf.S \
ilogbl.S log10.S log10f.S log10l.S log1p.S log1pf.S log1pl.S log2.S log2f.S log2l.S \
log.S logf.S logl.S nearbyint.S nearbyintf.S nearbyintl.S remainder.S remainderf.S \
remainderl.S remquo.S remquof.S remquol.S scalbn.S scalbnf.S scalbnl.S sin.S \
sinf.S sinl.S tan.S tanf.S tanl.S s_expm1.S
MATH_SRCS = e_acos.c e_acosh.c e_asin.c e_atan2.c e_atanh.c e_cosh.c e_exp.c e_fmod.c \
e_hypot.c e_j0.c e_j1.c e_jn.c e_log.c e_log10.c e_pow.c e_rem_pio2.c \
e_remainder.c e_scalb.c e_sinh.c e_sqrt.c ef_acos.c ef_acosh.c ef_asin.c \
ef_atan2.c ef_atanh.c ef_cosh.c ef_exp.c ef_fmod.c ef_hypot.c ef_j0.c ef_j1.c \
ef_jn.c ef_log.c ef_log10.c ef_pow.c ef_rem_pio2.c ef_remainder.c ef_scalb.c \
ef_sinh.c ef_sqrt.c er_gamma.c er_lgamma.c erf_gamma.c erf_lgamma.c f_exp.c \
f_expf.c f_llrint.c f_llrintf.c f_llrintl.c f_lrint.c f_lrintf.c f_lrintl.c \
f_pow.c f_powf.c f_rint.c f_rintf.c f_rintl.c k_cos.c k_rem_pio2.c k_sin.c \
k_standard.c k_tan.c kf_cos.c kf_rem_pio2.c kf_sin.c kf_tan.c s_asinh.c \
s_atan.c s_cbrt.c s_ceil.c s_copysign.c s_cos.c s_erf.c s_exp10.c s_expm1.c \
s_fabs.c s_fdim.c s_finite.c s_floor.c s_fma.c s_fmax.c s_fmin.c s_fpclassify.c \
s_frexp.c s_ilogb.c s_infconst.c s_infinity.c s_isinf.c s_isinfd.c s_isnan.c \
s_isnand.c s_ldexp.c s_lib_ver.c s_llrint.c s_llround.c s_log1p.c s_log2.c \
s_logb.c s_lrint.c s_lround.c s_matherr.c s_modf.c s_nan.c s_nearbyint.c \
s_nextafter.c s_pow10.c s_remquo.c s_rint.c s_round.c s_scalbln.c s_scalbn.c \
s_signbit.c s_signif.c s_sin.c s_tan.c s_tanh.c s_trunc.c scalblnl.c scalbnl.c \
sf_asinh.c sf_atan.c sf_cbrt.c sf_ceil.c sf_copysign.c sf_cos.c sf_erf.c \
sf_exp10.c sf_expm1.c sf_fabs.c sf_fdim.c sf_finite.c sf_floor.c sf_fma.c \
sf_fmax.c sf_fmin.c sf_fpclassify.c sf_frexp.c sf_ilogb.c sf_infinity.c \
sf_isinf.c sf_isinff.c sf_isnan.c sf_isnanf.c sf_ldexp.c sf_llrint.c \
sf_llround.c sf_log1p.c sf_log2.c sf_logb.c sf_lrint.c sf_lround.c sf_modf.c \
sf_nan.c sf_nearbyint.c sf_nextafter.c sf_pow10.c sf_remquo.c sf_rint.c \
sf_round.c sf_scalbln.c sf_scalbn.c sf_signif.c sf_sin.c sf_tan.c sf_tanh.c \
sf_trunc.c w_acos.c w_acosh.c w_asin.c w_atan2.c w_atanh.c w_cosh.c w_drem.c \
w_exp.c w_exp2.c w_fmod.c w_gamma.c w_hypot.c w_j0.c w_j1.c w_jn.c w_lgamma.c \
w_log.c w_log10.c w_pow.c w_remainder.c w_scalb.c w_sincos.c w_sinh.c w_sqrt.c \
w_tgamma.c wf_acos.c wf_acosh.c wf_asin.c wf_atan2.c wf_atanh.c wf_cosh.c \
wf_drem.c wf_exp.c wf_exp2.c wf_fmod.c wf_gamma.c wf_hypot.c wf_j0.c wf_j1.c \
wf_jn.c wf_lgamma.c wf_log.c wf_log10.c wf_pow.c wf_remainder.c wf_scalb.c \
wf_sincos.c wf_sinh.c wf_sqrt.c wf_tgamma.c wr_gamma.c wr_lgamma.c wrf_gamma.c \
wrf_lgamma.c \
f_atan2.S f_atan2f.S f_frexp.S f_frexpf.S f_ldexp.S f_ldexpf.S f_log.S \
f_log10.S f_log10f.S f_logf.S f_tan.S f_tanf.S
 
 
AMZ_OBJS = $(patsubst %.S, %.o, $(patsubst %.c, %.o, $(AMZ_SRCS)))
385,7 → 398,7
 
 
%.obj : %.asm Makefile
fasm $< $@
fasm $< $
 
%.o : %.c Makefile
$(CC) $(CFLAGS) $(DEFINES) $(INCLUDES) -o $@ $<
395,3 → 408,5
-rm -f */*.o
 
 
 
 
/programs/develop/libraries/newlib/math/lgammal.c
File deleted
/programs/develop/libraries/newlib/math/tanhf.c
File deleted
/programs/develop/libraries/newlib/math/powil.c
File deleted
/programs/develop/libraries/newlib/math/tgammal.c
File deleted
/programs/develop/libraries/newlib/math/scalbnf.S
File deleted
/programs/develop/libraries/newlib/math/fmaxf.c
File deleted
/programs/develop/libraries/newlib/math/atanhf.c
File deleted
/programs/develop/libraries/newlib/math/atanhl.c
File deleted
/programs/develop/libraries/newlib/math/fdimf.c
File deleted
/programs/develop/libraries/newlib/math/signbitf.c
File deleted
/programs/develop/libraries/newlib/math/signbitl.c
File deleted
/programs/develop/libraries/newlib/math/asinhf.c
File deleted
/programs/develop/libraries/newlib/math/asinhl.c
File deleted
/programs/develop/libraries/newlib/math/fminl.c
File deleted
/programs/develop/libraries/newlib/math/acoshf.c
File deleted
/programs/develop/libraries/newlib/math/acoshl.c
File deleted
/programs/develop/libraries/newlib/math/ilogbl.S
File deleted
/programs/develop/libraries/newlib/math/ilogbf.S
File deleted
/programs/develop/libraries/newlib/math/op-2.h
File deleted
/programs/develop/libraries/newlib/math/op-4.h
File deleted
/programs/develop/libraries/newlib/math/op-8.h
File deleted
/programs/develop/libraries/newlib/math/scalbn.S
File deleted
/programs/develop/libraries/newlib/math/exp2.S
File deleted
/programs/develop/libraries/newlib/math/lgamma.c
File deleted
/programs/develop/libraries/newlib/math/nexttowardf.c
File deleted
/programs/develop/libraries/newlib/math/double.h
File deleted
/programs/develop/libraries/newlib/math/remquof.S
File deleted
/programs/develop/libraries/newlib/math/isnanl.c
File deleted
/programs/develop/libraries/newlib/math/isnanf.c
File deleted
/programs/develop/libraries/newlib/math/sinhl.c
File deleted
/programs/develop/libraries/newlib/math/atanf.c
File deleted
/programs/develop/libraries/newlib/math/fabs.c
File deleted
/programs/develop/libraries/newlib/math/tgamma.c
File deleted
/programs/develop/libraries/newlib/math/exp2l.S
File deleted
/programs/develop/libraries/newlib/math/hypotl.c
File deleted
/programs/develop/libraries/newlib/math/hypotf.c
File deleted
/programs/develop/libraries/newlib/math/asinh.c
File deleted
/programs/develop/libraries/newlib/math/expf.c
File deleted
/programs/develop/libraries/newlib/math/expl.c
File deleted
/programs/develop/libraries/newlib/math/log10.S
File deleted
/programs/develop/libraries/newlib/math/floor.S
File deleted
/programs/develop/libraries/newlib/math/asinl.c
File deleted
/programs/develop/libraries/newlib/math/remquo.S
File deleted
/programs/develop/libraries/newlib/math/quad.h
File deleted
/programs/develop/libraries/newlib/math/fmodl.c
File deleted
/programs/develop/libraries/newlib/math/rint.c
File deleted
/programs/develop/libraries/newlib/math/powi.c
File deleted
/programs/develop/libraries/newlib/math/sin.S
File deleted
/programs/develop/libraries/newlib/math/nearbyintl.S
File deleted
/programs/develop/libraries/newlib/math/nearbyintf.S
File deleted
/programs/develop/libraries/newlib/math/rintf.c
File deleted
/programs/develop/libraries/newlib/math/ilogb.S
File deleted
/programs/develop/libraries/newlib/math/frexp.S
File deleted
/programs/develop/libraries/newlib/math/nextafterl.c
File deleted
/programs/develop/libraries/newlib/math/nextafterf.c
File deleted
/programs/develop/libraries/newlib/math/copysignl.S
File deleted
/programs/develop/libraries/newlib/math/acosf.c
File deleted
/programs/develop/libraries/newlib/math/fpclassifyl.c
File deleted
/programs/develop/libraries/newlib/math/coshf.c
File deleted
/programs/develop/libraries/newlib/math/cbrtf.c
File deleted
/programs/develop/libraries/newlib/math/fmaf.S
File deleted
/programs/develop/libraries/newlib/math/ceilf.S
File deleted
/programs/develop/libraries/newlib/math/tan.S
File deleted
/programs/develop/libraries/newlib/math/isnan.c
File deleted
/programs/develop/libraries/newlib/math/nexttoward.c
File deleted
/programs/develop/libraries/newlib/math/trunc.c
File deleted
/programs/develop/libraries/newlib/math/sqrtf.c
File deleted
/programs/develop/libraries/newlib/math/lrint.c
File deleted
/programs/develop/libraries/newlib/math/expm1f.c
File deleted
/programs/develop/libraries/newlib/math/expm1l.c
File deleted
/programs/develop/libraries/newlib/math/log2f.S
File deleted
/programs/develop/libraries/newlib/math/log10l.S
File deleted
/programs/develop/libraries/newlib/math/log10f.S
File deleted
/programs/develop/libraries/newlib/math/fmal.c
File deleted
/programs/develop/libraries/newlib/math/fmax.c
File deleted
/programs/develop/libraries/newlib/math/nearbyint.S
File deleted
/programs/develop/libraries/newlib/math/llrintf.c
File deleted
/programs/develop/libraries/newlib/math/fmin.c
File deleted
/programs/develop/libraries/newlib/math/sinf.S
File deleted
/programs/develop/libraries/newlib/math/sinl.S
File deleted
/programs/develop/libraries/newlib/math/pow.c
File deleted
/programs/develop/libraries/newlib/math/scalbnl.S
File deleted
/programs/develop/libraries/newlib/math/cos.S
File deleted
/programs/develop/libraries/newlib/math/log1p.S
File deleted
/programs/develop/libraries/newlib/math/fabsl.c
File deleted
/programs/develop/libraries/newlib/math/modff.c
File deleted
/programs/develop/libraries/newlib/math/logbf.c
File deleted
/programs/develop/libraries/newlib/math/powif.c
File deleted
/programs/develop/libraries/newlib/math/remquol.S
File deleted
/programs/develop/libraries/newlib/math/tanhl.c
File deleted
/programs/develop/libraries/newlib/math/exp.S
File deleted
/programs/develop/libraries/newlib/math/fminf.c
File deleted
/programs/develop/libraries/newlib/math/fmaxl.c
File deleted
/programs/develop/libraries/newlib/math/remainder.S
File deleted
/programs/develop/libraries/newlib/math/fdiml.c
File deleted
/programs/develop/libraries/newlib/math/ceil.S
File deleted
/programs/develop/libraries/newlib/math/op-1.h
File deleted
/programs/develop/libraries/newlib/math/fastmath.h
File deleted
/programs/develop/libraries/newlib/math/round_generic.c
File deleted
/programs/develop/libraries/newlib/math/lgammaf.c
File deleted
/programs/develop/libraries/newlib/math/ldexp.c
File deleted
/programs/develop/libraries/newlib/math/frexpl.S
File deleted
/programs/develop/libraries/newlib/math/frexpf.c
File deleted
/programs/develop/libraries/newlib/math/logl.S
File deleted
/programs/develop/libraries/newlib/math/logf.S
File deleted
/programs/develop/libraries/newlib/math/log2.S
File deleted
/programs/develop/libraries/newlib/math/s_expm1.S
File deleted
/programs/develop/libraries/newlib/math/fp_consts.c
File deleted
/programs/develop/libraries/newlib/math/sinhf.c
File deleted
/programs/develop/libraries/newlib/math/exp2f.S
File deleted
/programs/develop/libraries/newlib/math/ldexpl.c
File deleted
/programs/develop/libraries/newlib/math/ldexpf.c
File deleted
/programs/develop/libraries/newlib/math/log1pl.S
File deleted
/programs/develop/libraries/newlib/math/log1pf.S
File deleted
/programs/develop/libraries/newlib/math/fp_consts.h
File deleted
/programs/develop/libraries/newlib/math/floorf.S
File deleted
/programs/develop/libraries/newlib/math/floorl.S
File deleted
/programs/develop/libraries/newlib/math/tgammaf.c
File deleted
/programs/develop/libraries/newlib/math/truncf.c
File deleted
/programs/develop/libraries/newlib/math/truncl.c
File deleted
/programs/develop/libraries/newlib/math/fma.S
File deleted
/programs/develop/libraries/newlib/math/llrint.c
File deleted
/programs/develop/libraries/newlib/math/atanh.c
File deleted
/programs/develop/libraries/newlib/math/lrintl.c
File deleted
/programs/develop/libraries/newlib/math/lrintf.c
File deleted
/programs/develop/libraries/newlib/math/asinf.c
File deleted
/programs/develop/libraries/newlib/math/tanf.S
File deleted
/programs/develop/libraries/newlib/math/tanl.S
File deleted
/programs/develop/libraries/newlib/math/single.h
File deleted
/programs/develop/libraries/newlib/math/fpclassify.c
File deleted
/programs/develop/libraries/newlib/math/atanl.c
File deleted
/programs/develop/libraries/newlib/math/op-common.h
File deleted
/programs/develop/libraries/newlib/math/logb.c
File deleted
/programs/develop/libraries/newlib/math/fmodf.c
File deleted
/programs/develop/libraries/newlib/math/fucom.c
File deleted
/programs/develop/libraries/newlib/math/powf.c
File deleted
/programs/develop/libraries/newlib/math/powl.c
File deleted
/programs/develop/libraries/newlib/math/expm1.c
File deleted
/programs/develop/libraries/newlib/math/copysign.S
File deleted
/programs/develop/libraries/newlib/math/rintl.c
File deleted
/programs/develop/libraries/newlib/math/fp_constsl.c
File deleted
/programs/develop/libraries/newlib/math/fp_constsf.c
File deleted
/programs/develop/libraries/newlib/math/copysignf.S
File deleted
/programs/develop/libraries/newlib/math/llrintl.c
File deleted
/programs/develop/libraries/newlib/math/remainderf.S
File deleted
/programs/develop/libraries/newlib/math/remainderl.S
File deleted
/programs/develop/libraries/newlib/math/acosh.c
File deleted
/programs/develop/libraries/newlib/math/log.S
File deleted
/programs/develop/libraries/newlib/math/soft-fp.h
File deleted
/programs/develop/libraries/newlib/math/acosl.c
File deleted
/programs/develop/libraries/newlib/math/lround_generic.c
File deleted
/programs/develop/libraries/newlib/math/coshl.c
File deleted
/programs/develop/libraries/newlib/math/cbrtl.c
File deleted
/programs/develop/libraries/newlib/math/atan2f.c
File deleted
/programs/develop/libraries/newlib/math/atan2l.c
File deleted
/programs/develop/libraries/newlib/math/cosl.S
File deleted
/programs/develop/libraries/newlib/math/cosf.S
File deleted
/programs/develop/libraries/newlib/math/cephes_mconf.h
File deleted
/programs/develop/libraries/newlib/math/ceill.S
File deleted
/programs/develop/libraries/newlib/math/s_roundf.c
File deleted
/programs/develop/libraries/newlib/math/signbit.c
File deleted
/programs/develop/libraries/newlib/math/erfl.c
File deleted
/programs/develop/libraries/newlib/math/round_internal.h
File deleted
/programs/develop/libraries/newlib/math/sqrtl.c
File deleted
/programs/develop/libraries/newlib/math/fdim.c
File deleted
/programs/develop/libraries/newlib/math/log2l.S
File deleted
/programs/develop/libraries/newlib/math/fpclassifyf.c
File deleted
/programs/develop/libraries/newlib/math/cbrt.c
File deleted
/programs/develop/libraries/newlib/math/fabsf.c
File deleted
/programs/develop/libraries/newlib/math/modfl.c
File deleted
/programs/develop/libraries/newlib/math/logbl.c
File deleted
/programs/develop/libraries/newlib/math/e_acos.c
0,0 → 1,111
 
/* @(#)e_acos.c 5.1 93/09/24 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
/* __ieee754_acos(x)
* Method :
* acos(x) = pi/2 - asin(x)
* acos(-x) = pi/2 + asin(x)
* For |x|<=0.5
* acos(x) = pi/2 - (x + x*x^2*R(x^2)) (see asin.c)
* For x>0.5
* acos(x) = pi/2 - (pi/2 - 2asin(sqrt((1-x)/2)))
* = 2asin(sqrt((1-x)/2))
* = 2s + 2s*z*R(z) ...z=(1-x)/2, s=sqrt(z)
* = 2f + (2c + 2s*z*R(z))
* where f=hi part of s, and c = (z-f*f)/(s+f) is the correction term
* for f so that f+c ~ sqrt(z).
* For x<-0.5
* acos(x) = pi - 2asin(sqrt((1-|x|)/2))
* = pi - 0.5*(s+s*z*R(z)), where z=(1-|x|)/2,s=sqrt(z)
*
* Special cases:
* if x is NaN, return x itself;
* if |x|>1, return NaN with invalid signal.
*
* Function needed: sqrt
*/
 
#include "fdlibm.h"
 
#ifndef _DOUBLE_IS_32BITS
 
#ifdef __STDC__
static const double
#else
static double
#endif
one= 1.00000000000000000000e+00, /* 0x3FF00000, 0x00000000 */
pi = 3.14159265358979311600e+00, /* 0x400921FB, 0x54442D18 */
pio2_hi = 1.57079632679489655800e+00, /* 0x3FF921FB, 0x54442D18 */
pio2_lo = 6.12323399573676603587e-17, /* 0x3C91A626, 0x33145C07 */
pS0 = 1.66666666666666657415e-01, /* 0x3FC55555, 0x55555555 */
pS1 = -3.25565818622400915405e-01, /* 0xBFD4D612, 0x03EB6F7D */
pS2 = 2.01212532134862925881e-01, /* 0x3FC9C155, 0x0E884455 */
pS3 = -4.00555345006794114027e-02, /* 0xBFA48228, 0xB5688F3B */
pS4 = 7.91534994289814532176e-04, /* 0x3F49EFE0, 0x7501B288 */
pS5 = 3.47933107596021167570e-05, /* 0x3F023DE1, 0x0DFDF709 */
qS1 = -2.40339491173441421878e+00, /* 0xC0033A27, 0x1C8A2D4B */
qS2 = 2.02094576023350569471e+00, /* 0x40002AE5, 0x9C598AC8 */
qS3 = -6.88283971605453293030e-01, /* 0xBFE6066C, 0x1B8D0159 */
qS4 = 7.70381505559019352791e-02; /* 0x3FB3B8C5, 0xB12E9282 */
 
#ifdef __STDC__
double __ieee754_acos(double x)
#else
double __ieee754_acos(x)
double x;
#endif
{
double z,p,q,r,w,s,c,df;
__int32_t hx,ix;
GET_HIGH_WORD(hx,x);
ix = hx&0x7fffffff;
if(ix>=0x3ff00000) { /* |x| >= 1 */
__uint32_t lx;
GET_LOW_WORD(lx,x);
if(((ix-0x3ff00000)|lx)==0) { /* |x|==1 */
if(hx>0) return 0.0; /* acos(1) = 0 */
else return pi+2.0*pio2_lo; /* acos(-1)= pi */
}
return (x-x)/(x-x); /* acos(|x|>1) is NaN */
}
if(ix<0x3fe00000) { /* |x| < 0.5 */
if(ix<=0x3c600000) 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)*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 = __ieee754_sqrt(z);
r = p/q;
w = r*s-pio2_lo;
return pi - 2.0*(s+w);
} else { /* x > 0.5 */
z = (one-x)*0.5;
s = __ieee754_sqrt(z);
df = s;
SET_LOW_WORD(df,0);
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 2.0*(df+w);
}
}
 
#endif /* defined(_DOUBLE_IS_32BITS) */
/programs/develop/libraries/newlib/math/e_acosh.c
0,0 → 1,70
 
/* @(#)e_acosh.c 5.1 93/09/24 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*
*/
 
/* __ieee754_acosh(x)
* Method :
* Based on
* acosh(x) = log [ x + sqrt(x*x-1) ]
* we have
* acosh(x) := log(x)+ln2, if x is large; else
* acosh(x) := log(2x-1/(sqrt(x*x-1)+x)) if x>2; else
* acosh(x) := log1p(t+sqrt(2.0*t+t*t)); where t=x-1.
*
* Special cases:
* acosh(x) is NaN with signal if x<1.
* acosh(NaN) is NaN without signal.
*/
 
#include "fdlibm.h"
 
#ifndef _DOUBLE_IS_32BITS
 
#ifdef __STDC__
static const double
#else
static double
#endif
one = 1.0,
ln2 = 6.93147180559945286227e-01; /* 0x3FE62E42, 0xFEFA39EF */
 
#ifdef __STDC__
double __ieee754_acosh(double x)
#else
double __ieee754_acosh(x)
double x;
#endif
{
double t;
__int32_t hx;
__uint32_t lx;
EXTRACT_WORDS(hx,lx,x);
if(hx<0x3ff00000) { /* x < 1 */
return (x-x)/(x-x);
} else if(hx >=0x41b00000) { /* x > 2**28 */
if(hx >=0x7ff00000) { /* x is inf of NaN */
return x+x;
} else
return __ieee754_log(x)+ln2; /* acosh(huge)=log(2x) */
} else if(((hx-0x3ff00000)|lx)==0) {
return 0.0; /* acosh(1) = 0 */
} else if (hx > 0x40000000) { /* 2**28 > x > 2 */
t=x*x;
return __ieee754_log(2.0*x-one/(x+__ieee754_sqrt(t-one)));
} else { /* 1<x<2 */
t = x-one;
return log1p(t+__ieee754_sqrt(2.0*t+t*t));
}
}
 
#endif /* defined(_DOUBLE_IS_32BITS) */
/programs/develop/libraries/newlib/math/e_asin.c
0,0 → 1,121
 
/* @(#)e_asin.c 5.1 93/09/24 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
/* __ieee754_asin(x)
* Method :
* Since asin(x) = x + x^3/6 + x^5*3/40 + x^7*15/336 + ...
* we approximate asin(x) on [0,0.5] by
* asin(x) = x + x*x^2*R(x^2)
* where
* R(x^2) is a rational approximation of (asin(x)-x)/x^3
* and its remez error is bounded by
* |(asin(x)-x)/x^3 - R(x^2)| < 2^(-58.75)
*
* For x in [0.5,1]
* asin(x) = pi/2-2*asin(sqrt((1-x)/2))
* Let y = (1-x), z = y/2, s := sqrt(z), and pio2_hi+pio2_lo=pi/2;
* then for x>0.98
* asin(x) = pi/2 - 2*(s+s*z*R(z))
* = pio2_hi - (2*(s+s*z*R(z)) - pio2_lo)
* For x<=0.98, let pio4_hi = pio2_hi/2, then
* f = hi part of s;
* c = sqrt(z) - f = (z-f*f)/(s+f) ...f+c=sqrt(z)
* and
* asin(x) = pi/2 - 2*(s+s*z*R(z))
* = pio4_hi+(pio4-2s)-(2s*z*R(z)-pio2_lo)
* = pio4_hi+(pio4-2f)-(2s*z*R(z)-(pio2_lo+2c))
*
* Special cases:
* if x is NaN, return x itself;
* if |x|>1, return NaN with invalid signal.
*
*/
 
 
#include "fdlibm.h"
 
#ifndef _DOUBLE_IS_32BITS
 
#ifdef __STDC__
static const double
#else
static double
#endif
one = 1.00000000000000000000e+00, /* 0x3FF00000, 0x00000000 */
huge = 1.000e+300,
pio2_hi = 1.57079632679489655800e+00, /* 0x3FF921FB, 0x54442D18 */
pio2_lo = 6.12323399573676603587e-17, /* 0x3C91A626, 0x33145C07 */
pio4_hi = 7.85398163397448278999e-01, /* 0x3FE921FB, 0x54442D18 */
/* coefficient for R(x^2) */
pS0 = 1.66666666666666657415e-01, /* 0x3FC55555, 0x55555555 */
pS1 = -3.25565818622400915405e-01, /* 0xBFD4D612, 0x03EB6F7D */
pS2 = 2.01212532134862925881e-01, /* 0x3FC9C155, 0x0E884455 */
pS3 = -4.00555345006794114027e-02, /* 0xBFA48228, 0xB5688F3B */
pS4 = 7.91534994289814532176e-04, /* 0x3F49EFE0, 0x7501B288 */
pS5 = 3.47933107596021167570e-05, /* 0x3F023DE1, 0x0DFDF709 */
qS1 = -2.40339491173441421878e+00, /* 0xC0033A27, 0x1C8A2D4B */
qS2 = 2.02094576023350569471e+00, /* 0x40002AE5, 0x9C598AC8 */
qS3 = -6.88283971605453293030e-01, /* 0xBFE6066C, 0x1B8D0159 */
qS4 = 7.70381505559019352791e-02; /* 0x3FB3B8C5, 0xB12E9282 */
 
#ifdef __STDC__
double __ieee754_asin(double x)
#else
double __ieee754_asin(x)
double x;
#endif
{
double t,w,p,q,c,r,s;
__int32_t hx,ix;
GET_HIGH_WORD(hx,x);
ix = hx&0x7fffffff;
if(ix>= 0x3ff00000) { /* |x|>= 1 */
__uint32_t lx;
GET_LOW_WORD(lx,x);
if(((ix-0x3ff00000)|lx)==0)
/* asin(1)=+-pi/2 with inexact */
return x*pio2_hi+x*pio2_lo;
return (x-x)/(x-x); /* asin(|x|>1) is NaN */
} else if (ix<0x3fe00000) { /* |x|<0.5 */
if(ix<0x3e400000) { /* 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-fabs(x);
t = w*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 = __ieee754_sqrt(t);
if(ix>=0x3FEF3333) { /* if |x| > 0.975 */
w = p/q;
t = pio2_hi-(2.0*(s+s*w)-pio2_lo);
} else {
w = s;
SET_LOW_WORD(w,0);
c = (t-w*w)/(s+w);
r = p/q;
p = 2.0*s*r-(pio2_lo-2.0*c);
q = pio4_hi-2.0*w;
t = pio4_hi-(p-q);
}
if(hx>0) return t; else return -t;
}
 
#endif /* defined(_DOUBLE_IS_32BITS) */
/programs/develop/libraries/newlib/math/e_atan2.c
73,7 → 73,7
if(((ix|((lx|-lx)>>31))>0x7ff00000)||
((iy|((ly|-ly)>>31))>0x7ff00000)) /* x or y is NaN */
return x+y;
if((hx-0x3ff00000|lx)==0) return atan(y); /* x=1.0 */
if(((hx-0x3ff00000)|lx)==0) return atan(y); /* x=1.0 */
m = ((hy>>31)&1)|((hx>>30)&2); /* 2*sign(x)+sign(y) */
 
/* when y = 0 */
/programs/develop/libraries/newlib/math/e_atanh.c
0,0 → 1,75
 
/* @(#)e_atanh.c 5.1 93/09/24 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*
*/
 
/* __ieee754_atanh(x)
* Method :
* 1.Reduced x to positive by atanh(-x) = -atanh(x)
* 2.For x>=0.5
* 1 2x x
* atanh(x) = --- * log(1 + -------) = 0.5 * log1p(2 * --------)
* 2 1 - x 1 - x
*
* For x<0.5
* atanh(x) = 0.5*log1p(2x+2x*x/(1-x))
*
* Special cases:
* atanh(x) is NaN if |x| > 1 with signal;
* atanh(NaN) is that NaN with no signal;
* atanh(+-1) is +-INF with signal.
*
*/
 
#include "fdlibm.h"
 
#ifndef _DOUBLE_IS_32BITS
 
#ifdef __STDC__
static const double one = 1.0, huge = 1e300;
#else
static double one = 1.0, huge = 1e300;
#endif
 
#ifdef __STDC__
static const double zero = 0.0;
#else
static double zero = 0.0;
#endif
 
#ifdef __STDC__
double __ieee754_atanh(double x)
#else
double __ieee754_atanh(x)
double x;
#endif
{
double t;
__int32_t hx,ix;
__uint32_t lx;
EXTRACT_WORDS(hx,lx,x);
ix = hx&0x7fffffff;
if ((ix|((lx|(-lx))>>31))>0x3ff00000) /* |x|>1 */
return (x-x)/(x-x);
if(ix==0x3ff00000)
return x/zero;
if(ix<0x3e300000&&(huge+x)>zero) return x; /* x<2**-28 */
SET_HIGH_WORD(x,ix);
if(ix<0x3fe00000) { /* x < 0.5 */
t = x+x;
t = 0.5*log1p(t+t*x/(one-x));
} else
t = 0.5*log1p((x+x)/(one-x));
if(hx>=0) return t; else return -t;
}
 
#endif /* defined(_DOUBLE_IS_32BITS) */
/programs/develop/libraries/newlib/math/e_cosh.c
34,6 → 34,8
 
#include "fdlibm.h"
 
#ifndef _DOUBLE_IS_32BITS
 
#ifdef __STDC__
static const double one = 1.0, half=0.5, huge = 1.0e300;
#else
41,9 → 43,9
#endif
 
#ifdef __STDC__
double cosh(double x)
double __ieee754_cosh(double x)
#else
double cosh(x)
double __ieee754_cosh(x)
double x;
#endif
{
68,18 → 70,18
 
/* |x| in [0.5*ln2,22], return (exp(|x|)+1/exp(|x|)/2; */
if (ix < 0x40360000) {
t = exp(fabs(x));
t = __ieee754_exp(fabs(x));
return half*t+half/t;
}
 
/* |x| in [22, log(maxdouble)] return half*exp(|x|) */
if (ix < 0x40862E42) return half*exp(fabs(x));
if (ix < 0x40862E42) return half*__ieee754_exp(fabs(x));
 
/* |x| in [log(maxdouble), overflowthresold] */
GET_LOW_WORD(lx,x);
if (ix<0x408633CE ||
(ix==0x408633ce && lx<=(__uint32_t)0x8fb9f87d)) {
w = exp(half*fabs(x));
w = __ieee754_exp(half*fabs(x));
t = half*w;
return t*w;
}
88,3 → 90,4
return huge*huge;
}
 
#endif /* defined(_DOUBLE_IS_32BITS) */
/programs/develop/libraries/newlib/math/e_exp.c
0,0 → 1,166
 
/* @(#)e_exp.c 5.1 93/09/24 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
/* __ieee754_exp(x)
* Returns the exponential of x.
*
* Method
* 1. Argument reduction:
* Reduce x to an r so that |r| <= 0.5*ln2 ~ 0.34658.
* Given x, find r and integer k such that
*
* x = k*ln2 + r, |r| <= 0.5*ln2.
*
* Here r will be represented as r = hi-lo for better
* accuracy.
*
* 2. Approximation of exp(r) by a special rational function on
* the interval [0,0.34658]:
* Write
* R(r**2) = r*(exp(r)+1)/(exp(r)-1) = 2 + r*r/6 - r**4/360 + ...
* We use a special Reme algorithm on [0,0.34658] to generate
* a polynomial of degree 5 to approximate R. The maximum error
* of this polynomial approximation is bounded by 2**-59. In
* other words,
* R(z) ~ 2.0 + P1*z + P2*z**2 + P3*z**3 + P4*z**4 + P5*z**5
* (where z=r*r, and the values of P1 to P5 are listed below)
* and
* | 5 | -59
* | 2.0+P1*z+...+P5*z - R(z) | <= 2
* | |
* The computation of exp(r) thus becomes
* 2*r
* exp(r) = 1 + -------
* R - r
* r*R1(r)
* = 1 + r + ----------- (for better accuracy)
* 2 - R1(r)
* where
* 2 4 10
* R1(r) = r - (P1*r + P2*r + ... + P5*r ).
*
* 3. Scale back to obtain exp(x):
* From step 1, we have
* exp(x) = 2^k * exp(r)
*
* Special cases:
* exp(INF) is INF, exp(NaN) is NaN;
* exp(-INF) is 0, and
* for finite argument, only exp(0)=1 is exact.
*
* Accuracy:
* according to an error analysis, the error is always less than
* 1 ulp (unit in the last place).
*
* Misc. info.
* For IEEE double
* if x > 7.09782712893383973096e+02 then exp(x) overflow
* if x < -7.45133219101941108420e+02 then exp(x) underflow
*
* Constants:
* The hexadecimal values are the intended ones for the following
* constants. The decimal values may be used, provided that the
* compiler will convert from decimal to binary accurately enough
* to produce the hexadecimal values shown.
*/
 
#include "fdlibm.h"
 
#ifndef _DOUBLE_IS_32BITS
 
#ifdef __STDC__
static const double
#else
static double
#endif
one = 1.0,
halF[2] = {0.5,-0.5,},
huge = 1.0e+300,
twom1000= 9.33263618503218878990e-302, /* 2**-1000=0x01700000,0*/
o_threshold= 7.09782712893383973096e+02, /* 0x40862E42, 0xFEFA39EF */
u_threshold= -7.45133219101941108420e+02, /* 0xc0874910, 0xD52D3051 */
ln2HI[2] ={ 6.93147180369123816490e-01, /* 0x3fe62e42, 0xfee00000 */
-6.93147180369123816490e-01,},/* 0xbfe62e42, 0xfee00000 */
ln2LO[2] ={ 1.90821492927058770002e-10, /* 0x3dea39ef, 0x35793c76 */
-1.90821492927058770002e-10,},/* 0xbdea39ef, 0x35793c76 */
invln2 = 1.44269504088896338700e+00, /* 0x3ff71547, 0x652b82fe */
P1 = 1.66666666666666019037e-01, /* 0x3FC55555, 0x5555553E */
P2 = -2.77777777770155933842e-03, /* 0xBF66C16C, 0x16BEBD93 */
P3 = 6.61375632143793436117e-05, /* 0x3F11566A, 0xAF25DE2C */
P4 = -1.65339022054652515390e-06, /* 0xBEBBBD41, 0xC5D26BF1 */
P5 = 4.13813679705723846039e-08; /* 0x3E663769, 0x72BEA4D0 */
 
 
#ifdef __STDC__
double __ieee754_exp(double x) /* default IEEE double exp */
#else
double __ieee754_exp(x) /* default IEEE double exp */
double x;
#endif
{
double y,hi,lo,c,t;
__int32_t k = 0,xsb;
__uint32_t hx;
 
GET_HIGH_WORD(hx,x);
xsb = (hx>>31)&1; /* sign bit of x */
hx &= 0x7fffffff; /* high word of |x| */
 
/* filter out non-finite argument */
if(hx >= 0x40862E42) { /* if |x|>=709.78... */
if(hx>=0x7ff00000) {
__uint32_t lx;
GET_LOW_WORD(lx,x);
if(((hx&0xfffff)|lx)!=0)
return x+x; /* NaN */
else return (xsb==0)? x:0.0; /* exp(+-inf)={inf,0} */
}
if(x > o_threshold) return huge*huge; /* overflow */
if(x < u_threshold) return twom1000*twom1000; /* underflow */
}
 
/* argument reduction */
if(hx > 0x3fd62e42) { /* if |x| > 0.5 ln2 */
if(hx < 0x3FF0A2B2) { /* 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 < 0x3e300000) { /* when |x|<2**-28 */
if(huge+x>one) return one+x;/* trigger inexact */
}
 
/* 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-2.0)-x);
else y = one-((lo-(x*c)/(2.0-c))-hi);
if(k >= -1021) {
__uint32_t hy;
GET_HIGH_WORD(hy,y);
SET_HIGH_WORD(y,hy+(k<<20)); /* add k to y's exponent */
return y;
} else {
__uint32_t hy;
GET_HIGH_WORD(hy,y);
SET_HIGH_WORD(y,hy+((k+1000)<<20)); /* add k to y's exponent */
return y*twom1000;
}
}
 
#endif /* defined(_DOUBLE_IS_32BITS) */
/programs/develop/libraries/newlib/math/e_fmod.c
0,0 → 1,140
 
/* @(#)e_fmod.c 5.1 93/09/24 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
/*
* __ieee754_fmod(x,y)
* Return x mod y in exact arithmetic
* Method: shift and subtract
*/
 
#include "fdlibm.h"
 
#ifndef _DOUBLE_IS_32BITS
 
#ifdef __STDC__
static const double one = 1.0, Zero[] = {0.0, -0.0,};
#else
static double one = 1.0, Zero[] = {0.0, -0.0,};
#endif
 
#ifdef __STDC__
double __ieee754_fmod(double x, double y)
#else
double __ieee754_fmod(x,y)
double x,y ;
#endif
{
__int32_t n,hx,hy,hz,ix,iy,sx,i;
__uint32_t lx,ly,lz;
 
EXTRACT_WORDS(hx,lx,x);
EXTRACT_WORDS(hy,ly,y);
sx = hx&0x80000000; /* sign of x */
hx ^=sx; /* |x| */
hy &= 0x7fffffff; /* |y| */
 
/* purge off exception values */
if((hy|ly)==0||(hx>=0x7ff00000)|| /* y=0,or x not finite */
((hy|((ly|-ly)>>31))>0x7ff00000)) /* or y is NaN */
return (x*y)/(x*y);
if(hx<=hy) {
if((hx<hy)||(lx<ly)) return x; /* |x|<|y| return x */
if(lx==ly)
return Zero[(__uint32_t)sx>>31]; /* |x|=|y| return x*0*/
}
 
/* determine ix = ilogb(x) */
if(hx<0x00100000) { /* subnormal x */
if(hx==0) {
for (ix = -1043, i=lx; i>0; i<<=1) ix -=1;
} else {
for (ix = -1022,i=(hx<<11); i>0; i<<=1) ix -=1;
}
} else ix = (hx>>20)-1023;
 
/* determine iy = ilogb(y) */
if(hy<0x00100000) { /* subnormal y */
if(hy==0) {
for (iy = -1043, i=ly; i>0; i<<=1) iy -=1;
} else {
for (iy = -1022,i=(hy<<11); i>0; i<<=1) iy -=1;
}
} else iy = (hy>>20)-1023;
 
/* set up {hx,lx}, {hy,ly} and align y to x */
if(ix >= -1022)
hx = 0x00100000|(0x000fffff&hx);
else { /* subnormal x, shift x to normal */
n = -1022-ix;
if(n<=31) {
hx = (hx<<n)|(lx>>(32-n));
lx <<= n;
} else {
hx = lx<<(n-32);
lx = 0;
}
}
if(iy >= -1022)
hy = 0x00100000|(0x000fffff&hy);
else { /* subnormal y, shift y to normal */
n = -1022-iy;
if(n<=31) {
hy = (hy<<n)|(ly>>(32-n));
ly <<= n;
} else {
hy = ly<<(n-32);
ly = 0;
}
}
 
/* fix point fmod */
n = ix - iy;
while(n--) {
hz=hx-hy;lz=lx-ly; if(lx<ly) hz -= 1;
if(hz<0){hx = hx+hx+(lx>>31); lx = lx+lx;}
else {
if((hz|lz)==0) /* return sign(x)*0 */
return Zero[(__uint32_t)sx>>31];
hx = hz+hz+(lz>>31); lx = lz+lz;
}
}
hz=hx-hy;lz=lx-ly; if(lx<ly) hz -= 1;
if(hz>=0) {hx=hz;lx=lz;}
 
/* convert back to floating value and restore the sign */
if((hx|lx)==0) /* return sign(x)*0 */
return Zero[(__uint32_t)sx>>31];
while(hx<0x00100000) { /* normalize x */
hx = hx+hx+(lx>>31); lx = lx+lx;
iy -= 1;
}
if(iy>= -1022) { /* normalize output */
hx = ((hx-0x00100000)|((iy+1023)<<20));
INSERT_WORDS(x,hx|sx,lx);
} else { /* subnormal output */
n = -1022 - iy;
if(n<=20) {
lx = (lx>>n)|((__uint32_t)hx<<(32-n));
hx >>= n;
} else if (n<=31) {
lx = (hx<<(32-n))|(lx>>n); hx = sx;
} else {
lx = hx>>(n-32); hx = sx;
}
INSERT_WORDS(x,hx|sx,lx);
x *= one; /* create necessary signal */
}
return x; /* exact output */
}
 
#endif /* defined(_DOUBLE_IS_32BITS) */
/programs/develop/libraries/newlib/math/e_j0.c
0,0 → 1,487
 
/* @(#)e_j0.c 5.1 93/09/24 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
/* __ieee754_j0(x), __ieee754_y0(x)
* Bessel function of the first and second kinds of order zero.
* Method -- j0(x):
* 1. For tiny x, we use j0(x) = 1 - x^2/4 + x^4/64 - ...
* 2. Reduce x to |x| since j0(x)=j0(-x), and
* for x in (0,2)
* j0(x) = 1-z/4+ z^2*R0/S0, where z = x*x;
* (precision: |j0-1+z/4-z^2R0/S0 |<2**-63.67 )
* for x in (2,inf)
* j0(x) = sqrt(2/(pi*x))*(p0(x)*cos(x0)-q0(x)*sin(x0))
* where x0 = x-pi/4. It is better to compute sin(x0),cos(x0)
* as follow:
* cos(x0) = cos(x)cos(pi/4)+sin(x)sin(pi/4)
* = 1/sqrt(2) * (cos(x) + sin(x))
* sin(x0) = sin(x)cos(pi/4)-cos(x)sin(pi/4)
* = 1/sqrt(2) * (sin(x) - cos(x))
* (To avoid cancellation, use
* sin(x) +- cos(x) = -cos(2x)/(sin(x) -+ cos(x))
* to compute the worse one.)
*
* 3 Special cases
* j0(nan)= nan
* j0(0) = 1
* j0(inf) = 0
*
* Method -- y0(x):
* 1. For x<2.
* Since
* y0(x) = 2/pi*(j0(x)*(ln(x/2)+Euler) + x^2/4 - ...)
* therefore y0(x)-2/pi*j0(x)*ln(x) is an even function.
* We use the following function to approximate y0,
* y0(x) = U(z)/V(z) + (2/pi)*(j0(x)*ln(x)), z= x^2
* where
* U(z) = u00 + u01*z + ... + u06*z^6
* V(z) = 1 + v01*z + ... + v04*z^4
* with absolute approximation error bounded by 2**-72.
* Note: For tiny x, U/V = u0 and j0(x)~1, hence
* y0(tiny) = u0 + (2/pi)*ln(tiny), (choose tiny<2**-27)
* 2. For x>=2.
* y0(x) = sqrt(2/(pi*x))*(p0(x)*cos(x0)+q0(x)*sin(x0))
* where x0 = x-pi/4. It is better to compute sin(x0),cos(x0)
* by the method mentioned above.
* 3. Special cases: y0(0)=-inf, y0(x<0)=NaN, y0(inf)=0.
*/
 
#include "fdlibm.h"
 
#ifndef _DOUBLE_IS_32BITS
 
#ifdef __STDC__
static double pzero(double), qzero(double);
#else
static double pzero(), qzero();
#endif
 
#ifdef __STDC__
static const double
#else
static double
#endif
huge = 1e300,
one = 1.0,
invsqrtpi= 5.64189583547756279280e-01, /* 0x3FE20DD7, 0x50429B6D */
tpi = 6.36619772367581382433e-01, /* 0x3FE45F30, 0x6DC9C883 */
/* R0/S0 on [0, 2.00] */
R02 = 1.56249999999999947958e-02, /* 0x3F8FFFFF, 0xFFFFFFFD */
R03 = -1.89979294238854721751e-04, /* 0xBF28E6A5, 0xB61AC6E9 */
R04 = 1.82954049532700665670e-06, /* 0x3EBEB1D1, 0x0C503919 */
R05 = -4.61832688532103189199e-09, /* 0xBE33D5E7, 0x73D63FCE */
S01 = 1.56191029464890010492e-02, /* 0x3F8FFCE8, 0x82C8C2A4 */
S02 = 1.16926784663337450260e-04, /* 0x3F1EA6D2, 0xDD57DBF4 */
S03 = 5.13546550207318111446e-07, /* 0x3EA13B54, 0xCE84D5A9 */
S04 = 1.16614003333790000205e-09; /* 0x3E1408BC, 0xF4745D8F */
 
#ifdef __STDC__
static const double zero = 0.0;
#else
static double zero = 0.0;
#endif
 
#ifdef __STDC__
double __ieee754_j0(double x)
#else
double __ieee754_j0(x)
double x;
#endif
{
double z, s,c,ss,cc,r,u,v;
__int32_t hx,ix;
 
GET_HIGH_WORD(hx,x);
ix = hx&0x7fffffff;
if(ix>=0x7ff00000) return one/(x*x);
x = fabs(x);
if(ix >= 0x40000000) { /* |x| >= 2.0 */
s = sin(x);
c = cos(x);
ss = s-c;
cc = s+c;
if(ix<0x7fe00000) { /* make sure x+x not overflow */
z = -cos(x+x);
if ((s*c)<zero) cc = z/ss;
else ss = z/cc;
}
/*
* j0(x) = 1/sqrt(pi) * (P(0,x)*cc - Q(0,x)*ss) / sqrt(x)
* y0(x) = 1/sqrt(pi) * (P(0,x)*ss + Q(0,x)*cc) / sqrt(x)
*/
if(ix>0x48000000) z = (invsqrtpi*cc)/__ieee754_sqrt(x);
else {
u = pzero(x); v = qzero(x);
z = invsqrtpi*(u*cc-v*ss)/__ieee754_sqrt(x);
}
return z;
}
if(ix<0x3f200000) { /* |x| < 2**-13 */
if(huge+x>one) { /* raise inexact if x != 0 */
if(ix<0x3e400000) return one; /* |x|<2**-27 */
else return one - 0.25*x*x;
}
}
z = x*x;
r = z*(R02+z*(R03+z*(R04+z*R05)));
s = one+z*(S01+z*(S02+z*(S03+z*S04)));
if(ix < 0x3FF00000) { /* |x| < 1.00 */
return one + z*(-0.25+(r/s));
} else {
u = 0.5*x;
return((one+u)*(one-u)+z*(r/s));
}
}
 
#ifdef __STDC__
static const double
#else
static double
#endif
u00 = -7.38042951086872317523e-02, /* 0xBFB2E4D6, 0x99CBD01F */
u01 = 1.76666452509181115538e-01, /* 0x3FC69D01, 0x9DE9E3FC */
u02 = -1.38185671945596898896e-02, /* 0xBF8C4CE8, 0xB16CFA97 */
u03 = 3.47453432093683650238e-04, /* 0x3F36C54D, 0x20B29B6B */
u04 = -3.81407053724364161125e-06, /* 0xBECFFEA7, 0x73D25CAD */
u05 = 1.95590137035022920206e-08, /* 0x3E550057, 0x3B4EABD4 */
u06 = -3.98205194132103398453e-11, /* 0xBDC5E43D, 0x693FB3C8 */
v01 = 1.27304834834123699328e-02, /* 0x3F8A1270, 0x91C9C71A */
v02 = 7.60068627350353253702e-05, /* 0x3F13ECBB, 0xF578C6C1 */
v03 = 2.59150851840457805467e-07, /* 0x3E91642D, 0x7FF202FD */
v04 = 4.41110311332675467403e-10; /* 0x3DFE5018, 0x3BD6D9EF */
 
#ifdef __STDC__
double __ieee754_y0(double x)
#else
double __ieee754_y0(x)
double x;
#endif
{
double z, s,c,ss,cc,u,v;
__int32_t hx,ix,lx;
 
EXTRACT_WORDS(hx,lx,x);
ix = 0x7fffffff&hx;
/* Y0(NaN) is NaN, y0(-inf) is Nan, y0(inf) is 0 */
if(ix>=0x7ff00000) return one/(x+x*x);
if((ix|lx)==0) return -one/zero;
if(hx<0) return zero/zero;
if(ix >= 0x40000000) { /* |x| >= 2.0 */
/* y0(x) = sqrt(2/(pi*x))*(p0(x)*sin(x0)+q0(x)*cos(x0))
* where x0 = x-pi/4
* Better formula:
* cos(x0) = cos(x)cos(pi/4)+sin(x)sin(pi/4)
* = 1/sqrt(2) * (sin(x) + cos(x))
* sin(x0) = sin(x)cos(3pi/4)-cos(x)sin(3pi/4)
* = 1/sqrt(2) * (sin(x) - cos(x))
* To avoid cancellation, use
* sin(x) +- cos(x) = -cos(2x)/(sin(x) -+ cos(x))
* to compute the worse one.
*/
s = sin(x);
c = cos(x);
ss = s-c;
cc = s+c;
/*
* j0(x) = 1/sqrt(pi) * (P(0,x)*cc - Q(0,x)*ss) / sqrt(x)
* y0(x) = 1/sqrt(pi) * (P(0,x)*ss + Q(0,x)*cc) / sqrt(x)
*/
if(ix<0x7fe00000) { /* make sure x+x not overflow */
z = -cos(x+x);
if ((s*c)<zero) cc = z/ss;
else ss = z/cc;
}
if(ix>0x48000000) z = (invsqrtpi*ss)/__ieee754_sqrt(x);
else {
u = pzero(x); v = qzero(x);
z = invsqrtpi*(u*ss+v*cc)/__ieee754_sqrt(x);
}
return z;
}
if(ix<=0x3e400000) { /* x < 2**-27 */
return(u00 + tpi*__ieee754_log(x));
}
z = x*x;
u = u00+z*(u01+z*(u02+z*(u03+z*(u04+z*(u05+z*u06)))));
v = one+z*(v01+z*(v02+z*(v03+z*v04)));
return(u/v + tpi*(__ieee754_j0(x)*__ieee754_log(x)));
}
 
/* The asymptotic expansions of pzero is
* 1 - 9/128 s^2 + 11025/98304 s^4 - ..., where s = 1/x.
* For x >= 2, We approximate pzero by
* pzero(x) = 1 + (R/S)
* where R = pR0 + pR1*s^2 + pR2*s^4 + ... + pR5*s^10
* S = 1 + pS0*s^2 + ... + pS4*s^10
* and
* | pzero(x)-1-R/S | <= 2 ** ( -60.26)
*/
#ifdef __STDC__
static const double pR8[6] = { /* for x in [inf, 8]=1/[0,0.125] */
#else
static double pR8[6] = { /* for x in [inf, 8]=1/[0,0.125] */
#endif
0.00000000000000000000e+00, /* 0x00000000, 0x00000000 */
-7.03124999999900357484e-02, /* 0xBFB1FFFF, 0xFFFFFD32 */
-8.08167041275349795626e+00, /* 0xC02029D0, 0xB44FA779 */
-2.57063105679704847262e+02, /* 0xC0701102, 0x7B19E863 */
-2.48521641009428822144e+03, /* 0xC0A36A6E, 0xCD4DCAFC */
-5.25304380490729545272e+03, /* 0xC0B4850B, 0x36CC643D */
};
#ifdef __STDC__
static const double pS8[5] = {
#else
static double pS8[5] = {
#endif
1.16534364619668181717e+02, /* 0x405D2233, 0x07A96751 */
3.83374475364121826715e+03, /* 0x40ADF37D, 0x50596938 */
4.05978572648472545552e+04, /* 0x40E3D2BB, 0x6EB6B05F */
1.16752972564375915681e+05, /* 0x40FC810F, 0x8F9FA9BD */
4.76277284146730962675e+04, /* 0x40E74177, 0x4F2C49DC */
};
 
#ifdef __STDC__
static const double pR5[6] = { /* for x in [8,4.5454]=1/[0.125,0.22001] */
#else
static double pR5[6] = { /* for x in [8,4.5454]=1/[0.125,0.22001] */
#endif
-1.14125464691894502584e-11, /* 0xBDA918B1, 0x47E495CC */
-7.03124940873599280078e-02, /* 0xBFB1FFFF, 0xE69AFBC6 */
-4.15961064470587782438e+00, /* 0xC010A370, 0xF90C6BBF */
-6.76747652265167261021e+01, /* 0xC050EB2F, 0x5A7D1783 */
-3.31231299649172967747e+02, /* 0xC074B3B3, 0x6742CC63 */
-3.46433388365604912451e+02, /* 0xC075A6EF, 0x28A38BD7 */
};
#ifdef __STDC__
static const double pS5[5] = {
#else
static double pS5[5] = {
#endif
6.07539382692300335975e+01, /* 0x404E6081, 0x0C98C5DE */
1.05125230595704579173e+03, /* 0x40906D02, 0x5C7E2864 */
5.97897094333855784498e+03, /* 0x40B75AF8, 0x8FBE1D60 */
9.62544514357774460223e+03, /* 0x40C2CCB8, 0xFA76FA38 */
2.40605815922939109441e+03, /* 0x40A2CC1D, 0xC70BE864 */
};
 
#ifdef __STDC__
static const double pR3[6] = {/* for x in [4.547,2.8571]=1/[0.2199,0.35001] */
#else
static double pR3[6] = {/* for x in [4.547,2.8571]=1/[0.2199,0.35001] */
#endif
-2.54704601771951915620e-09, /* 0xBE25E103, 0x6FE1AA86 */
-7.03119616381481654654e-02, /* 0xBFB1FFF6, 0xF7C0E24B */
-2.40903221549529611423e+00, /* 0xC00345B2, 0xAEA48074 */
-2.19659774734883086467e+01, /* 0xC035F74A, 0x4CB94E14 */
-5.80791704701737572236e+01, /* 0xC04D0A22, 0x420A1A45 */
-3.14479470594888503854e+01, /* 0xC03F72AC, 0xA892D80F */
};
#ifdef __STDC__
static const double pS3[5] = {
#else
static double pS3[5] = {
#endif
3.58560338055209726349e+01, /* 0x4041ED92, 0x84077DD3 */
3.61513983050303863820e+02, /* 0x40769839, 0x464A7C0E */
1.19360783792111533330e+03, /* 0x4092A66E, 0x6D1061D6 */
1.12799679856907414432e+03, /* 0x40919FFC, 0xB8C39B7E */
1.73580930813335754692e+02, /* 0x4065B296, 0xFC379081 */
};
 
#ifdef __STDC__
static const double pR2[6] = {/* for x in [2.8570,2]=1/[0.3499,0.5] */
#else
static double pR2[6] = {/* for x in [2.8570,2]=1/[0.3499,0.5] */
#endif
-8.87534333032526411254e-08, /* 0xBE77D316, 0xE927026D */
-7.03030995483624743247e-02, /* 0xBFB1FF62, 0x495E1E42 */
-1.45073846780952986357e+00, /* 0xBFF73639, 0x8A24A843 */
-7.63569613823527770791e+00, /* 0xC01E8AF3, 0xEDAFA7F3 */
-1.11931668860356747786e+01, /* 0xC02662E6, 0xC5246303 */
-3.23364579351335335033e+00, /* 0xC009DE81, 0xAF8FE70F */
};
#ifdef __STDC__
static const double pS2[5] = {
#else
static double pS2[5] = {
#endif
2.22202997532088808441e+01, /* 0x40363865, 0x908B5959 */
1.36206794218215208048e+02, /* 0x4061069E, 0x0EE8878F */
2.70470278658083486789e+02, /* 0x4070E786, 0x42EA079B */
1.53875394208320329881e+02, /* 0x40633C03, 0x3AB6FAFF */
1.46576176948256193810e+01, /* 0x402D50B3, 0x44391809 */
};
 
#ifdef __STDC__
static double pzero(double x)
#else
static double pzero(x)
double x;
#endif
{
#ifdef __STDC__
const double *p,*q;
#else
double *p,*q;
#endif
double z,r,s;
__int32_t ix;
GET_HIGH_WORD(ix,x);
ix &= 0x7fffffff;
if(ix>=0x40200000) {p = pR8; q= pS8;}
else if(ix>=0x40122E8B){p = pR5; q= pS5;}
else if(ix>=0x4006DB6D){p = pR3; q= pS3;}
else {p = pR2; q= pS2;}
z = one/(x*x);
r = p[0]+z*(p[1]+z*(p[2]+z*(p[3]+z*(p[4]+z*p[5]))));
s = one+z*(q[0]+z*(q[1]+z*(q[2]+z*(q[3]+z*q[4]))));
return one+ r/s;
}
 
/* For x >= 8, the asymptotic expansions of qzero is
* -1/8 s + 75/1024 s^3 - ..., where s = 1/x.
* We approximate qzero by
* qzero(x) = s*(-1.25 + (R/S))
* where R = qR0 + qR1*s^2 + qR2*s^4 + ... + qR5*s^10
* S = 1 + qS0*s^2 + ... + qS5*s^12
* and
* | qzero(x)/s +1.25-R/S | <= 2 ** ( -61.22)
*/
#ifdef __STDC__
static const double qR8[6] = { /* for x in [inf, 8]=1/[0,0.125] */
#else
static double qR8[6] = { /* for x in [inf, 8]=1/[0,0.125] */
#endif
0.00000000000000000000e+00, /* 0x00000000, 0x00000000 */
7.32421874999935051953e-02, /* 0x3FB2BFFF, 0xFFFFFE2C */
1.17682064682252693899e+01, /* 0x40278952, 0x5BB334D6 */
5.57673380256401856059e+02, /* 0x40816D63, 0x15301825 */
8.85919720756468632317e+03, /* 0x40C14D99, 0x3E18F46D */
3.70146267776887834771e+04, /* 0x40E212D4, 0x0E901566 */
};
#ifdef __STDC__
static const double qS8[6] = {
#else
static double qS8[6] = {
#endif
1.63776026895689824414e+02, /* 0x406478D5, 0x365B39BC */
8.09834494656449805916e+03, /* 0x40BFA258, 0x4E6B0563 */
1.42538291419120476348e+05, /* 0x41016652, 0x54D38C3F */
8.03309257119514397345e+05, /* 0x412883DA, 0x83A52B43 */
8.40501579819060512818e+05, /* 0x4129A66B, 0x28DE0B3D */
-3.43899293537866615225e+05, /* 0xC114FD6D, 0x2C9530C5 */
};
 
#ifdef __STDC__
static const double qR5[6] = { /* for x in [8,4.5454]=1/[0.125,0.22001] */
#else
static double qR5[6] = { /* for x in [8,4.5454]=1/[0.125,0.22001] */
#endif
1.84085963594515531381e-11, /* 0x3DB43D8F, 0x29CC8CD9 */
7.32421766612684765896e-02, /* 0x3FB2BFFF, 0xD172B04C */
5.83563508962056953777e+00, /* 0x401757B0, 0xB9953DD3 */
1.35111577286449829671e+02, /* 0x4060E392, 0x0A8788E9 */
1.02724376596164097464e+03, /* 0x40900CF9, 0x9DC8C481 */
1.98997785864605384631e+03, /* 0x409F17E9, 0x53C6E3A6 */
};
#ifdef __STDC__
static const double qS5[6] = {
#else
static double qS5[6] = {
#endif
8.27766102236537761883e+01, /* 0x4054B1B3, 0xFB5E1543 */
2.07781416421392987104e+03, /* 0x40A03BA0, 0xDA21C0CE */
1.88472887785718085070e+04, /* 0x40D267D2, 0x7B591E6D */
5.67511122894947329769e+04, /* 0x40EBB5E3, 0x97E02372 */
3.59767538425114471465e+04, /* 0x40E19118, 0x1F7A54A0 */
-5.35434275601944773371e+03, /* 0xC0B4EA57, 0xBEDBC609 */
};
 
#ifdef __STDC__
static const double qR3[6] = {/* for x in [4.547,2.8571]=1/[0.2199,0.35001] */
#else
static double qR3[6] = {/* for x in [4.547,2.8571]=1/[0.2199,0.35001] */
#endif
4.37741014089738620906e-09, /* 0x3E32CD03, 0x6ADECB82 */
7.32411180042911447163e-02, /* 0x3FB2BFEE, 0x0E8D0842 */
3.34423137516170720929e+00, /* 0x400AC0FC, 0x61149CF5 */
4.26218440745412650017e+01, /* 0x40454F98, 0x962DAEDD */
1.70808091340565596283e+02, /* 0x406559DB, 0xE25EFD1F */
1.66733948696651168575e+02, /* 0x4064D77C, 0x81FA21E0 */
};
#ifdef __STDC__
static const double qS3[6] = {
#else
static double qS3[6] = {
#endif
4.87588729724587182091e+01, /* 0x40486122, 0xBFE343A6 */
7.09689221056606015736e+02, /* 0x40862D83, 0x86544EB3 */
3.70414822620111362994e+03, /* 0x40ACF04B, 0xE44DFC63 */
6.46042516752568917582e+03, /* 0x40B93C6C, 0xD7C76A28 */
2.51633368920368957333e+03, /* 0x40A3A8AA, 0xD94FB1C0 */
-1.49247451836156386662e+02, /* 0xC062A7EB, 0x201CF40F */
};
 
#ifdef __STDC__
static const double qR2[6] = {/* for x in [2.8570,2]=1/[0.3499,0.5] */
#else
static double qR2[6] = {/* for x in [2.8570,2]=1/[0.3499,0.5] */
#endif
1.50444444886983272379e-07, /* 0x3E84313B, 0x54F76BDB */
7.32234265963079278272e-02, /* 0x3FB2BEC5, 0x3E883E34 */
1.99819174093815998816e+00, /* 0x3FFFF897, 0xE727779C */
1.44956029347885735348e+01, /* 0x402CFDBF, 0xAAF96FE5 */
3.16662317504781540833e+01, /* 0x403FAA8E, 0x29FBDC4A */
1.62527075710929267416e+01, /* 0x403040B1, 0x71814BB4 */
};
#ifdef __STDC__
static const double qS2[6] = {
#else
static double qS2[6] = {
#endif
3.03655848355219184498e+01, /* 0x403E5D96, 0xF7C07AED */
2.69348118608049844624e+02, /* 0x4070D591, 0xE4D14B40 */
8.44783757595320139444e+02, /* 0x408A6645, 0x22B3BF22 */
8.82935845112488550512e+02, /* 0x408B977C, 0x9C5CC214 */
2.12666388511798828631e+02, /* 0x406A9553, 0x0E001365 */
-5.31095493882666946917e+00, /* 0xC0153E6A, 0xF8B32931 */
};
 
#ifdef __STDC__
static double qzero(double x)
#else
static double qzero(x)
double x;
#endif
{
#ifdef __STDC__
const double *p,*q;
#else
double *p,*q;
#endif
double s,r,z;
__int32_t ix;
GET_HIGH_WORD(ix,x);
ix &= 0x7fffffff;
if(ix>=0x40200000) {p = qR8; q= qS8;}
else if(ix>=0x40122E8B){p = qR5; q= qS5;}
else if(ix>=0x4006DB6D){p = qR3; q= qS3;}
else {p = qR2; q= qS2;}
z = one/(x*x);
r = p[0]+z*(p[1]+z*(p[2]+z*(p[3]+z*(p[4]+z*p[5]))));
s = one+z*(q[0]+z*(q[1]+z*(q[2]+z*(q[3]+z*(q[4]+z*q[5])))));
return (-.125 + r/s)/x;
}
 
#endif /* defined(_DOUBLE_IS_32BITS) */
/programs/develop/libraries/newlib/math/e_j1.c
0,0 → 1,486
 
/* @(#)e_j1.c 5.1 93/09/24 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
/* __ieee754_j1(x), __ieee754_y1(x)
* Bessel function of the first and second kinds of order zero.
* Method -- j1(x):
* 1. For tiny x, we use j1(x) = x/2 - x^3/16 + x^5/384 - ...
* 2. Reduce x to |x| since j1(x)=-j1(-x), and
* for x in (0,2)
* j1(x) = x/2 + x*z*R0/S0, where z = x*x;
* (precision: |j1/x - 1/2 - R0/S0 |<2**-61.51 )
* for x in (2,inf)
* j1(x) = sqrt(2/(pi*x))*(p1(x)*cos(x1)-q1(x)*sin(x1))
* y1(x) = sqrt(2/(pi*x))*(p1(x)*sin(x1)+q1(x)*cos(x1))
* where x1 = x-3*pi/4. It is better to compute sin(x1),cos(x1)
* as follow:
* cos(x1) = cos(x)cos(3pi/4)+sin(x)sin(3pi/4)
* = 1/sqrt(2) * (sin(x) - cos(x))
* sin(x1) = sin(x)cos(3pi/4)-cos(x)sin(3pi/4)
* = -1/sqrt(2) * (sin(x) + cos(x))
* (To avoid cancellation, use
* sin(x) +- cos(x) = -cos(2x)/(sin(x) -+ cos(x))
* to compute the worse one.)
*
* 3 Special cases
* j1(nan)= nan
* j1(0) = 0
* j1(inf) = 0
*
* Method -- y1(x):
* 1. screen out x<=0 cases: y1(0)=-inf, y1(x<0)=NaN
* 2. For x<2.
* Since
* y1(x) = 2/pi*(j1(x)*(ln(x/2)+Euler)-1/x-x/2+5/64*x^3-...)
* therefore y1(x)-2/pi*j1(x)*ln(x)-1/x is an odd function.
* We use the following function to approximate y1,
* y1(x) = x*U(z)/V(z) + (2/pi)*(j1(x)*ln(x)-1/x), z= x^2
* where for x in [0,2] (abs err less than 2**-65.89)
* U(z) = U0[0] + U0[1]*z + ... + U0[4]*z^4
* V(z) = 1 + v0[0]*z + ... + v0[4]*z^5
* Note: For tiny x, 1/x dominate y1 and hence
* y1(tiny) = -2/pi/tiny, (choose tiny<2**-54)
* 3. For x>=2.
* y1(x) = sqrt(2/(pi*x))*(p1(x)*sin(x1)+q1(x)*cos(x1))
* where x1 = x-3*pi/4. It is better to compute sin(x1),cos(x1)
* by method mentioned above.
*/
 
#include "fdlibm.h"
 
#ifndef _DOUBLE_IS_32BITS
 
#ifdef __STDC__
static double pone(double), qone(double);
#else
static double pone(), qone();
#endif
 
#ifdef __STDC__
static const double
#else
static double
#endif
huge = 1e300,
one = 1.0,
invsqrtpi= 5.64189583547756279280e-01, /* 0x3FE20DD7, 0x50429B6D */
tpi = 6.36619772367581382433e-01, /* 0x3FE45F30, 0x6DC9C883 */
/* R0/S0 on [0,2] */
r00 = -6.25000000000000000000e-02, /* 0xBFB00000, 0x00000000 */
r01 = 1.40705666955189706048e-03, /* 0x3F570D9F, 0x98472C61 */
r02 = -1.59955631084035597520e-05, /* 0xBEF0C5C6, 0xBA169668 */
r03 = 4.96727999609584448412e-08, /* 0x3E6AAAFA, 0x46CA0BD9 */
s01 = 1.91537599538363460805e-02, /* 0x3F939D0B, 0x12637E53 */
s02 = 1.85946785588630915560e-04, /* 0x3F285F56, 0xB9CDF664 */
s03 = 1.17718464042623683263e-06, /* 0x3EB3BFF8, 0x333F8498 */
s04 = 5.04636257076217042715e-09, /* 0x3E35AC88, 0xC97DFF2C */
s05 = 1.23542274426137913908e-11; /* 0x3DAB2ACF, 0xCFB97ED8 */
 
#ifdef __STDC__
static const double zero = 0.0;
#else
static double zero = 0.0;
#endif
 
#ifdef __STDC__
double __ieee754_j1(double x)
#else
double __ieee754_j1(x)
double x;
#endif
{
double z, s,c,ss,cc,r,u,v,y;
__int32_t hx,ix;
 
GET_HIGH_WORD(hx,x);
ix = hx&0x7fffffff;
if(ix>=0x7ff00000) return one/x;
y = fabs(x);
if(ix >= 0x40000000) { /* |x| >= 2.0 */
s = sin(y);
c = cos(y);
ss = -s-c;
cc = s-c;
if(ix<0x7fe00000) { /* make sure y+y not overflow */
z = cos(y+y);
if ((s*c)>zero) cc = z/ss;
else ss = z/cc;
}
/*
* j1(x) = 1/__ieee754_sqrt(pi) * (P(1,x)*cc - Q(1,x)*ss) / __ieee754_sqrt(x)
* y1(x) = 1/__ieee754_sqrt(pi) * (P(1,x)*ss + Q(1,x)*cc) / __ieee754_sqrt(x)
*/
if(ix>0x48000000) z = (invsqrtpi*cc)/__ieee754_sqrt(y);
else {
u = pone(y); v = qone(y);
z = invsqrtpi*(u*cc-v*ss)/__ieee754_sqrt(y);
}
if(hx<0) return -z;
else return z;
}
if(ix<0x3e400000) { /* |x|<2**-27 */
if(huge+x>one) return 0.5*x;/* inexact if x!=0 necessary */
}
z = x*x;
r = z*(r00+z*(r01+z*(r02+z*r03)));
s = one+z*(s01+z*(s02+z*(s03+z*(s04+z*s05))));
r *= x;
return(x*0.5+r/s);
}
 
#ifdef __STDC__
static const double U0[5] = {
#else
static double U0[5] = {
#endif
-1.96057090646238940668e-01, /* 0xBFC91866, 0x143CBC8A */
5.04438716639811282616e-02, /* 0x3FA9D3C7, 0x76292CD1 */
-1.91256895875763547298e-03, /* 0xBF5F55E5, 0x4844F50F */
2.35252600561610495928e-05, /* 0x3EF8AB03, 0x8FA6B88E */
-9.19099158039878874504e-08, /* 0xBE78AC00, 0x569105B8 */
};
#ifdef __STDC__
static const double V0[5] = {
#else
static double V0[5] = {
#endif
1.99167318236649903973e-02, /* 0x3F94650D, 0x3F4DA9F0 */
2.02552581025135171496e-04, /* 0x3F2A8C89, 0x6C257764 */
1.35608801097516229404e-06, /* 0x3EB6C05A, 0x894E8CA6 */
6.22741452364621501295e-09, /* 0x3E3ABF1D, 0x5BA69A86 */
1.66559246207992079114e-11, /* 0x3DB25039, 0xDACA772A */
};
 
#ifdef __STDC__
double __ieee754_y1(double x)
#else
double __ieee754_y1(x)
double x;
#endif
{
double z, s,c,ss,cc,u,v;
__int32_t hx,ix,lx;
 
EXTRACT_WORDS(hx,lx,x);
ix = 0x7fffffff&hx;
/* if Y1(NaN) is NaN, Y1(-inf) is NaN, Y1(inf) is 0 */
if(ix>=0x7ff00000) return one/(x+x*x);
if((ix|lx)==0) return -one/zero;
if(hx<0) return zero/zero;
if(ix >= 0x40000000) { /* |x| >= 2.0 */
s = sin(x);
c = cos(x);
ss = -s-c;
cc = s-c;
if(ix<0x7fe00000) { /* make sure x+x not overflow */
z = cos(x+x);
if ((s*c)>zero) cc = z/ss;
else ss = z/cc;
}
/* y1(x) = sqrt(2/(pi*x))*(p1(x)*sin(x0)+q1(x)*cos(x0))
* where x0 = x-3pi/4
* Better formula:
* cos(x0) = cos(x)cos(3pi/4)+sin(x)sin(3pi/4)
* = 1/sqrt(2) * (sin(x) - cos(x))
* sin(x0) = sin(x)cos(3pi/4)-cos(x)sin(3pi/4)
* = -1/sqrt(2) * (cos(x) + sin(x))
* To avoid cancellation, use
* sin(x) +- cos(x) = -cos(2x)/(sin(x) -+ cos(x))
* to compute the worse one.
*/
if(ix>0x48000000) z = (invsqrtpi*ss)/__ieee754_sqrt(x);
else {
u = pone(x); v = qone(x);
z = invsqrtpi*(u*ss+v*cc)/__ieee754_sqrt(x);
}
return z;
}
if(ix<=0x3c900000) { /* x < 2**-54 */
return(-tpi/x);
}
z = x*x;
u = U0[0]+z*(U0[1]+z*(U0[2]+z*(U0[3]+z*U0[4])));
v = one+z*(V0[0]+z*(V0[1]+z*(V0[2]+z*(V0[3]+z*V0[4]))));
return(x*(u/v) + tpi*(__ieee754_j1(x)*__ieee754_log(x)-one/x));
}
 
/* For x >= 8, the asymptotic expansions of pone is
* 1 + 15/128 s^2 - 4725/2^15 s^4 - ..., where s = 1/x.
* We approximate pone by
* pone(x) = 1 + (R/S)
* where R = pr0 + pr1*s^2 + pr2*s^4 + ... + pr5*s^10
* S = 1 + ps0*s^2 + ... + ps4*s^10
* and
* | pone(x)-1-R/S | <= 2 ** ( -60.06)
*/
 
#ifdef __STDC__
static const double pr8[6] = { /* for x in [inf, 8]=1/[0,0.125] */
#else
static double pr8[6] = { /* for x in [inf, 8]=1/[0,0.125] */
#endif
0.00000000000000000000e+00, /* 0x00000000, 0x00000000 */
1.17187499999988647970e-01, /* 0x3FBDFFFF, 0xFFFFFCCE */
1.32394806593073575129e+01, /* 0x402A7A9D, 0x357F7FCE */
4.12051854307378562225e+02, /* 0x4079C0D4, 0x652EA590 */
3.87474538913960532227e+03, /* 0x40AE457D, 0xA3A532CC */
7.91447954031891731574e+03, /* 0x40BEEA7A, 0xC32782DD */
};
#ifdef __STDC__
static const double ps8[5] = {
#else
static double ps8[5] = {
#endif
1.14207370375678408436e+02, /* 0x405C8D45, 0x8E656CAC */
3.65093083420853463394e+03, /* 0x40AC85DC, 0x964D274F */
3.69562060269033463555e+04, /* 0x40E20B86, 0x97C5BB7F */
9.76027935934950801311e+04, /* 0x40F7D42C, 0xB28F17BB */
3.08042720627888811578e+04, /* 0x40DE1511, 0x697A0B2D */
};
 
#ifdef __STDC__
static const double pr5[6] = { /* for x in [8,4.5454]=1/[0.125,0.22001] */
#else
static double pr5[6] = { /* for x in [8,4.5454]=1/[0.125,0.22001] */
#endif
1.31990519556243522749e-11, /* 0x3DAD0667, 0xDAE1CA7D */
1.17187493190614097638e-01, /* 0x3FBDFFFF, 0xE2C10043 */
6.80275127868432871736e+00, /* 0x401B3604, 0x6E6315E3 */
1.08308182990189109773e+02, /* 0x405B13B9, 0x452602ED */
5.17636139533199752805e+02, /* 0x40802D16, 0xD052D649 */
5.28715201363337541807e+02, /* 0x408085B8, 0xBB7E0CB7 */
};
#ifdef __STDC__
static const double ps5[5] = {
#else
static double ps5[5] = {
#endif
5.92805987221131331921e+01, /* 0x404DA3EA, 0xA8AF633D */
9.91401418733614377743e+02, /* 0x408EFB36, 0x1B066701 */
5.35326695291487976647e+03, /* 0x40B4E944, 0x5706B6FB */
7.84469031749551231769e+03, /* 0x40BEA4B0, 0xB8A5BB15 */
1.50404688810361062679e+03, /* 0x40978030, 0x036F5E51 */
};
 
#ifdef __STDC__
static const double pr3[6] = {
#else
static double pr3[6] = {/* for x in [4.547,2.8571]=1/[0.2199,0.35001] */
#endif
3.02503916137373618024e-09, /* 0x3E29FC21, 0xA7AD9EDD */
1.17186865567253592491e-01, /* 0x3FBDFFF5, 0x5B21D17B */
3.93297750033315640650e+00, /* 0x400F76BC, 0xE85EAD8A */
3.51194035591636932736e+01, /* 0x40418F48, 0x9DA6D129 */
9.10550110750781271918e+01, /* 0x4056C385, 0x4D2C1837 */
4.85590685197364919645e+01, /* 0x4048478F, 0x8EA83EE5 */
};
#ifdef __STDC__
static const double ps3[5] = {
#else
static double ps3[5] = {
#endif
3.47913095001251519989e+01, /* 0x40416549, 0xA134069C */
3.36762458747825746741e+02, /* 0x40750C33, 0x07F1A75F */
1.04687139975775130551e+03, /* 0x40905B7C, 0x5037D523 */
8.90811346398256432622e+02, /* 0x408BD67D, 0xA32E31E9 */
1.03787932439639277504e+02, /* 0x4059F26D, 0x7C2EED53 */
};
 
#ifdef __STDC__
static const double pr2[6] = {/* for x in [2.8570,2]=1/[0.3499,0.5] */
#else
static double pr2[6] = {/* for x in [2.8570,2]=1/[0.3499,0.5] */
#endif
1.07710830106873743082e-07, /* 0x3E7CE9D4, 0xF65544F4 */
1.17176219462683348094e-01, /* 0x3FBDFF42, 0xBE760D83 */
2.36851496667608785174e+00, /* 0x4002F2B7, 0xF98FAEC0 */
1.22426109148261232917e+01, /* 0x40287C37, 0x7F71A964 */
1.76939711271687727390e+01, /* 0x4031B1A8, 0x177F8EE2 */
5.07352312588818499250e+00, /* 0x40144B49, 0xA574C1FE */
};
#ifdef __STDC__
static const double ps2[5] = {
#else
static double ps2[5] = {
#endif
2.14364859363821409488e+01, /* 0x40356FBD, 0x8AD5ECDC */
1.25290227168402751090e+02, /* 0x405F5293, 0x14F92CD5 */
2.32276469057162813669e+02, /* 0x406D08D8, 0xD5A2DBD9 */
1.17679373287147100768e+02, /* 0x405D6B7A, 0xDA1884A9 */
8.36463893371618283368e+00, /* 0x4020BAB1, 0xF44E5192 */
};
 
#ifdef __STDC__
static double pone(double x)
#else
static double pone(x)
double x;
#endif
{
#ifdef __STDC__
const double *p,*q;
#else
double *p,*q;
#endif
double z,r,s;
__int32_t ix;
GET_HIGH_WORD(ix,x);
ix &= 0x7fffffff;
if(ix>=0x40200000) {p = pr8; q= ps8;}
else if(ix>=0x40122E8B){p = pr5; q= ps5;}
else if(ix>=0x4006DB6D){p = pr3; q= ps3;}
else {p = pr2; q= ps2;}
z = one/(x*x);
r = p[0]+z*(p[1]+z*(p[2]+z*(p[3]+z*(p[4]+z*p[5]))));
s = one+z*(q[0]+z*(q[1]+z*(q[2]+z*(q[3]+z*q[4]))));
return one+ r/s;
}
 
/* For x >= 8, the asymptotic expansions of qone is
* 3/8 s - 105/1024 s^3 - ..., where s = 1/x.
* We approximate qone by
* qone(x) = s*(0.375 + (R/S))
* where R = qr1*s^2 + qr2*s^4 + ... + qr5*s^10
* S = 1 + qs1*s^2 + ... + qs6*s^12
* and
* | qone(x)/s -0.375-R/S | <= 2 ** ( -61.13)
*/
 
#ifdef __STDC__
static const double qr8[6] = { /* for x in [inf, 8]=1/[0,0.125] */
#else
static double qr8[6] = { /* for x in [inf, 8]=1/[0,0.125] */
#endif
0.00000000000000000000e+00, /* 0x00000000, 0x00000000 */
-1.02539062499992714161e-01, /* 0xBFBA3FFF, 0xFFFFFDF3 */
-1.62717534544589987888e+01, /* 0xC0304591, 0xA26779F7 */
-7.59601722513950107896e+02, /* 0xC087BCD0, 0x53E4B576 */
-1.18498066702429587167e+04, /* 0xC0C724E7, 0x40F87415 */
-4.84385124285750353010e+04, /* 0xC0E7A6D0, 0x65D09C6A */
};
#ifdef __STDC__
static const double qs8[6] = {
#else
static double qs8[6] = {
#endif
1.61395369700722909556e+02, /* 0x40642CA6, 0xDE5BCDE5 */
7.82538599923348465381e+03, /* 0x40BE9162, 0xD0D88419 */
1.33875336287249578163e+05, /* 0x4100579A, 0xB0B75E98 */
7.19657723683240939863e+05, /* 0x4125F653, 0x72869C19 */
6.66601232617776375264e+05, /* 0x412457D2, 0x7719AD5C */
-2.94490264303834643215e+05, /* 0xC111F969, 0x0EA5AA18 */
};
 
#ifdef __STDC__
static const double qr5[6] = { /* for x in [8,4.5454]=1/[0.125,0.22001] */
#else
static double qr5[6] = { /* for x in [8,4.5454]=1/[0.125,0.22001] */
#endif
-2.08979931141764104297e-11, /* 0xBDB6FA43, 0x1AA1A098 */
-1.02539050241375426231e-01, /* 0xBFBA3FFF, 0xCB597FEF */
-8.05644828123936029840e+00, /* 0xC0201CE6, 0xCA03AD4B */
-1.83669607474888380239e+02, /* 0xC066F56D, 0x6CA7B9B0 */
-1.37319376065508163265e+03, /* 0xC09574C6, 0x6931734F */
-2.61244440453215656817e+03, /* 0xC0A468E3, 0x88FDA79D */
};
#ifdef __STDC__
static const double qs5[6] = {
#else
static double qs5[6] = {
#endif
8.12765501384335777857e+01, /* 0x405451B2, 0xFF5A11B2 */
1.99179873460485964642e+03, /* 0x409F1F31, 0xE77BF839 */
1.74684851924908907677e+04, /* 0x40D10F1F, 0x0D64CE29 */
4.98514270910352279316e+04, /* 0x40E8576D, 0xAABAD197 */
2.79480751638918118260e+04, /* 0x40DB4B04, 0xCF7C364B */
-4.71918354795128470869e+03, /* 0xC0B26F2E, 0xFCFFA004 */
};
 
#ifdef __STDC__
static const double qr3[6] = {
#else
static double qr3[6] = {/* for x in [4.547,2.8571]=1/[0.2199,0.35001] */
#endif
-5.07831226461766561369e-09, /* 0xBE35CFA9, 0xD38FC84F */
-1.02537829820837089745e-01, /* 0xBFBA3FEB, 0x51AEED54 */
-4.61011581139473403113e+00, /* 0xC01270C2, 0x3302D9FF */
-5.78472216562783643212e+01, /* 0xC04CEC71, 0xC25D16DA */
-2.28244540737631695038e+02, /* 0xC06C87D3, 0x4718D55F */
-2.19210128478909325622e+02, /* 0xC06B66B9, 0x5F5C1BF6 */
};
#ifdef __STDC__
static const double qs3[6] = {
#else
static double qs3[6] = {
#endif
4.76651550323729509273e+01, /* 0x4047D523, 0xCCD367E4 */
6.73865112676699709482e+02, /* 0x40850EEB, 0xC031EE3E */
3.38015286679526343505e+03, /* 0x40AA684E, 0x448E7C9A */
5.54772909720722782367e+03, /* 0x40B5ABBA, 0xA61D54A6 */
1.90311919338810798763e+03, /* 0x409DBC7A, 0x0DD4DF4B */
-1.35201191444307340817e+02, /* 0xC060E670, 0x290A311F */
};
 
#ifdef __STDC__
static const double qr2[6] = {/* for x in [2.8570,2]=1/[0.3499,0.5] */
#else
static double qr2[6] = {/* for x in [2.8570,2]=1/[0.3499,0.5] */
#endif
-1.78381727510958865572e-07, /* 0xBE87F126, 0x44C626D2 */
-1.02517042607985553460e-01, /* 0xBFBA3E8E, 0x9148B010 */
-2.75220568278187460720e+00, /* 0xC0060484, 0x69BB4EDA */
-1.96636162643703720221e+01, /* 0xC033A9E2, 0xC168907F */
-4.23253133372830490089e+01, /* 0xC04529A3, 0xDE104AAA */
-2.13719211703704061733e+01, /* 0xC0355F36, 0x39CF6E52 */
};
#ifdef __STDC__
static const double qs2[6] = {
#else
static double qs2[6] = {
#endif
2.95333629060523854548e+01, /* 0x403D888A, 0x78AE64FF */
2.52981549982190529136e+02, /* 0x406F9F68, 0xDB821CBA */
7.57502834868645436472e+02, /* 0x4087AC05, 0xCE49A0F7 */
7.39393205320467245656e+02, /* 0x40871B25, 0x48D4C029 */
1.55949003336666123687e+02, /* 0x40637E5E, 0x3C3ED8D4 */
-4.95949898822628210127e+00, /* 0xC013D686, 0xE71BE86B */
};
 
#ifdef __STDC__
static double qone(double x)
#else
static double qone(x)
double x;
#endif
{
#ifdef __STDC__
const double *p,*q;
#else
double *p,*q;
#endif
double s,r,z;
__int32_t ix;
GET_HIGH_WORD(ix,x);
ix &= 0x7fffffff;
if(ix>=0x40200000) {p = qr8; q= qs8;}
else if(ix>=0x40122E8B){p = qr5; q= qs5;}
else if(ix>=0x4006DB6D){p = qr3; q= qs3;}
else {p = qr2; q= qs2;}
z = one/(x*x);
r = p[0]+z*(p[1]+z*(p[2]+z*(p[3]+z*(p[4]+z*p[5]))));
s = one+z*(q[0]+z*(q[1]+z*(q[2]+z*(q[3]+z*(q[4]+z*q[5])))));
return (.375 + r/s)/x;
}
 
#endif /* defined(_DOUBLE_IS_32BITS) */
/programs/develop/libraries/newlib/math/e_jn.c
0,0 → 1,281
 
/* @(#)e_jn.c 5.1 93/09/24 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
/*
* __ieee754_jn(n, x), __ieee754_yn(n, x)
* floating point Bessel's function of the 1st and 2nd kind
* of order n
*
* Special cases:
* y0(0)=y1(0)=yn(n,0) = -inf with division by zero signal;
* y0(-ve)=y1(-ve)=yn(n,-ve) are NaN with invalid signal.
* Note 2. About jn(n,x), yn(n,x)
* For n=0, j0(x) is called,
* for n=1, j1(x) is called,
* for n<x, forward recursion us used starting
* from values of j0(x) and j1(x).
* for n>x, a continued fraction approximation to
* j(n,x)/j(n-1,x) is evaluated and then backward
* recursion is used starting from a supposed value
* for j(n,x). The resulting value of j(0,x) is
* compared with the actual value to correct the
* supposed value of j(n,x).
*
* yn(n,x) is similar in all respects, except
* that forward recursion is used for all
* values of n>1.
*
*/
 
#include "fdlibm.h"
 
#ifndef _DOUBLE_IS_32BITS
 
#ifdef __STDC__
static const double
#else
static double
#endif
invsqrtpi= 5.64189583547756279280e-01, /* 0x3FE20DD7, 0x50429B6D */
two = 2.00000000000000000000e+00, /* 0x40000000, 0x00000000 */
one = 1.00000000000000000000e+00; /* 0x3FF00000, 0x00000000 */
 
#ifdef __STDC__
static const double zero = 0.00000000000000000000e+00;
#else
static double zero = 0.00000000000000000000e+00;
#endif
 
#ifdef __STDC__
double __ieee754_jn(int n, double x)
#else
double __ieee754_jn(n,x)
int n; double x;
#endif
{
__int32_t i,hx,ix,lx, sgn;
double a, b, temp, di;
double z, w;
 
/* J(-n,x) = (-1)^n * J(n, x), J(n, -x) = (-1)^n * J(n, x)
* Thus, J(-n,x) = J(n,-x)
*/
EXTRACT_WORDS(hx,lx,x);
ix = 0x7fffffff&hx;
/* if J(n,NaN) is NaN */
if((ix|((__uint32_t)(lx|-lx))>>31)>0x7ff00000) return x+x;
if(n<0){
n = -n;
x = -x;
hx ^= 0x80000000;
}
if(n==0) return(__ieee754_j0(x));
if(n==1) return(__ieee754_j1(x));
sgn = (n&1)&(hx>>31); /* even n -- 0, odd n -- sign(x) */
x = fabs(x);
if((ix|lx)==0||ix>=0x7ff00000) /* if x is 0 or inf */
b = zero;
else if((double)n<=x) {
/* Safe to use J(n+1,x)=2n/x *J(n,x)-J(n-1,x) */
if(ix>=0x52D00000) { /* x > 2**302 */
/* (x >> n**2)
* Jn(x) = cos(x-(2n+1)*pi/4)*sqrt(2/x*pi)
* Yn(x) = sin(x-(2n+1)*pi/4)*sqrt(2/x*pi)
* Let s=sin(x), c=cos(x),
* xn=x-(2n+1)*pi/4, sqt2 = sqrt(2),then
*
* n sin(xn)*sqt2 cos(xn)*sqt2
* ----------------------------------
* 0 s-c c+s
* 1 -s-c -c+s
* 2 -s+c -c-s
* 3 s+c c-s
*/
switch(n&3) {
case 0: temp = cos(x)+sin(x); break;
case 1: temp = -cos(x)+sin(x); break;
case 2: temp = -cos(x)-sin(x); break;
case 3: temp = cos(x)-sin(x); break;
}
b = invsqrtpi*temp/__ieee754_sqrt(x);
} else {
a = __ieee754_j0(x);
b = __ieee754_j1(x);
for(i=1;i<n;i++){
temp = b;
b = b*((double)(i+i)/x) - a; /* avoid underflow */
a = temp;
}
}
} else {
if(ix<0x3e100000) { /* x < 2**-29 */
/* x is tiny, return the first Taylor expansion of J(n,x)
* J(n,x) = 1/n!*(x/2)^n - ...
*/
if(n>33) /* underflow */
b = zero;
else {
temp = x*0.5; b = temp;
for (a=one,i=2;i<=n;i++) {
a *= (double)i; /* a = n! */
b *= temp; /* b = (x/2)^n */
}
b = b/a;
}
} else {
/* use backward recurrence */
/* x x^2 x^2
* J(n,x)/J(n-1,x) = ---- ------ ------ .....
* 2n - 2(n+1) - 2(n+2)
*
* 1 1 1
* (for large x) = ---- ------ ------ .....
* 2n 2(n+1) 2(n+2)
* -- - ------ - ------ -
* x x x
*
* Let w = 2n/x and h=2/x, then the above quotient
* is equal to the continued fraction:
* 1
* = -----------------------
* 1
* w - -----------------
* 1
* w+h - ---------
* w+2h - ...
*
* To determine how many terms needed, let
* Q(0) = w, Q(1) = w(w+h) - 1,
* Q(k) = (w+k*h)*Q(k-1) - Q(k-2),
* When Q(k) > 1e4 good for single
* When Q(k) > 1e9 good for double
* When Q(k) > 1e17 good for quadruple
*/
/* determine k */
double t,v;
double q0,q1,h,tmp; __int32_t k,m;
w = (n+n)/(double)x; h = 2.0/(double)x;
q0 = w; z = w+h; q1 = w*z - 1.0; k=1;
while(q1<1.0e9) {
k += 1; z += h;
tmp = z*q1 - q0;
q0 = q1;
q1 = tmp;
}
m = n+n;
for(t=zero, i = 2*(n+k); i>=m; i -= 2) t = one/(i/x-t);
a = t;
b = one;
/* estimate log((2/x)^n*n!) = n*log(2/x)+n*ln(n)
* Hence, if n*(log(2n/x)) > ...
* single 8.8722839355e+01
* double 7.09782712893383973096e+02
* long double 1.1356523406294143949491931077970765006170e+04
* then recurrent value may overflow and the result is
* likely underflow to zero
*/
tmp = n;
v = two/x;
tmp = tmp*__ieee754_log(fabs(v*tmp));
if(tmp<7.09782712893383973096e+02) {
for(i=n-1,di=(double)(i+i);i>0;i--){
temp = b;
b *= di;
b = b/x - a;
a = temp;
di -= two;
}
} else {
for(i=n-1,di=(double)(i+i);i>0;i--){
temp = b;
b *= di;
b = b/x - a;
a = temp;
di -= two;
/* scale b to avoid spurious overflow */
if(b>1e100) {
a /= b;
t /= b;
b = one;
}
}
}
b = (t*__ieee754_j0(x)/b);
}
}
if(sgn==1) return -b; else return b;
}
 
#ifdef __STDC__
double __ieee754_yn(int n, double x)
#else
double __ieee754_yn(n,x)
int n; double x;
#endif
{
__int32_t i,hx,ix,lx;
__int32_t sign;
double a, b, temp;
 
EXTRACT_WORDS(hx,lx,x);
ix = 0x7fffffff&hx;
/* if Y(n,NaN) is NaN */
if((ix|((__uint32_t)(lx|-lx))>>31)>0x7ff00000) return x+x;
if((ix|lx)==0) return -one/zero;
if(hx<0) return zero/zero;
sign = 1;
if(n<0){
n = -n;
sign = 1 - ((n&1)<<1);
}
if(n==0) return(__ieee754_y0(x));
if(n==1) return(sign*__ieee754_y1(x));
if(ix==0x7ff00000) return zero;
if(ix>=0x52D00000) { /* x > 2**302 */
/* (x >> n**2)
* Jn(x) = cos(x-(2n+1)*pi/4)*sqrt(2/x*pi)
* Yn(x) = sin(x-(2n+1)*pi/4)*sqrt(2/x*pi)
* Let s=sin(x), c=cos(x),
* xn=x-(2n+1)*pi/4, sqt2 = sqrt(2),then
*
* n sin(xn)*sqt2 cos(xn)*sqt2
* ----------------------------------
* 0 s-c c+s
* 1 -s-c -c+s
* 2 -s+c -c-s
* 3 s+c c-s
*/
switch(n&3) {
case 0: temp = sin(x)-cos(x); break;
case 1: temp = -sin(x)-cos(x); break;
case 2: temp = -sin(x)+cos(x); break;
case 3: temp = sin(x)+cos(x); break;
}
b = invsqrtpi*temp/__ieee754_sqrt(x);
} else {
__uint32_t high;
a = __ieee754_y0(x);
b = __ieee754_y1(x);
/* quit if b is -inf */
GET_HIGH_WORD(high,b);
for(i=1;i<n&&high!=0xfff00000;i++){
temp = b;
b = ((double)(i+i)/x)*b - a;
GET_HIGH_WORD(high,b);
a = temp;
}
}
if(sign>0) return b; else return -b;
}
 
#endif /* defined(_DOUBLE_IS_32BITS) */
/programs/develop/libraries/newlib/math/e_log.c
0,0 → 1,146
 
/* @(#)e_log.c 5.1 93/09/24 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
/* __ieee754_log(x)
* Return the logrithm of x
*
* Method :
* 1. Argument Reduction: find k and f such that
* x = 2^k * (1+f),
* where sqrt(2)/2 < 1+f < sqrt(2) .
*
* 2. Approximation of log(1+f).
* Let s = f/(2+f) ; based on log(1+f) = log(1+s) - log(1-s)
* = 2s + 2/3 s**3 + 2/5 s**5 + .....,
* = 2s + s*R
* We use a special Reme algorithm on [0,0.1716] to generate
* a polynomial of degree 14 to approximate R The maximum error
* of this polynomial approximation is bounded by 2**-58.45. In
* other words,
* 2 4 6 8 10 12 14
* R(z) ~ Lg1*s +Lg2*s +Lg3*s +Lg4*s +Lg5*s +Lg6*s +Lg7*s
* (the values of Lg1 to Lg7 are listed in the program)
* and
* | 2 14 | -58.45
* | Lg1*s +...+Lg7*s - R(z) | <= 2
* | |
* Note that 2s = f - s*f = f - hfsq + s*hfsq, where hfsq = f*f/2.
* In order to guarantee error in log below 1ulp, we compute log
* by
* log(1+f) = f - s*(f - R) (if f is not too large)
* log(1+f) = f - (hfsq - s*(hfsq+R)). (better accuracy)
*
* 3. Finally, log(x) = k*ln2 + log(1+f).
* = k*ln2_hi+(f-(hfsq-(s*(hfsq+R)+k*ln2_lo)))
* Here ln2 is split into two floating point number:
* ln2_hi + ln2_lo,
* where n*ln2_hi is always exact for |n| < 2000.
*
* Special cases:
* log(x) is NaN with signal if x < 0 (including -INF) ;
* log(+INF) is +INF; log(0) is -INF with signal;
* log(NaN) is that NaN with no signal.
*
* Accuracy:
* according to an error analysis, the error is always less than
* 1 ulp (unit in the last place).
*
* Constants:
* The hexadecimal values are the intended ones for the following
* constants. The decimal values may be used, provided that the
* compiler will convert from decimal to binary accurately enough
* to produce the hexadecimal values shown.
*/
 
#include "fdlibm.h"
 
#ifndef _DOUBLE_IS_32BITS
 
#ifdef __STDC__
static const double
#else
static double
#endif
ln2_hi = 6.93147180369123816490e-01, /* 3fe62e42 fee00000 */
ln2_lo = 1.90821492927058770002e-10, /* 3dea39ef 35793c76 */
two54 = 1.80143985094819840000e+16, /* 43500000 00000000 */
Lg1 = 6.666666666666735130e-01, /* 3FE55555 55555593 */
Lg2 = 3.999999999940941908e-01, /* 3FD99999 9997FA04 */
Lg3 = 2.857142874366239149e-01, /* 3FD24924 94229359 */
Lg4 = 2.222219843214978396e-01, /* 3FCC71C5 1D8E78AF */
Lg5 = 1.818357216161805012e-01, /* 3FC74664 96CB03DE */
Lg6 = 1.531383769920937332e-01, /* 3FC39A09 D078C69F */
Lg7 = 1.479819860511658591e-01; /* 3FC2F112 DF3E5244 */
 
#ifdef __STDC__
static const double zero = 0.0;
#else
static double zero = 0.0;
#endif
 
#ifdef __STDC__
double __ieee754_log(double x)
#else
double __ieee754_log(x)
double x;
#endif
{
double hfsq,f,s,z,R,w,t1,t2,dk;
__int32_t k,hx,i,j;
__uint32_t lx;
 
EXTRACT_WORDS(hx,lx,x);
 
k=0;
if (hx < 0x00100000) { /* x < 2**-1022 */
if (((hx&0x7fffffff)|lx)==0)
return -two54/zero; /* log(+-0)=-inf */
if (hx<0) return (x-x)/zero; /* log(-#) = NaN */
k -= 54; x *= two54; /* subnormal number, scale up x */
GET_HIGH_WORD(hx,x);
}
if (hx >= 0x7ff00000) return x+x;
k += (hx>>20)-1023;
hx &= 0x000fffff;
i = (hx+0x95f64)&0x100000;
SET_HIGH_WORD(x,hx|(i^0x3ff00000)); /* normalize x or x/2 */
k += (i>>20);
f = x-1.0;
if((0x000fffff&(2+hx))<3) { /* |f| < 2**-20 */
if(f==zero) { if(k==0) return zero; else {dk=(double)k;
return dk*ln2_hi+dk*ln2_lo;}}
R = f*f*(0.5-0.33333333333333333*f);
if(k==0) return f-R; else {dk=(double)k;
return dk*ln2_hi-((R-dk*ln2_lo)-f);}
}
s = f/(2.0+f);
dk = (double)k;
z = s*s;
i = hx-0x6147a;
w = z*z;
j = 0x6b851-hx;
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=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);
}
}
 
#endif /* defined(_DOUBLE_IS_32BITS) */
/programs/develop/libraries/newlib/math/e_log10.c
0,0 → 1,98
 
/* @(#)e_log10.c 5.1 93/09/24 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
/* __ieee754_log10(x)
* Return the base 10 logarithm of x
*
* Method :
* Let log10_2hi = leading 40 bits of log10(2) and
* log10_2lo = log10(2) - log10_2hi,
* ivln10 = 1/log(10) rounded.
* Then
* n = ilogb(x),
* if(n<0) n = n+1;
* x = scalbn(x,-n);
* log10(x) := n*log10_2hi + (n*log10_2lo + ivln10*log(x))
*
* Note 1:
* To guarantee log10(10**n)=n, where 10**n is normal, the rounding
* mode must set to Round-to-Nearest.
* Note 2:
* [1/log(10)] rounded to 53 bits has error .198 ulps;
* log10 is monotonic at all binary break points.
*
* Special cases:
* log10(x) is NaN with signal if x < 0;
* log10(+INF) is +INF with no signal; log10(0) is -INF with signal;
* log10(NaN) is that NaN with no signal;
* log10(10**N) = N for N=0,1,...,22.
*
* Constants:
* The hexadecimal values are the intended ones for the following constants.
* The decimal values may be used, provided that the compiler will convert
* from decimal to binary accurately enough to produce the hexadecimal values
* shown.
*/
 
#include "fdlibm.h"
 
#ifndef _DOUBLE_IS_32BITS
 
#ifdef __STDC__
static const double
#else
static double
#endif
two54 = 1.80143985094819840000e+16, /* 0x43500000, 0x00000000 */
ivln10 = 4.34294481903251816668e-01, /* 0x3FDBCB7B, 0x1526E50E */
log10_2hi = 3.01029995663611771306e-01, /* 0x3FD34413, 0x509F6000 */
log10_2lo = 3.69423907715893078616e-13; /* 0x3D59FEF3, 0x11F12B36 */
 
#ifdef __STDC__
static const double zero = 0.0;
#else
static double zero = 0.0;
#endif
 
#ifdef __STDC__
double __ieee754_log10(double x)
#else
double __ieee754_log10(x)
double x;
#endif
{
double y,z;
__int32_t i,k,hx;
__uint32_t lx;
 
EXTRACT_WORDS(hx,lx,x);
 
k=0;
if (hx < 0x00100000) { /* x < 2**-1022 */
if (((hx&0x7fffffff)|lx)==0)
return -two54/zero; /* log(+-0)=-inf */
if (hx<0) return (x-x)/zero; /* log(-#) = NaN */
k -= 54; x *= two54; /* subnormal number, scale up x */
GET_HIGH_WORD(hx,x);
}
if (hx >= 0x7ff00000) return x+x;
k += (hx>>20)-1023;
i = ((__uint32_t)k&0x80000000)>>31;
hx = (hx&0x000fffff)|((0x3ff-i)<<20);
y = (double)(k+i);
SET_HIGH_WORD(x,hx);
z = y*log10_2lo + ivln10*__ieee754_log(x);
return z+y*log10_2hi;
}
 
#endif /* defined(_DOUBLE_IS_32BITS) */
/programs/develop/libraries/newlib/math/e_pow.c
0,0 → 1,315
 
/* @(#)e_pow.c 5.1 93/09/24 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
/* __ieee754_pow(x,y) return x**y
*
* n
* Method: Let x = 2 * (1+f)
* 1. Compute and return log2(x) in two pieces:
* log2(x) = w1 + w2,
* where w1 has 53-24 = 29 bit trailing zeros.
* 2. Perform y*log2(x) = n+y' by simulating multi-precision
* arithmetic, where |y'|<=0.5.
* 3. Return x**y = 2**n*exp(y'*log2)
*
* Special cases:
* 1. (anything) ** 0 is 1
* 2. (anything) ** 1 is itself
* 3a. (anything) ** NAN is NAN except
* 3b. +1 ** NAN is 1
* 4. NAN ** (anything except 0) is NAN
* 5. +-(|x| > 1) ** +INF is +INF
* 6. +-(|x| > 1) ** -INF is +0
* 7. +-(|x| < 1) ** +INF is +0
* 8. +-(|x| < 1) ** -INF is +INF
* 9. +-1 ** +-INF is 1
* 10. +0 ** (+anything except 0, NAN) is +0
* 11. -0 ** (+anything except 0, NAN, odd integer) is +0
* 12. +0 ** (-anything except 0, NAN) is +INF
* 13. -0 ** (-anything except 0, NAN, odd integer) is +INF
* 14. -0 ** (odd integer) = -( +0 ** (odd integer) )
* 15. +INF ** (+anything except 0,NAN) is +INF
* 16. +INF ** (-anything except 0,NAN) is +0
* 17. -INF ** (anything) = -0 ** (-anything)
* 18. (-anything) ** (integer) is (-1)**(integer)*(+anything**integer)
* 19. (-anything except 0 and inf) ** (non-integer) is NAN
*
* Accuracy:
* pow(x,y) returns x**y nearly rounded. In particular
* pow(integer,integer)
* always returns the correct integer provided it is
* representable.
*
* Constants :
* The hexadecimal values are the intended ones for the following
* constants. The decimal values may be used, provided that the
* compiler will convert from decimal to binary accurately enough
* to produce the hexadecimal values shown.
*/
 
#include "fdlibm.h"
 
#ifndef _DOUBLE_IS_32BITS
 
#ifdef __STDC__
static const double
#else
static double
#endif
bp[] = {1.0, 1.5,},
dp_h[] = { 0.0, 5.84962487220764160156e-01,}, /* 0x3FE2B803, 0x40000000 */
dp_l[] = { 0.0, 1.35003920212974897128e-08,}, /* 0x3E4CFDEB, 0x43CFD006 */
zero = 0.0,
one = 1.0,
two = 2.0,
two53 = 9007199254740992.0, /* 0x43400000, 0x00000000 */
huge = 1.0e300,
tiny = 1.0e-300,
/* poly coefs for (3/2)*(log(x)-2s-2/3*s**3 */
L1 = 5.99999999999994648725e-01, /* 0x3FE33333, 0x33333303 */
L2 = 4.28571428578550184252e-01, /* 0x3FDB6DB6, 0xDB6FABFF */
L3 = 3.33333329818377432918e-01, /* 0x3FD55555, 0x518F264D */
L4 = 2.72728123808534006489e-01, /* 0x3FD17460, 0xA91D4101 */
L5 = 2.30660745775561754067e-01, /* 0x3FCD864A, 0x93C9DB65 */
L6 = 2.06975017800338417784e-01, /* 0x3FCA7E28, 0x4A454EEF */
P1 = 1.66666666666666019037e-01, /* 0x3FC55555, 0x5555553E */
P2 = -2.77777777770155933842e-03, /* 0xBF66C16C, 0x16BEBD93 */
P3 = 6.61375632143793436117e-05, /* 0x3F11566A, 0xAF25DE2C */
P4 = -1.65339022054652515390e-06, /* 0xBEBBBD41, 0xC5D26BF1 */
P5 = 4.13813679705723846039e-08, /* 0x3E663769, 0x72BEA4D0 */
lg2 = 6.93147180559945286227e-01, /* 0x3FE62E42, 0xFEFA39EF */
lg2_h = 6.93147182464599609375e-01, /* 0x3FE62E43, 0x00000000 */
lg2_l = -1.90465429995776804525e-09, /* 0xBE205C61, 0x0CA86C39 */
ovt = 8.0085662595372944372e-0017, /* -(1024-log2(ovfl+.5ulp)) */
cp = 9.61796693925975554329e-01, /* 0x3FEEC709, 0xDC3A03FD =2/(3ln2) */
cp_h = 9.61796700954437255859e-01, /* 0x3FEEC709, 0xE0000000 =(float)cp */
cp_l = -7.02846165095275826516e-09, /* 0xBE3E2FE0, 0x145B01F5 =tail of cp_h*/
ivln2 = 1.44269504088896338700e+00, /* 0x3FF71547, 0x652B82FE =1/ln2 */
ivln2_h = 1.44269502162933349609e+00, /* 0x3FF71547, 0x60000000 =24b 1/ln2*/
ivln2_l = 1.92596299112661746887e-08; /* 0x3E54AE0B, 0xF85DDF44 =1/ln2 tail*/
 
#ifdef __STDC__
double __ieee754_pow(double x, double y)
#else
double __ieee754_pow(x,y)
double x, y;
#endif
{
double z,ax,z_h,z_l,p_h,p_l;
double y1,t1,t2,r,s,t,u,v,w;
__int32_t i,j,k,yisint,n;
__int32_t hx,hy,ix,iy;
__uint32_t lx,ly;
 
EXTRACT_WORDS(hx,lx,x);
EXTRACT_WORDS(hy,ly,y);
ix = hx&0x7fffffff; iy = hy&0x7fffffff;
 
/* y==zero: x**0 = 1 */
if((iy|ly)==0) return one;
 
/* x|y==NaN return NaN unless x==1 then return 1 */
if(ix > 0x7ff00000 || ((ix==0x7ff00000)&&(lx!=0)) ||
iy > 0x7ff00000 || ((iy==0x7ff00000)&&(ly!=0))) {
if(((ix-0x3ff00000)|lx)==0) return one;
else return nan("");
}
 
/* determine if y is an odd int when x < 0
* yisint = 0 ... y is not an integer
* yisint = 1 ... y is an odd int
* yisint = 2 ... y is an even int
*/
yisint = 0;
if(hx<0) {
if(iy>=0x43400000) yisint = 2; /* even integer y */
else if(iy>=0x3ff00000) {
k = (iy>>20)-0x3ff; /* exponent */
if(k>20) {
j = ly>>(52-k);
if((j<<(52-k))==ly) yisint = 2-(j&1);
} else if(ly==0) {
j = iy>>(20-k);
if((j<<(20-k))==iy) yisint = 2-(j&1);
}
}
}
 
/* special value of y */
if(ly==0) {
if (iy==0x7ff00000) { /* y is +-inf */
if(((ix-0x3ff00000)|lx)==0)
return one; /* +-1**+-inf = 1 */
else if (ix >= 0x3ff00000)/* (|x|>1)**+-inf = inf,0 */
return (hy>=0)? y: zero;
else /* (|x|<1)**-,+inf = inf,0 */
return (hy<0)?-y: zero;
}
if(iy==0x3ff00000) { /* y is +-1 */
if(hy<0) return one/x; else return x;
}
if(hy==0x40000000) return x*x; /* y is 2 */
if(hy==0x3fe00000) { /* y is 0.5 */
if(hx>=0) /* x >= +0 */
return __ieee754_sqrt(x);
}
}
 
ax = fabs(x);
/* special value of x */
if(lx==0) {
if(ix==0x7ff00000||ix==0||ix==0x3ff00000){
z = ax; /*x is +-0,+-inf,+-1*/
if(hy<0) z = one/z; /* z = (1/|x|) */
if(hx<0) {
if(((ix-0x3ff00000)|yisint)==0) {
z = (z-z)/(z-z); /* (-1)**non-int is NaN */
} else if(yisint==1)
z = -z; /* (x<0)**odd = -(|x|**odd) */
}
return z;
}
}
/* (x<0)**(non-int) is NaN */
/* REDHAT LOCAL: This used to be
if((((hx>>31)+1)|yisint)==0) return (x-x)/(x-x);
but ANSI C says a right shift of a signed negative quantity is
implementation defined. */
if(((((__uint32_t)hx>>31)-1)|yisint)==0) return (x-x)/(x-x);
 
/* |y| is huge */
if(iy>0x41e00000) { /* if |y| > 2**31 */
if(iy>0x43f00000){ /* if |y| > 2**64, must o/uflow */
if(ix<=0x3fefffff) return (hy<0)? huge*huge:tiny*tiny;
if(ix>=0x3ff00000) return (hy>0)? huge*huge:tiny*tiny;
}
/* over/underflow if x is not close to one */
if(ix<0x3fefffff) return (hy<0)? huge*huge:tiny*tiny;
if(ix>0x3ff00000) return (hy>0)? huge*huge:tiny*tiny;
/* now |1-x| is tiny <= 2**-20, suffice to compute
log(x) by x-x^2/2+x^3/3-x^4/4 */
t = ax-1; /* t has 20 trailing zeros */
w = (t*t)*(0.5-t*(0.3333333333333333333333-t*0.25));
u = ivln2_h*t; /* ivln2_h has 21 sig. bits */
v = t*ivln2_l-w*ivln2;
t1 = u+v;
SET_LOW_WORD(t1,0);
t2 = v-(t1-u);
} else {
double s2,s_h,s_l,t_h,t_l;
n = 0;
/* take care subnormal number */
if(ix<0x00100000)
{ax *= two53; n -= 53; GET_HIGH_WORD(ix,ax); }
n += ((ix)>>20)-0x3ff;
j = ix&0x000fffff;
/* determine interval */
ix = j|0x3ff00000; /* normalize ix */
if(j<=0x3988E) k=0; /* |x|<sqrt(3/2) */
else if(j<0xBB67A) k=1; /* |x|<sqrt(3) */
else {k=0;n+=1;ix -= 0x00100000;}
SET_HIGH_WORD(ax,ix);
 
/* compute s = s_h+s_l = (x-1)/(x+1) or (x-1.5)/(x+1.5) */
u = ax-bp[k]; /* bp[0]=1.0, bp[1]=1.5 */
v = one/(ax+bp[k]);
s = u*v;
s_h = s;
SET_LOW_WORD(s_h,0);
/* t_h=ax+bp[k] High */
t_h = zero;
SET_HIGH_WORD(t_h,((ix>>1)|0x20000000)+0x00080000+(k<<18));
t_l = ax - (t_h-bp[k]);
s_l = v*((u-s_h*t_h)-s_h*t_l);
/* compute log(ax) */
s2 = s*s;
r = s2*s2*(L1+s2*(L2+s2*(L3+s2*(L4+s2*(L5+s2*L6)))));
r += s_l*(s_h+s);
s2 = s_h*s_h;
t_h = 3.0+s2+r;
SET_LOW_WORD(t_h,0);
t_l = r-((t_h-3.0)-s2);
/* u+v = s*(1+...) */
u = s_h*t_h;
v = s_l*t_h+t_l*s;
/* 2/(3log2)*(s+...) */
p_h = u+v;
SET_LOW_WORD(p_h,0);
p_l = v-(p_h-u);
z_h = cp_h*p_h; /* cp_h+cp_l = 2/(3*log2) */
z_l = cp_l*p_h+p_l*cp+dp_l[k];
/* log2(ax) = (s+..)*2/(3*log2) = n + dp_h + z_h + z_l */
t = (double)n;
t1 = (((z_h+z_l)+dp_h[k])+t);
SET_LOW_WORD(t1,0);
t2 = z_l-(((t1-t)-dp_h[k])-z_h);
}
 
s = one; /* s (sign of result -ve**odd) = -1 else = 1 */
if(((((__uint32_t)hx>>31)-1)|(yisint-1))==0)
s = -one;/* (-ve)**(odd int) */
 
/* split up y into y1+y2 and compute (y1+y2)*(t1+t2) */
y1 = y;
SET_LOW_WORD(y1,0);
p_l = (y-y1)*t1+y*t2;
p_h = y1*t1;
z = p_l+p_h;
EXTRACT_WORDS(j,i,z);
if (j>=0x40900000) { /* z >= 1024 */
if(((j-0x40900000)|i)!=0) /* if z > 1024 */
return s*huge*huge; /* overflow */
else {
if(p_l+ovt>z-p_h) return s*huge*huge; /* overflow */
}
} else if((j&0x7fffffff)>=0x4090cc00 ) { /* z <= -1075 */
if(((j-0xc090cc00)|i)!=0) /* z < -1075 */
return s*tiny*tiny; /* underflow */
else {
if(p_l<=z-p_h) return s*tiny*tiny; /* underflow */
}
}
/*
* compute 2**(p_h+p_l)
*/
i = j&0x7fffffff;
k = (i>>20)-0x3ff;
n = 0;
if(i>0x3fe00000) { /* if |z| > 0.5, set n = [z+0.5] */
n = j+(0x00100000>>(k+1));
k = ((n&0x7fffffff)>>20)-0x3ff; /* new k for n */
t = zero;
SET_HIGH_WORD(t,n&~(0x000fffff>>k));
n = ((n&0x000fffff)|0x00100000)>>(20-k);
if(j<0) n = -n;
p_h -= t;
}
t = p_l+p_h;
SET_LOW_WORD(t,0);
u = t*lg2_h;
v = (p_l-(t-p_h))*lg2+t*lg2_l;
z = u+v;
w = v-(z-u);
t = z*z;
t1 = z - t*(P1+t*(P2+t*(P3+t*(P4+t*P5))));
r = (z*t1)/(t1-two)-(w+z*w);
z = one-(r-z);
GET_HIGH_WORD(j,z);
j += (n<<20);
if((j>>20)<=0) z = scalbn(z,(int)n); /* subnormal output */
else SET_HIGH_WORD(z,j);
return s*z;
}
 
#endif /* defined(_DOUBLE_IS_32BITS) */
/programs/develop/libraries/newlib/math/e_rem_pio2.c
0,0 → 1,185
 
/* @(#)e_rem_pio2.c 5.1 93/09/24 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*
*/
 
/* __ieee754_rem_pio2(x,y)
*
* return the remainder of x rem pi/2 in y[0]+y[1]
* use __kernel_rem_pio2()
*/
 
#include "fdlibm.h"
 
#ifndef _DOUBLE_IS_32BITS
 
/*
* Table of constants for 2/pi, 396 Hex digits (476 decimal) of 2/pi
*/
#ifdef __STDC__
static const __int32_t two_over_pi[] = {
#else
static __int32_t two_over_pi[] = {
#endif
0xA2F983, 0x6E4E44, 0x1529FC, 0x2757D1, 0xF534DD, 0xC0DB62,
0x95993C, 0x439041, 0xFE5163, 0xABDEBB, 0xC561B7, 0x246E3A,
0x424DD2, 0xE00649, 0x2EEA09, 0xD1921C, 0xFE1DEB, 0x1CB129,
0xA73EE8, 0x8235F5, 0x2EBB44, 0x84E99C, 0x7026B4, 0x5F7E41,
0x3991D6, 0x398353, 0x39F49C, 0x845F8B, 0xBDF928, 0x3B1FF8,
0x97FFDE, 0x05980F, 0xEF2F11, 0x8B5A0A, 0x6D1F6D, 0x367ECF,
0x27CB09, 0xB74F46, 0x3F669E, 0x5FEA2D, 0x7527BA, 0xC7EBE5,
0xF17B3D, 0x0739F7, 0x8A5292, 0xEA6BFB, 0x5FB11F, 0x8D5D08,
0x560330, 0x46FC7B, 0x6BABF0, 0xCFBC20, 0x9AF436, 0x1DA9E3,
0x91615E, 0xE61B08, 0x659985, 0x5F14A0, 0x68408D, 0xFFD880,
0x4D7327, 0x310606, 0x1556CA, 0x73A8C9, 0x60E27B, 0xC08C6B,
};
 
#ifdef __STDC__
static const __int32_t npio2_hw[] = {
#else
static __int32_t npio2_hw[] = {
#endif
0x3FF921FB, 0x400921FB, 0x4012D97C, 0x401921FB, 0x401F6A7A, 0x4022D97C,
0x4025FDBB, 0x402921FB, 0x402C463A, 0x402F6A7A, 0x4031475C, 0x4032D97C,
0x40346B9C, 0x4035FDBB, 0x40378FDB, 0x403921FB, 0x403AB41B, 0x403C463A,
0x403DD85A, 0x403F6A7A, 0x40407E4C, 0x4041475C, 0x4042106C, 0x4042D97C,
0x4043A28C, 0x40446B9C, 0x404534AC, 0x4045FDBB, 0x4046C6CB, 0x40478FDB,
0x404858EB, 0x404921FB,
};
 
/*
* invpio2: 53 bits of 2/pi
* pio2_1: first 33 bit of pi/2
* pio2_1t: pi/2 - pio2_1
* pio2_2: second 33 bit of pi/2
* pio2_2t: pi/2 - (pio2_1+pio2_2)
* pio2_3: third 33 bit of pi/2
* pio2_3t: pi/2 - (pio2_1+pio2_2+pio2_3)
*/
 
#ifdef __STDC__
static const double
#else
static double
#endif
zero = 0.00000000000000000000e+00, /* 0x00000000, 0x00000000 */
half = 5.00000000000000000000e-01, /* 0x3FE00000, 0x00000000 */
two24 = 1.67772160000000000000e+07, /* 0x41700000, 0x00000000 */
invpio2 = 6.36619772367581382433e-01, /* 0x3FE45F30, 0x6DC9C883 */
pio2_1 = 1.57079632673412561417e+00, /* 0x3FF921FB, 0x54400000 */
pio2_1t = 6.07710050650619224932e-11, /* 0x3DD0B461, 0x1A626331 */
pio2_2 = 6.07710050630396597660e-11, /* 0x3DD0B461, 0x1A600000 */
pio2_2t = 2.02226624879595063154e-21, /* 0x3BA3198A, 0x2E037073 */
pio2_3 = 2.02226624871116645580e-21, /* 0x3BA3198A, 0x2E000000 */
pio2_3t = 8.47842766036889956997e-32; /* 0x397B839A, 0x252049C1 */
 
#ifdef __STDC__
__int32_t __ieee754_rem_pio2(double x, double *y)
#else
__int32_t __ieee754_rem_pio2(x,y)
double x,y[];
#endif
{
double z = 0.0,w,t,r,fn;
double tx[3];
__int32_t i,j,n,ix,hx;
int e0,nx;
__uint32_t low;
 
GET_HIGH_WORD(hx,x); /* high word of x */
ix = hx&0x7fffffff;
if(ix<=0x3fe921fb) /* |x| ~<= pi/4 , no need for reduction */
{y[0] = x; y[1] = 0; return 0;}
if(ix<0x4002d97c) { /* |x| < 3pi/4, special case with n=+-1 */
if(hx>0) {
z = x - pio2_1;
if(ix!=0x3ff921fb) { /* 33+53 bit pi is good enough */
y[0] = z - pio2_1t;
y[1] = (z-y[0])-pio2_1t;
} else { /* near pi/2, use 33+33+53 bit pi */
z -= pio2_2;
y[0] = z - pio2_2t;
y[1] = (z-y[0])-pio2_2t;
}
return 1;
} else { /* negative x */
z = x + pio2_1;
if(ix!=0x3ff921fb) { /* 33+53 bit pi is good enough */
y[0] = z + pio2_1t;
y[1] = (z-y[0])+pio2_1t;
} else { /* near pi/2, use 33+33+53 bit pi */
z += pio2_2;
y[0] = z + pio2_2t;
y[1] = (z-y[0])+pio2_2t;
}
return -1;
}
}
if(ix<=0x413921fb) { /* |x| ~<= 2^19*(pi/2), medium size */
t = fabs(x);
n = (__int32_t) (t*invpio2+half);
fn = (double)n;
r = t-fn*pio2_1;
w = fn*pio2_1t; /* 1st round good to 85 bit */
if(n<32&&ix!=npio2_hw[n-1]) {
y[0] = r-w; /* quick check no cancellation */
} else {
__uint32_t high;
j = ix>>20;
y[0] = r-w;
GET_HIGH_WORD(high,y[0]);
i = j-((high>>20)&0x7ff);
if(i>16) { /* 2nd iteration needed, good to 118 */
t = r;
w = fn*pio2_2;
r = t-w;
w = fn*pio2_2t-((t-r)-w);
y[0] = r-w;
GET_HIGH_WORD(high,y[0]);
i = j-((high>>20)&0x7ff);
if(i>49) { /* 3rd iteration need, 151 bits acc */
t = r; /* will cover all possible cases */
w = fn*pio2_3;
r = t-w;
w = fn*pio2_3t-((t-r)-w);
y[0] = r-w;
}
}
}
y[1] = (r-y[0])-w;
if(hx<0) {y[0] = -y[0]; y[1] = -y[1]; return -n;}
else return n;
}
/*
* all other (large) arguments
*/
if(ix>=0x7ff00000) { /* x is inf or NaN */
y[0]=y[1]=x-x; return 0;
}
/* set z = scalbn(|x|,ilogb(x)-23) */
GET_LOW_WORD(low,x);
SET_LOW_WORD(z,low);
e0 = (int)((ix>>20)-1046); /* e0 = ilogb(z)-23; */
SET_HIGH_WORD(z, ix - ((__int32_t)e0<<20));
for(i=0;i<2;i++) {
tx[i] = (double)((__int32_t)(z));
z = (z-tx[i])*two24;
}
tx[2] = z;
nx = 3;
while(tx[nx-1]==zero) nx--; /* skip zero term */
n = __kernel_rem_pio2(tx,y,e0,nx,2,two_over_pi);
if(hx<0) {y[0] = -y[0]; y[1] = -y[1]; return -n;}
return n;
}
 
#endif /* defined(_DOUBLE_IS_32BITS) */
/programs/develop/libraries/newlib/math/e_remainder.c
0,0 → 1,80
 
/* @(#)e_remainder.c 5.1 93/09/24 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
/* __ieee754_remainder(x,p)
* Return :
* returns x REM p = x - [x/p]*p as if in infinite
* precise arithmetic, where [x/p] is the (infinite bit)
* integer nearest x/p (in half way case choose the even one).
* Method :
* Based on fmod() return x-[x/p]chopped*p exactlp.
*/
 
#include "fdlibm.h"
 
#ifndef _DOUBLE_IS_32BITS
 
#ifdef __STDC__
static const double zero = 0.0;
#else
static double zero = 0.0;
#endif
 
 
#ifdef __STDC__
double __ieee754_remainder(double x, double p)
#else
double __ieee754_remainder(x,p)
double x,p;
#endif
{
__int32_t hx,hp;
__uint32_t sx,lx,lp;
double p_half;
 
EXTRACT_WORDS(hx,lx,x);
EXTRACT_WORDS(hp,lp,p);
sx = hx&0x80000000;
hp &= 0x7fffffff;
hx &= 0x7fffffff;
 
/* purge off exception values */
if((hp|lp)==0) return (x*p)/(x*p); /* p = 0 */
if((hx>=0x7ff00000)|| /* x not finite */
((hp>=0x7ff00000)&& /* p is NaN */
(((hp-0x7ff00000)|lp)!=0)))
return (x*p)/(x*p);
 
 
if (hp<=0x7fdfffff) x = __ieee754_fmod(x,p+p); /* now x < 2p */
if (((hx-hp)|(lx-lp))==0) return zero*x;
x = fabs(x);
p = fabs(p);
if (hp<0x00200000) {
if(x+x>p) {
x-=p;
if(x+x>=p) x -= p;
}
} else {
p_half = 0.5*p;
if(x>p_half) {
x-=p;
if(x>=p_half) x -= p;
}
}
GET_HIGH_WORD(hx,x);
SET_HIGH_WORD(x,hx^sx);
return x;
}
 
#endif /* defined(_DOUBLE_IS_32BITS) */
/programs/develop/libraries/newlib/math/e_scalb.c
0,0 → 1,55
 
/* @(#)e_scalb.c 5.1 93/09/24 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
/*
* __ieee754_scalb(x, fn) is provide for
* passing various standard test suite. One
* should use scalbn() instead.
*/
 
#include "fdlibm.h"
 
#ifndef _DOUBLE_IS_32BITS
 
#ifdef _SCALB_INT
#ifdef __STDC__
double __ieee754_scalb(double x, int fn)
#else
double __ieee754_scalb(x,fn)
double x; int fn;
#endif
#else
#ifdef __STDC__
double __ieee754_scalb(double x, double fn)
#else
double __ieee754_scalb(x,fn)
double x, fn;
#endif
#endif
{
#ifdef _SCALB_INT
return scalbn(x,fn);
#else
if (isnan(x)||isnan(fn)) return x*fn;
if (!finite(fn)) {
if(fn>0.0) return x*fn;
else return x/(-fn);
}
if (rint(fn)!=fn) return (fn-fn)/(fn-fn);
if ( fn > 65000.0) return scalbn(x, 65000);
if (-fn > 65000.0) return scalbn(x,-65000);
return scalbn(x,(int)fn);
#endif
}
 
#endif /* defined(_DOUBLE_IS_32BITS) */
/programs/develop/libraries/newlib/math/e_sinh.c
31,6 → 31,8
 
#include "fdlibm.h"
 
#ifndef _DOUBLE_IS_32BITS
 
#ifdef __STDC__
static const double one = 1.0, shuge = 1.0e307;
#else
38,9 → 40,9
#endif
 
#ifdef __STDC__
double sinh(double x)
double __ieee754_sinh(double x)
#else
double sinh(x)
double __ieee754_sinh(x)
double x;
#endif
{
67,12 → 69,12
}
 
/* |x| in [22, log(maxdouble)] return 0.5*exp(|x|) */
if (ix < 0x40862E42) return h * exp(fabs(x));
if (ix < 0x40862E42) return h*__ieee754_exp(fabs(x));
 
/* |x| in [log(maxdouble), overflowthresold] */
GET_LOW_WORD(lx,x);
if (ix<0x408633CE || (ix==0x408633ce && lx<=(__uint32_t)0x8fb9f87d)) {
w = exp(0.5*fabs(x));
w = __ieee754_exp(0.5*fabs(x));
t = h*w;
return t*w;
}
81,3 → 83,4
return x*shuge;
}
 
#endif /* defined(_DOUBLE_IS_32BITS) */
/programs/develop/libraries/newlib/math/ef_acos.c
0,0 → 1,84
/* ef_acos.c -- float version of e_acos.c.
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
*/
 
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#include "fdlibm.h"
 
#ifdef __STDC__
static const float
#else
static float
#endif
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 */
 
#ifdef __STDC__
float __ieee754_acosf(float x)
#else
float __ieee754_acosf(x)
float x;
#endif
{
float z,p,q,r,w,s,c,df;
__int32_t 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 = __ieee754_sqrtf(z);
r = p/q;
w = r*s-pio2_lo;
return pi - (float)2.0*(s+w);
} else { /* x > 0.5 */
__int32_t idf;
z = (one-x)*(float)0.5;
s = __ieee754_sqrtf(z);
df = s;
GET_FLOAT_WORD(idf,df);
SET_FLOAT_WORD(df,idf&0xfffff000);
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);
}
}
/programs/develop/libraries/newlib/math/ef_acosh.c
0,0 → 1,53
/* ef_acosh.c -- float version of e_acosh.c.
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
*/
 
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*
*/
 
#include "fdlibm.h"
 
#ifdef __STDC__
static const float
#else
static float
#endif
one = 1.0,
ln2 = 6.9314718246e-01; /* 0x3f317218 */
 
#ifdef __STDC__
float __ieee754_acoshf(float x)
#else
float __ieee754_acoshf(x)
float x;
#endif
{
float t;
__int32_t hx;
GET_FLOAT_WORD(hx,x);
if(hx<0x3f800000) { /* x < 1 */
return (x-x)/(x-x);
} else if(hx >=0x4d800000) { /* x > 2**28 */
if(!FLT_UWORD_IS_FINITE(hx)) { /* x is inf of NaN */
return x+x;
} else
return __ieee754_logf(x)+ln2; /* acosh(huge)=log(2x) */
} else if (hx==0x3f800000) {
return 0.0; /* acosh(1) = 0 */
} else if (hx > 0x40000000) { /* 2**28 > x > 2 */
t=x*x;
return __ieee754_logf((float)2.0*x-one/(x+__ieee754_sqrtf(t-one)));
} else { /* 1<x<2 */
t = x-one;
return log1pf(t+__ieee754_sqrtf((float)2.0*t+t*t));
}
}
/programs/develop/libraries/newlib/math/ef_asin.c
0,0 → 1,88
/* ef_asin.c -- float version of e_asin.c.
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
*/
 
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#include "fdlibm.h"
 
#ifdef __STDC__
static const float
#else
static float
#endif
one = 1.0000000000e+00, /* 0x3F800000 */
huge = 1.000e+30,
pio2_hi = 1.57079637050628662109375f,
pio2_lo = -4.37113900018624283e-8f,
pio4_hi = 0.785398185253143310546875f,
/* 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 */
 
#ifdef __STDC__
float __ieee754_asinf(float x)
#else
float __ieee754_asinf(x)
float x;
#endif
{
float t,w,p,q,c,r,s;
__int32_t 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 = __ieee754_sqrtf(t);
if(ix>=0x3F79999A) { /* if |x| > 0.975 */
w = p/q;
t = pio2_hi-((float)2.0*(s+s*w)-pio2_lo);
} else {
__int32_t iw;
w = s;
GET_FLOAT_WORD(iw,w);
SET_FLOAT_WORD(w,iw&0xfffff000);
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;
}
/programs/develop/libraries/newlib/math/ef_atan2.c
0,0 → 1,101
/* ef_atan2.c -- float version of e_atan2.c.
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
*/
 
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*
*/
 
#include "fdlibm.h"
 
#ifdef __STDC__
static const float
#else
static float
#endif
tiny = 1.0e-30,
zero = 0.0,
pi_o_4 = 7.8539818525e-01, /* 0x3f490fdb */
pi_o_2 = 1.5707963705e+00, /* 0x3fc90fdb */
pi = 3.1415927410e+00, /* 0x40490fdb */
pi_lo = -8.7422776573e-08; /* 0xb3bbbd2e */
 
#ifdef __STDC__
float __ieee754_atan2f(float y, float x)
#else
float __ieee754_atan2f(y,x)
float y,x;
#endif
{
float z;
__int32_t k,m,hx,hy,ix,iy;
 
GET_FLOAT_WORD(hx,x);
ix = hx&0x7fffffff;
GET_FLOAT_WORD(hy,y);
iy = hy&0x7fffffff;
if(FLT_UWORD_IS_NAN(ix)||
FLT_UWORD_IS_NAN(iy)) /* 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(FLT_UWORD_IS_ZERO(iy)) {
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(FLT_UWORD_IS_ZERO(ix)) return (hy<0)? -pi_o_2-tiny: pi_o_2+tiny;
/* when x is INF */
if(FLT_UWORD_IS_INFINITE(ix)) {
if(FLT_UWORD_IS_INFINITE(iy)) {
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: return -zero ; /* atan(-...,+INF) */
case 2: return pi+tiny ; /* atan(+...,-INF) */
case 3: return -pi-tiny ; /* atan(-...,-INF) */
}
}
}
/* when y is INF */
if(FLT_UWORD_IS_INFINITE(iy)) 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 ^ 0x80000000);
}
return z ; /* atan(-,+) */
case 2: return pi-(z-pi_lo);/* atan(+,-) */
default: /* case 3 */
return (z-pi_lo)-pi;/* atan(-,-) */
}
}
/programs/develop/libraries/newlib/math/ef_atanh.c
0,0 → 1,54
/* ef_atanh.c -- float version of e_atanh.c.
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
*/
 
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*
*/
 
#include "fdlibm.h"
 
#ifdef __STDC__
static const float one = 1.0, huge = 1e30;
#else
static float one = 1.0, huge = 1e30;
#endif
 
#ifdef __STDC__
static const float zero = 0.0;
#else
static float zero = 0.0;
#endif
 
#ifdef __STDC__
float __ieee754_atanhf(float x)
#else
float __ieee754_atanhf(x)
float x;
#endif
{
float t;
__int32_t hx,ix;
GET_FLOAT_WORD(hx,x);
ix = hx&0x7fffffff;
if (ix>0x3f800000) /* |x|>1 */
return (x-x)/(x-x);
if(ix==0x3f800000)
return x/zero;
if(ix<0x31800000&&(huge+x)>zero) return x; /* x<2**-28 */
SET_FLOAT_WORD(x,ix);
if(ix<0x3f000000) { /* x < 0.5 */
t = x+x;
t = (float)0.5*log1pf(t+t*x/(one-x));
} else
t = (float)0.5*log1pf((x+x)/(one-x));
if(hx>=0) return t; else return -t;
}
/programs/develop/libraries/newlib/math/ef_cosh.c
0,0 → 1,71
/* ef_cosh.c -- float version of e_cosh.c.
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
*/
 
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#include "fdlibm.h"
 
#ifdef __v810__
#define const
#endif
 
#ifdef __STDC__
static const float one = 1.0, half=0.5, huge = 1.0e30;
#else
static float one = 1.0, half=0.5, huge = 1.0e30;
#endif
 
#ifdef __STDC__
float __ieee754_coshf(float x)
#else
float __ieee754_coshf(x)
float x;
#endif
{
float t,w;
__int32_t ix;
 
GET_FLOAT_WORD(ix,x);
ix &= 0x7fffffff;
 
/* x is INF or NaN */
if(!FLT_UWORD_IS_FINITE(ix)) return x*x;
 
/* |x| in [0,0.5*ln2], return 1+expm1(|x|)^2/(2*exp(|x|)) */
if(ix<0x3eb17218) {
t = expm1f(fabsf(x));
w = one+t;
if (ix<0x24000000) return w; /* cosh(tiny) = 1 */
return one+(t*t)/(w+w);
}
 
/* |x| in [0.5*ln2,22], return (exp(|x|)+1/exp(|x|)/2; */
if (ix < 0x41b00000) {
t = __ieee754_expf(fabsf(x));
return half*t+half/t;
}
 
/* |x| in [22, log(maxdouble)] return half*exp(|x|) */
if (ix <= FLT_UWORD_LOG_MAX)
return half*__ieee754_expf(fabsf(x));
 
/* |x| in [log(maxdouble), overflowthresold] */
if (ix <= FLT_UWORD_LOG_2MAX) {
w = __ieee754_expf(half*fabsf(x));
t = half*w;
return t*w;
}
 
/* |x| > overflowthresold, cosh(x) overflow */
return huge*huge;
}
/programs/develop/libraries/newlib/math/ef_exp.c
0,0 → 1,99
/* ef_exp.c -- float version of e_exp.c.
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
*/
 
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#include "fdlibm.h"
 
#ifdef __v810__
#define const
#endif
 
#ifdef __STDC__
static const float
#else
static float
#endif
one = 1.0,
halF[2] = {0.5,-0.5,},
huge = 1.0e+30,
twom100 = 7.8886090522e-31, /* 2**-100=0x0d800000 */
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 */
 
#ifdef __STDC__
float __ieee754_expf(float x) /* default IEEE double exp */
#else
float __ieee754_expf(x) /* default IEEE double exp */
float x;
#endif
{
float y,hi,lo,c,t;
__int32_t k = 0,xsb,sx;
__uint32_t hx;
 
GET_FLOAT_WORD(sx,x);
xsb = (sx>>31)&1; /* sign bit of x */
hx = sx & 0x7fffffff; /* high word of |x| */
 
/* filter out non-finite argument */
if(FLT_UWORD_IS_NAN(hx))
return x+x; /* NaN */
if(FLT_UWORD_IS_INFINITE(hx))
return (xsb==0)? x:0.0; /* exp(+-inf)={inf,0} */
if(sx > FLT_UWORD_LOG_MAX)
return huge*huge; /* overflow */
if(sx < 0 && hx > FLT_UWORD_LOG_MIN)
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 */
}
 
/* 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) {
__uint32_t hy;
GET_FLOAT_WORD(hy,y);
SET_FLOAT_WORD(y,hy+(k<<23)); /* add k to y's exponent */
return y;
} else {
__uint32_t hy;
GET_FLOAT_WORD(hy,y);
SET_FLOAT_WORD(y,hy+((k+100)<<23)); /* add k to y's exponent */
return y*twom100;
}
}
/programs/develop/libraries/newlib/math/ef_fmod.c
0,0 → 1,113
/* ef_fmod.c -- float version of e_fmod.c.
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
*/
 
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
/*
* __ieee754_fmodf(x,y)
* Return x mod y in exact arithmetic
* Method: shift and subtract
*/
 
#include "fdlibm.h"
 
#ifdef __STDC__
static const float one = 1.0, Zero[] = {0.0, -0.0,};
#else
static float one = 1.0, Zero[] = {0.0, -0.0,};
#endif
 
#ifdef __STDC__
float __ieee754_fmodf(float x, float y)
#else
float __ieee754_fmodf(x,y)
float x,y ;
#endif
{
__int32_t n,hx,hy,hz,ix,iy,sx,i;
 
GET_FLOAT_WORD(hx,x);
GET_FLOAT_WORD(hy,y);
sx = hx&0x80000000; /* sign of x */
hx ^=sx; /* |x| */
hy &= 0x7fffffff; /* |y| */
 
/* purge off exception values */
if(FLT_UWORD_IS_ZERO(hy)||
!FLT_UWORD_IS_FINITE(hx)||
FLT_UWORD_IS_NAN(hy))
return (x*y)/(x*y);
if(hx<hy) return x; /* |x|<|y| return x */
if(hx==hy)
return Zero[(__uint32_t)sx>>31]; /* |x|=|y| return x*0*/
 
/* Note: y cannot be zero if we reach here. */
 
/* determine ix = ilogb(x) */
if(FLT_UWORD_IS_SUBNORMAL(hx)) { /* subnormal x */
for (ix = -126,i=(hx<<8); i>0; i<<=1) ix -=1;
} else ix = (hx>>23)-127;
 
/* determine iy = ilogb(y) */
if(FLT_UWORD_IS_SUBNORMAL(hy)) { /* 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[(__uint32_t)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[(__uint32_t)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 */
/* If denormals are not supported, this code will generate a
zero representation. */
n = -126 - iy;
hx >>= n;
SET_FLOAT_WORD(x,hx|sx);
x *= one; /* create necessary signal */
}
return x; /* exact output */
}
/programs/develop/libraries/newlib/math/ef_hypot.c
0,0 → 1,83
/* ef_hypot.c -- float version of e_hypot.c.
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
*/
 
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#include "fdlibm.h"
 
#ifdef __STDC__
float __ieee754_hypotf(float x, float y)
#else
float __ieee754_hypotf(x,y)
float x, y;
#endif
{
float a=x,b=y,t1,t2,y1,y2,w;
__int32_t j,k,ha,hb;
 
GET_FLOAT_WORD(ha,x);
ha &= 0x7fffffffL;
GET_FLOAT_WORD(hb,y);
hb &= 0x7fffffffL;
if(hb > ha) {a=y;b=x;j=ha; ha=hb;hb=j;} else {a=x;b=y;}
SET_FLOAT_WORD(a,ha); /* a <- |a| */
SET_FLOAT_WORD(b,hb); /* b <- |b| */
if((ha-hb)>0xf000000L) {return a+b;} /* x/y > 2**30 */
k=0;
if(ha > 0x58800000L) { /* a>2**50 */
if(!FLT_UWORD_IS_FINITE(ha)) { /* Inf or NaN */
w = a+b; /* for sNaN */
if(FLT_UWORD_IS_INFINITE(ha)) w = a;
if(FLT_UWORD_IS_INFINITE(hb)) w = b;
return w;
}
/* scale a and b by 2**-68 */
ha -= 0x22000000L; hb -= 0x22000000L; k += 68;
SET_FLOAT_WORD(a,ha);
SET_FLOAT_WORD(b,hb);
}
if(hb < 0x26800000L) { /* b < 2**-50 */
if(FLT_UWORD_IS_ZERO(hb)) {
return a;
} else if(FLT_UWORD_IS_SUBNORMAL(hb)) {
SET_FLOAT_WORD(t1,0x7e800000L); /* t1=2^126 */
b *= t1;
a *= t1;
k -= 126;
} else { /* scale a and b by 2^68 */
ha += 0x22000000; /* a *= 2^68 */
hb += 0x22000000; /* b *= 2^68 */
k -= 68;
SET_FLOAT_WORD(a,ha);
SET_FLOAT_WORD(b,hb);
}
}
/* medium size a and b */
w = a-b;
if (w>b) {
SET_FLOAT_WORD(t1,ha&0xfffff000L);
t2 = a-t1;
w = __ieee754_sqrtf(t1*t1-(b*(-b)-t2*(a+t1)));
} else {
a = a+a;
SET_FLOAT_WORD(y1,hb&0xfffff000L);
y2 = b - y1;
SET_FLOAT_WORD(t1,ha+0x00800000L);
t2 = a - t1;
w = __ieee754_sqrtf(t1*y1-(w*(-w)-(t1*y2+t2*b)));
}
if(k!=0) {
SET_FLOAT_WORD(t1,0x3f800000L+(k<<23));
return t1*w;
} else return w;
}
/programs/develop/libraries/newlib/math/ef_j0.c
0,0 → 1,439
/* ef_j0.c -- float version of e_j0.c.
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
*/
 
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#include "fdlibm.h"
 
#ifdef __STDC__
static float pzerof(float), qzerof(float);
#else
static float pzerof(), qzerof();
#endif
 
#ifdef __STDC__
static const float
#else
static float
#endif
huge = 1e30,
one = 1.0,
invsqrtpi= 5.6418961287e-01, /* 0x3f106ebb */
tpi = 6.3661974669e-01, /* 0x3f22f983 */
/* R0/S0 on [0, 2.00] */
R02 = 1.5625000000e-02, /* 0x3c800000 */
R03 = -1.8997929874e-04, /* 0xb947352e */
R04 = 1.8295404516e-06, /* 0x35f58e88 */
R05 = -4.6183270541e-09, /* 0xb19eaf3c */
S01 = 1.5619102865e-02, /* 0x3c7fe744 */
S02 = 1.1692678527e-04, /* 0x38f53697 */
S03 = 5.1354652442e-07, /* 0x3509daa6 */
S04 = 1.1661400734e-09; /* 0x30a045e8 */
 
#ifdef __STDC__
static const float zero = 0.0;
#else
static float zero = 0.0;
#endif
 
#ifdef __STDC__
float __ieee754_j0f(float x)
#else
float __ieee754_j0f(x)
float x;
#endif
{
float z, s,c,ss,cc,r,u,v;
__int32_t hx,ix;
 
GET_FLOAT_WORD(hx,x);
ix = hx&0x7fffffff;
if(!FLT_UWORD_IS_FINITE(ix)) return one/(x*x);
x = fabsf(x);
if(ix >= 0x40000000) { /* |x| >= 2.0 */
s = sinf(x);
c = cosf(x);
ss = s-c;
cc = s+c;
if(ix<=FLT_UWORD_HALF_MAX) { /* make sure x+x not overflow */
z = -cosf(x+x);
if ((s*c)<zero) cc = z/ss;
else ss = z/cc;
}
/*
* j0(x) = 1/sqrt(pi) * (P(0,x)*cc - Q(0,x)*ss) / sqrt(x)
* y0(x) = 1/sqrt(pi) * (P(0,x)*ss + Q(0,x)*cc) / sqrt(x)
*/
if(ix>0x80000000) z = (invsqrtpi*cc)/__ieee754_sqrtf(x);
else {
u = pzerof(x); v = qzerof(x);
z = invsqrtpi*(u*cc-v*ss)/__ieee754_sqrtf(x);
}
return z;
}
if(ix<0x39000000) { /* |x| < 2**-13 */
if(huge+x>one) { /* raise inexact if x != 0 */
if(ix<0x32000000) return one; /* |x|<2**-27 */
else return one - (float)0.25*x*x;
}
}
z = x*x;
r = z*(R02+z*(R03+z*(R04+z*R05)));
s = one+z*(S01+z*(S02+z*(S03+z*S04)));
if(ix < 0x3F800000) { /* |x| < 1.00 */
return one + z*((float)-0.25+(r/s));
} else {
u = (float)0.5*x;
return((one+u)*(one-u)+z*(r/s));
}
}
 
#ifdef __STDC__
static const float
#else
static float
#endif
u00 = -7.3804296553e-02, /* 0xbd9726b5 */
u01 = 1.7666645348e-01, /* 0x3e34e80d */
u02 = -1.3818567619e-02, /* 0xbc626746 */
u03 = 3.4745343146e-04, /* 0x39b62a69 */
u04 = -3.8140706238e-06, /* 0xb67ff53c */
u05 = 1.9559013964e-08, /* 0x32a802ba */
u06 = -3.9820518410e-11, /* 0xae2f21eb */
v01 = 1.2730483897e-02, /* 0x3c509385 */
v02 = 7.6006865129e-05, /* 0x389f65e0 */
v03 = 2.5915085189e-07, /* 0x348b216c */
v04 = 4.4111031494e-10; /* 0x2ff280c2 */
 
#ifdef __STDC__
float __ieee754_y0f(float x)
#else
float __ieee754_y0f(x)
float x;
#endif
{
float z, s,c,ss,cc,u,v;
__int32_t hx,ix;
 
GET_FLOAT_WORD(hx,x);
ix = 0x7fffffff&hx;
/* Y0(NaN) is NaN, y0(-inf) is Nan, y0(inf) is 0 */
if(!FLT_UWORD_IS_FINITE(ix)) return one/(x+x*x);
if(FLT_UWORD_IS_ZERO(ix)) return -one/zero;
if(hx<0) return zero/zero;
if(ix >= 0x40000000) { /* |x| >= 2.0 */
/* y0(x) = sqrt(2/(pi*x))*(p0(x)*sin(x0)+q0(x)*cos(x0))
* where x0 = x-pi/4
* Better formula:
* cos(x0) = cos(x)cos(pi/4)+sin(x)sin(pi/4)
* = 1/sqrt(2) * (sin(x) + cos(x))
* sin(x0) = sin(x)cos(3pi/4)-cos(x)sin(3pi/4)
* = 1/sqrt(2) * (sin(x) - cos(x))
* To avoid cancellation, use
* sin(x) +- cos(x) = -cos(2x)/(sin(x) -+ cos(x))
* to compute the worse one.
*/
s = sinf(x);
c = cosf(x);
ss = s-c;
cc = s+c;
/*
* j0(x) = 1/sqrt(pi) * (P(0,x)*cc - Q(0,x)*ss) / sqrt(x)
* y0(x) = 1/sqrt(pi) * (P(0,x)*ss + Q(0,x)*cc) / sqrt(x)
*/
if(ix<=FLT_UWORD_HALF_MAX) { /* make sure x+x not overflow */
z = -cosf(x+x);
if ((s*c)<zero) cc = z/ss;
else ss = z/cc;
}
if(ix>0x80000000) z = (invsqrtpi*ss)/__ieee754_sqrtf(x);
else {
u = pzerof(x); v = qzerof(x);
z = invsqrtpi*(u*ss+v*cc)/__ieee754_sqrtf(x);
}
return z;
}
if(ix<=0x32000000) { /* x < 2**-27 */
return(u00 + tpi*__ieee754_logf(x));
}
z = x*x;
u = u00+z*(u01+z*(u02+z*(u03+z*(u04+z*(u05+z*u06)))));
v = one+z*(v01+z*(v02+z*(v03+z*v04)));
return(u/v + tpi*(__ieee754_j0f(x)*__ieee754_logf(x)));
}
 
/* The asymptotic expansions of pzero is
* 1 - 9/128 s^2 + 11025/98304 s^4 - ..., where s = 1/x.
* For x >= 2, We approximate pzero by
* pzero(x) = 1 + (R/S)
* where R = pR0 + pR1*s^2 + pR2*s^4 + ... + pR5*s^10
* S = 1 + pS0*s^2 + ... + pS4*s^10
* and
* | pzero(x)-1-R/S | <= 2 ** ( -60.26)
*/
#ifdef __STDC__
static const float pR8[6] = { /* for x in [inf, 8]=1/[0,0.125] */
#else
static float pR8[6] = { /* for x in [inf, 8]=1/[0,0.125] */
#endif
0.0000000000e+00, /* 0x00000000 */
-7.0312500000e-02, /* 0xbd900000 */
-8.0816707611e+00, /* 0xc1014e86 */
-2.5706311035e+02, /* 0xc3808814 */
-2.4852163086e+03, /* 0xc51b5376 */
-5.2530439453e+03, /* 0xc5a4285a */
};
#ifdef __STDC__
static const float pS8[5] = {
#else
static float pS8[5] = {
#endif
1.1653436279e+02, /* 0x42e91198 */
3.8337448730e+03, /* 0x456f9beb */
4.0597855469e+04, /* 0x471e95db */
1.1675296875e+05, /* 0x47e4087c */
4.7627726562e+04, /* 0x473a0bba */
};
#ifdef __STDC__
static const float pR5[6] = { /* for x in [8,4.5454]=1/[0.125,0.22001] */
#else
static float pR5[6] = { /* for x in [8,4.5454]=1/[0.125,0.22001] */
#endif
-1.1412546255e-11, /* 0xad48c58a */
-7.0312492549e-02, /* 0xbd8fffff */
-4.1596107483e+00, /* 0xc0851b88 */
-6.7674766541e+01, /* 0xc287597b */
-3.3123129272e+02, /* 0xc3a59d9b */
-3.4643338013e+02, /* 0xc3ad3779 */
};
#ifdef __STDC__
static const float pS5[5] = {
#else
static float pS5[5] = {
#endif
6.0753936768e+01, /* 0x42730408 */
1.0512523193e+03, /* 0x44836813 */
5.9789707031e+03, /* 0x45bad7c4 */
9.6254453125e+03, /* 0x461665c8 */
2.4060581055e+03, /* 0x451660ee */
};
 
#ifdef __STDC__
static const float pR3[6] = {/* for x in [4.547,2.8571]=1/[0.2199,0.35001] */
#else
static float pR3[6] = {/* for x in [4.547,2.8571]=1/[0.2199,0.35001] */
#endif
-2.5470459075e-09, /* 0xb12f081b */
-7.0311963558e-02, /* 0xbd8fffb8 */
-2.4090321064e+00, /* 0xc01a2d95 */
-2.1965976715e+01, /* 0xc1afba52 */
-5.8079170227e+01, /* 0xc2685112 */
-3.1447946548e+01, /* 0xc1fb9565 */
};
#ifdef __STDC__
static const float pS3[5] = {
#else
static float pS3[5] = {
#endif
3.5856033325e+01, /* 0x420f6c94 */
3.6151397705e+02, /* 0x43b4c1ca */
1.1936077881e+03, /* 0x44953373 */
1.1279968262e+03, /* 0x448cffe6 */
1.7358093262e+02, /* 0x432d94b8 */
};
 
#ifdef __STDC__
static const float pR2[6] = {/* for x in [2.8570,2]=1/[0.3499,0.5] */
#else
static float pR2[6] = {/* for x in [2.8570,2]=1/[0.3499,0.5] */
#endif
-8.8753431271e-08, /* 0xb3be98b7 */
-7.0303097367e-02, /* 0xbd8ffb12 */
-1.4507384300e+00, /* 0xbfb9b1cc */
-7.6356959343e+00, /* 0xc0f4579f */
-1.1193166733e+01, /* 0xc1331736 */
-3.2336456776e+00, /* 0xc04ef40d */
};
#ifdef __STDC__
static const float pS2[5] = {
#else
static float pS2[5] = {
#endif
2.2220300674e+01, /* 0x41b1c32d */
1.3620678711e+02, /* 0x430834f0 */
2.7047027588e+02, /* 0x43873c32 */
1.5387539673e+02, /* 0x4319e01a */
1.4657617569e+01, /* 0x416a859a */
};
 
#ifdef __STDC__
static float pzerof(float x)
#else
static float pzerof(x)
float x;
#endif
{
#ifdef __STDC__
const float *p,*q;
#else
float *p,*q;
#endif
float z,r,s;
__int32_t ix;
GET_FLOAT_WORD(ix,x);
ix &= 0x7fffffff;
if(ix>=0x41000000) {p = pR8; q= pS8;}
else if(ix>=0x40f71c58){p = pR5; q= pS5;}
else if(ix>=0x4036db68){p = pR3; q= pS3;}
else {p = pR2; q= pS2;}
z = one/(x*x);
r = p[0]+z*(p[1]+z*(p[2]+z*(p[3]+z*(p[4]+z*p[5]))));
s = one+z*(q[0]+z*(q[1]+z*(q[2]+z*(q[3]+z*q[4]))));
return one+ r/s;
}
 
/* For x >= 8, the asymptotic expansions of qzero is
* -1/8 s + 75/1024 s^3 - ..., where s = 1/x.
* We approximate qzero by
* qzero(x) = s*(-1.25 + (R/S))
* where R = qR0 + qR1*s^2 + qR2*s^4 + ... + qR5*s^10
* S = 1 + qS0*s^2 + ... + qS5*s^12
* and
* | qzero(x)/s +1.25-R/S | <= 2 ** ( -61.22)
*/
#ifdef __STDC__
static const float qR8[6] = { /* for x in [inf, 8]=1/[0,0.125] */
#else
static float qR8[6] = { /* for x in [inf, 8]=1/[0,0.125] */
#endif
0.0000000000e+00, /* 0x00000000 */
7.3242187500e-02, /* 0x3d960000 */
1.1768206596e+01, /* 0x413c4a93 */
5.5767340088e+02, /* 0x440b6b19 */
8.8591972656e+03, /* 0x460a6cca */
3.7014625000e+04, /* 0x471096a0 */
};
#ifdef __STDC__
static const float qS8[6] = {
#else
static float qS8[6] = {
#endif
1.6377603149e+02, /* 0x4323c6aa */
8.0983447266e+03, /* 0x45fd12c2 */
1.4253829688e+05, /* 0x480b3293 */
8.0330925000e+05, /* 0x49441ed4 */
8.4050156250e+05, /* 0x494d3359 */
-3.4389928125e+05, /* 0xc8a7eb69 */
};
 
#ifdef __STDC__
static const float qR5[6] = { /* for x in [8,4.5454]=1/[0.125,0.22001] */
#else
static float qR5[6] = { /* for x in [8,4.5454]=1/[0.125,0.22001] */
#endif
1.8408595828e-11, /* 0x2da1ec79 */
7.3242180049e-02, /* 0x3d95ffff */
5.8356351852e+00, /* 0x40babd86 */
1.3511157227e+02, /* 0x43071c90 */
1.0272437744e+03, /* 0x448067cd */
1.9899779053e+03, /* 0x44f8bf4b */
};
#ifdef __STDC__
static const float qS5[6] = {
#else
static float qS5[6] = {
#endif
8.2776611328e+01, /* 0x42a58da0 */
2.0778142090e+03, /* 0x4501dd07 */
1.8847289062e+04, /* 0x46933e94 */
5.6751113281e+04, /* 0x475daf1d */
3.5976753906e+04, /* 0x470c88c1 */
-5.3543427734e+03, /* 0xc5a752be */
};
 
#ifdef __STDC__
static const float qR3[6] = {/* for x in [4.547,2.8571]=1/[0.2199,0.35001] */
#else
static float qR3[6] = {/* for x in [4.547,2.8571]=1/[0.2199,0.35001] */
#endif
4.3774099900e-09, /* 0x3196681b */
7.3241114616e-02, /* 0x3d95ff70 */
3.3442313671e+00, /* 0x405607e3 */
4.2621845245e+01, /* 0x422a7cc5 */
1.7080809021e+02, /* 0x432acedf */
1.6673394775e+02, /* 0x4326bbe4 */
};
#ifdef __STDC__
static const float qS3[6] = {
#else
static float qS3[6] = {
#endif
4.8758872986e+01, /* 0x42430916 */
7.0968920898e+02, /* 0x44316c1c */
3.7041481934e+03, /* 0x4567825f */
6.4604252930e+03, /* 0x45c9e367 */
2.5163337402e+03, /* 0x451d4557 */
-1.4924745178e+02, /* 0xc3153f59 */
};
 
#ifdef __STDC__
static const float qR2[6] = {/* for x in [2.8570,2]=1/[0.3499,0.5] */
#else
static float qR2[6] = {/* for x in [2.8570,2]=1/[0.3499,0.5] */
#endif
1.5044444979e-07, /* 0x342189db */
7.3223426938e-02, /* 0x3d95f62a */
1.9981917143e+00, /* 0x3fffc4bf */
1.4495602608e+01, /* 0x4167edfd */
3.1666231155e+01, /* 0x41fd5471 */
1.6252708435e+01, /* 0x4182058c */
};
#ifdef __STDC__
static const float qS2[6] = {
#else
static float qS2[6] = {
#endif
3.0365585327e+01, /* 0x41f2ecb8 */
2.6934811401e+02, /* 0x4386ac8f */
8.4478375244e+02, /* 0x44533229 */
8.8293585205e+02, /* 0x445cbbe5 */
2.1266638184e+02, /* 0x4354aa98 */
-5.3109550476e+00, /* 0xc0a9f358 */
};
 
#ifdef __STDC__
static float qzerof(float x)
#else
static float qzerof(x)
float x;
#endif
{
#ifdef __STDC__
const float *p,*q;
#else
float *p,*q;
#endif
float s,r,z;
__int32_t ix;
GET_FLOAT_WORD(ix,x);
ix &= 0x7fffffff;
if(ix>=0x41000000) {p = qR8; q= qS8;}
else if(ix>=0x40f71c58){p = qR5; q= qS5;}
else if(ix>=0x4036db68){p = qR3; q= qS3;}
else {p = qR2; q= qS2;}
z = one/(x*x);
r = p[0]+z*(p[1]+z*(p[2]+z*(p[3]+z*(p[4]+z*p[5]))));
s = one+z*(q[0]+z*(q[1]+z*(q[2]+z*(q[3]+z*(q[4]+z*q[5])))));
return (-(float).125 + r/s)/x;
}
/programs/develop/libraries/newlib/math/ef_j1.c
0,0 → 1,439
/* ef_j1.c -- float version of e_j1.c.
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
*/
 
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#include "fdlibm.h"
 
#ifdef __STDC__
static float ponef(float), qonef(float);
#else
static float ponef(), qonef();
#endif
 
#ifdef __STDC__
static const float
#else
static float
#endif
huge = 1e30,
one = 1.0,
invsqrtpi= 5.6418961287e-01, /* 0x3f106ebb */
tpi = 6.3661974669e-01, /* 0x3f22f983 */
/* R0/S0 on [0,2] */
r00 = -6.2500000000e-02, /* 0xbd800000 */
r01 = 1.4070566976e-03, /* 0x3ab86cfd */
r02 = -1.5995563444e-05, /* 0xb7862e36 */
r03 = 4.9672799207e-08, /* 0x335557d2 */
s01 = 1.9153760746e-02, /* 0x3c9ce859 */
s02 = 1.8594678841e-04, /* 0x3942fab6 */
s03 = 1.1771846857e-06, /* 0x359dffc2 */
s04 = 5.0463624390e-09, /* 0x31ad6446 */
s05 = 1.2354227016e-11; /* 0x2d59567e */
 
#ifdef __STDC__
static const float zero = 0.0;
#else
static float zero = 0.0;
#endif
 
#ifdef __STDC__
float __ieee754_j1f(float x)
#else
float __ieee754_j1f(x)
float x;
#endif
{
float z, s,c,ss,cc,r,u,v,y;
__int32_t hx,ix;
 
GET_FLOAT_WORD(hx,x);
ix = hx&0x7fffffff;
if(!FLT_UWORD_IS_FINITE(ix)) return one/x;
y = fabsf(x);
if(ix >= 0x40000000) { /* |x| >= 2.0 */
s = sinf(y);
c = cosf(y);
ss = -s-c;
cc = s-c;
if(ix<=FLT_UWORD_HALF_MAX) { /* make sure y+y not overflow */
z = cosf(y+y);
if ((s*c)>zero) cc = z/ss;
else ss = z/cc;
}
/*
* j1(x) = 1/sqrt(pi) * (P(1,x)*cc - Q(1,x)*ss) / sqrt(x)
* y1(x) = 1/sqrt(pi) * (P(1,x)*ss + Q(1,x)*cc) / sqrt(x)
*/
if(ix>0x80000000) z = (invsqrtpi*cc)/__ieee754_sqrtf(y);
else {
u = ponef(y); v = qonef(y);
z = invsqrtpi*(u*cc-v*ss)/__ieee754_sqrtf(y);
}
if(hx<0) return -z;
else return z;
}
if(ix<0x32000000) { /* |x|<2**-27 */
if(huge+x>one) return (float)0.5*x;/* inexact if x!=0 necessary */
}
z = x*x;
r = z*(r00+z*(r01+z*(r02+z*r03)));
s = one+z*(s01+z*(s02+z*(s03+z*(s04+z*s05))));
r *= x;
return(x*(float)0.5+r/s);
}
 
#ifdef __STDC__
static const float U0[5] = {
#else
static float U0[5] = {
#endif
-1.9605709612e-01, /* 0xbe48c331 */
5.0443872809e-02, /* 0x3d4e9e3c */
-1.9125689287e-03, /* 0xbafaaf2a */
2.3525259166e-05, /* 0x37c5581c */
-9.1909917899e-08, /* 0xb3c56003 */
};
#ifdef __STDC__
static const float V0[5] = {
#else
static float V0[5] = {
#endif
1.9916731864e-02, /* 0x3ca3286a */
2.0255257550e-04, /* 0x3954644b */
1.3560879779e-06, /* 0x35b602d4 */
6.2274145840e-09, /* 0x31d5f8eb */
1.6655924903e-11, /* 0x2d9281cf */
};
 
#ifdef __STDC__
float __ieee754_y1f(float x)
#else
float __ieee754_y1f(x)
float x;
#endif
{
float z, s,c,ss,cc,u,v;
__int32_t hx,ix;
 
GET_FLOAT_WORD(hx,x);
ix = 0x7fffffff&hx;
/* if Y1(NaN) is NaN, Y1(-inf) is NaN, Y1(inf) is 0 */
if(!FLT_UWORD_IS_FINITE(ix)) return one/(x+x*x);
if(FLT_UWORD_IS_ZERO(ix)) return -one/zero;
if(hx<0) return zero/zero;
if(ix >= 0x40000000) { /* |x| >= 2.0 */
s = sinf(x);
c = cosf(x);
ss = -s-c;
cc = s-c;
if(ix<=FLT_UWORD_HALF_MAX) { /* make sure x+x not overflow */
z = cosf(x+x);
if ((s*c)>zero) cc = z/ss;
else ss = z/cc;
}
/* y1(x) = sqrt(2/(pi*x))*(p1(x)*sin(x0)+q1(x)*cos(x0))
* where x0 = x-3pi/4
* Better formula:
* cos(x0) = cos(x)cos(3pi/4)+sin(x)sin(3pi/4)
* = 1/sqrt(2) * (sin(x) - cos(x))
* sin(x0) = sin(x)cos(3pi/4)-cos(x)sin(3pi/4)
* = -1/sqrt(2) * (cos(x) + sin(x))
* To avoid cancellation, use
* sin(x) +- cos(x) = -cos(2x)/(sin(x) -+ cos(x))
* to compute the worse one.
*/
if(ix>0x48000000) z = (invsqrtpi*ss)/__ieee754_sqrtf(x);
else {
u = ponef(x); v = qonef(x);
z = invsqrtpi*(u*ss+v*cc)/__ieee754_sqrtf(x);
}
return z;
}
if(ix<=0x24800000) { /* x < 2**-54 */
return(-tpi/x);
}
z = x*x;
u = U0[0]+z*(U0[1]+z*(U0[2]+z*(U0[3]+z*U0[4])));
v = one+z*(V0[0]+z*(V0[1]+z*(V0[2]+z*(V0[3]+z*V0[4]))));
return(x*(u/v) + tpi*(__ieee754_j1f(x)*__ieee754_logf(x)-one/x));
}
 
/* For x >= 8, the asymptotic expansions of pone is
* 1 + 15/128 s^2 - 4725/2^15 s^4 - ..., where s = 1/x.
* We approximate pone by
* pone(x) = 1 + (R/S)
* where R = pr0 + pr1*s^2 + pr2*s^4 + ... + pr5*s^10
* S = 1 + ps0*s^2 + ... + ps4*s^10
* and
* | pone(x)-1-R/S | <= 2 ** ( -60.06)
*/
 
#ifdef __STDC__
static const float pr8[6] = { /* for x in [inf, 8]=1/[0,0.125] */
#else
static float pr8[6] = { /* for x in [inf, 8]=1/[0,0.125] */
#endif
0.0000000000e+00, /* 0x00000000 */
1.1718750000e-01, /* 0x3df00000 */
1.3239480972e+01, /* 0x4153d4ea */
4.1205184937e+02, /* 0x43ce06a3 */
3.8747453613e+03, /* 0x45722bed */
7.9144794922e+03, /* 0x45f753d6 */
};
#ifdef __STDC__
static const float ps8[5] = {
#else
static float ps8[5] = {
#endif
1.1420736694e+02, /* 0x42e46a2c */
3.6509309082e+03, /* 0x45642ee5 */
3.6956207031e+04, /* 0x47105c35 */
9.7602796875e+04, /* 0x47bea166 */
3.0804271484e+04, /* 0x46f0a88b */
};
 
#ifdef __STDC__
static const float pr5[6] = { /* for x in [8,4.5454]=1/[0.125,0.22001] */
#else
static float pr5[6] = { /* for x in [8,4.5454]=1/[0.125,0.22001] */
#endif
1.3199052094e-11, /* 0x2d68333f */
1.1718749255e-01, /* 0x3defffff */
6.8027510643e+00, /* 0x40d9b023 */
1.0830818176e+02, /* 0x42d89dca */
5.1763616943e+02, /* 0x440168b7 */
5.2871520996e+02, /* 0x44042dc6 */
};
#ifdef __STDC__
static const float ps5[5] = {
#else
static float ps5[5] = {
#endif
5.9280597687e+01, /* 0x426d1f55 */
9.9140142822e+02, /* 0x4477d9b1 */
5.3532670898e+03, /* 0x45a74a23 */
7.8446904297e+03, /* 0x45f52586 */
1.5040468750e+03, /* 0x44bc0180 */
};
 
#ifdef __STDC__
static const float pr3[6] = {
#else
static float pr3[6] = {/* for x in [4.547,2.8571]=1/[0.2199,0.35001] */
#endif
3.0250391081e-09, /* 0x314fe10d */
1.1718686670e-01, /* 0x3defffab */
3.9329774380e+00, /* 0x407bb5e7 */
3.5119403839e+01, /* 0x420c7a45 */
9.1055007935e+01, /* 0x42b61c2a */
4.8559066772e+01, /* 0x42423c7c */
};
#ifdef __STDC__
static const float ps3[5] = {
#else
static float ps3[5] = {
#endif
3.4791309357e+01, /* 0x420b2a4d */
3.3676245117e+02, /* 0x43a86198 */
1.0468714600e+03, /* 0x4482dbe3 */
8.9081134033e+02, /* 0x445eb3ed */
1.0378793335e+02, /* 0x42cf936c */
};
 
#ifdef __STDC__
static const float pr2[6] = {/* for x in [2.8570,2]=1/[0.3499,0.5] */
#else
static float pr2[6] = {/* for x in [2.8570,2]=1/[0.3499,0.5] */
#endif
1.0771083225e-07, /* 0x33e74ea8 */
1.1717621982e-01, /* 0x3deffa16 */
2.3685150146e+00, /* 0x401795c0 */
1.2242610931e+01, /* 0x4143e1bc */
1.7693971634e+01, /* 0x418d8d41 */
5.0735230446e+00, /* 0x40a25a4d */
};
#ifdef __STDC__
static const float ps2[5] = {
#else
static float ps2[5] = {
#endif
2.1436485291e+01, /* 0x41ab7dec */
1.2529022980e+02, /* 0x42fa9499 */
2.3227647400e+02, /* 0x436846c7 */
1.1767937469e+02, /* 0x42eb5bd7 */
8.3646392822e+00, /* 0x4105d590 */
};
 
#ifdef __STDC__
static float ponef(float x)
#else
static float ponef(x)
float x;
#endif
{
#ifdef __STDC__
const float *p,*q;
#else
float *p,*q;
#endif
float z,r,s;
__int32_t ix;
GET_FLOAT_WORD(ix,x);
ix &= 0x7fffffff;
if(ix>=0x41000000) {p = pr8; q= ps8;}
else if(ix>=0x40f71c58){p = pr5; q= ps5;}
else if(ix>=0x4036db68){p = pr3; q= ps3;}
else {p = pr2; q= ps2;}
z = one/(x*x);
r = p[0]+z*(p[1]+z*(p[2]+z*(p[3]+z*(p[4]+z*p[5]))));
s = one+z*(q[0]+z*(q[1]+z*(q[2]+z*(q[3]+z*q[4]))));
return one+ r/s;
}
 
/* For x >= 8, the asymptotic expansions of qone is
* 3/8 s - 105/1024 s^3 - ..., where s = 1/x.
* We approximate qone by
* qone(x) = s*(0.375 + (R/S))
* where R = qr1*s^2 + qr2*s^4 + ... + qr5*s^10
* S = 1 + qs1*s^2 + ... + qs6*s^12
* and
* | qone(x)/s -0.375-R/S | <= 2 ** ( -61.13)
*/
 
#ifdef __STDC__
static const float qr8[6] = { /* for x in [inf, 8]=1/[0,0.125] */
#else
static float qr8[6] = { /* for x in [inf, 8]=1/[0,0.125] */
#endif
0.0000000000e+00, /* 0x00000000 */
-1.0253906250e-01, /* 0xbdd20000 */
-1.6271753311e+01, /* 0xc1822c8d */
-7.5960174561e+02, /* 0xc43de683 */
-1.1849806641e+04, /* 0xc639273a */
-4.8438511719e+04, /* 0xc73d3683 */
};
#ifdef __STDC__
static const float qs8[6] = {
#else
static float qs8[6] = {
#endif
1.6139537048e+02, /* 0x43216537 */
7.8253862305e+03, /* 0x45f48b17 */
1.3387534375e+05, /* 0x4802bcd6 */
7.1965775000e+05, /* 0x492fb29c */
6.6660125000e+05, /* 0x4922be94 */
-2.9449025000e+05, /* 0xc88fcb48 */
};
 
#ifdef __STDC__
static const float qr5[6] = { /* for x in [8,4.5454]=1/[0.125,0.22001] */
#else
static float qr5[6] = { /* for x in [8,4.5454]=1/[0.125,0.22001] */
#endif
-2.0897993405e-11, /* 0xadb7d219 */
-1.0253904760e-01, /* 0xbdd1fffe */
-8.0564479828e+00, /* 0xc100e736 */
-1.8366960144e+02, /* 0xc337ab6b */
-1.3731937256e+03, /* 0xc4aba633 */
-2.6124443359e+03, /* 0xc523471c */
};
#ifdef __STDC__
static const float qs5[6] = {
#else
static float qs5[6] = {
#endif
8.1276550293e+01, /* 0x42a28d98 */
1.9917987061e+03, /* 0x44f8f98f */
1.7468484375e+04, /* 0x468878f8 */
4.9851425781e+04, /* 0x4742bb6d */
2.7948074219e+04, /* 0x46da5826 */
-4.7191835938e+03, /* 0xc5937978 */
};
 
#ifdef __STDC__
static const float qr3[6] = {
#else
static float qr3[6] = {/* for x in [4.547,2.8571]=1/[0.2199,0.35001] */
#endif
-5.0783124372e-09, /* 0xb1ae7d4f */
-1.0253783315e-01, /* 0xbdd1ff5b */
-4.6101160049e+00, /* 0xc0938612 */
-5.7847221375e+01, /* 0xc267638e */
-2.2824453735e+02, /* 0xc3643e9a */
-2.1921012878e+02, /* 0xc35b35cb */
};
#ifdef __STDC__
static const float qs3[6] = {
#else
static float qs3[6] = {
#endif
4.7665153503e+01, /* 0x423ea91e */
6.7386511230e+02, /* 0x4428775e */
3.3801528320e+03, /* 0x45534272 */
5.5477290039e+03, /* 0x45ad5dd5 */
1.9031191406e+03, /* 0x44ede3d0 */
-1.3520118713e+02, /* 0xc3073381 */
};
 
#ifdef __STDC__
static const float qr2[6] = {/* for x in [2.8570,2]=1/[0.3499,0.5] */
#else
static float qr2[6] = {/* for x in [2.8570,2]=1/[0.3499,0.5] */
#endif
-1.7838172539e-07, /* 0xb43f8932 */
-1.0251704603e-01, /* 0xbdd1f475 */
-2.7522056103e+00, /* 0xc0302423 */
-1.9663616180e+01, /* 0xc19d4f16 */
-4.2325313568e+01, /* 0xc2294d1f */
-2.1371921539e+01, /* 0xc1aaf9b2 */
};
#ifdef __STDC__
static const float qs2[6] = {
#else
static float qs2[6] = {
#endif
2.9533363342e+01, /* 0x41ec4454 */
2.5298155212e+02, /* 0x437cfb47 */
7.5750280762e+02, /* 0x443d602e */
7.3939318848e+02, /* 0x4438d92a */
1.5594900513e+02, /* 0x431bf2f2 */
-4.9594988823e+00, /* 0xc09eb437 */
};
 
#ifdef __STDC__
static float qonef(float x)
#else
static float qonef(x)
float x;
#endif
{
#ifdef __STDC__
const float *p,*q;
#else
float *p,*q;
#endif
float s,r,z;
__int32_t ix;
GET_FLOAT_WORD(ix,x);
ix &= 0x7fffffff;
if(ix>=0x40200000) {p = qr8; q= qs8;}
else if(ix>=0x40f71c58){p = qr5; q= qs5;}
else if(ix>=0x4036db68){p = qr3; q= qs3;}
else {p = qr2; q= qs2;}
z = one/(x*x);
r = p[0]+z*(p[1]+z*(p[2]+z*(p[3]+z*(p[4]+z*p[5]))));
s = one+z*(q[0]+z*(q[1]+z*(q[2]+z*(q[3]+z*(q[4]+z*q[5])))));
return ((float).375 + r/s)/x;
}
/programs/develop/libraries/newlib/math/ef_jn.c
0,0 → 1,207
/* ef_jn.c -- float version of e_jn.c.
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
*/
 
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#include "fdlibm.h"
 
#ifdef __STDC__
static const float
#else
static float
#endif
invsqrtpi= 5.6418961287e-01, /* 0x3f106ebb */
two = 2.0000000000e+00, /* 0x40000000 */
one = 1.0000000000e+00; /* 0x3F800000 */
 
#ifdef __STDC__
static const float zero = 0.0000000000e+00;
#else
static float zero = 0.0000000000e+00;
#endif
 
#ifdef __STDC__
float __ieee754_jnf(int n, float x)
#else
float __ieee754_jnf(n,x)
int n; float x;
#endif
{
__int32_t i,hx,ix, sgn;
float a, b, temp, di;
float z, w;
 
/* J(-n,x) = (-1)^n * J(n, x), J(n, -x) = (-1)^n * J(n, x)
* Thus, J(-n,x) = J(n,-x)
*/
GET_FLOAT_WORD(hx,x);
ix = 0x7fffffff&hx;
/* if J(n,NaN) is NaN */
if(FLT_UWORD_IS_NAN(ix)) return x+x;
if(n<0){
n = -n;
x = -x;
hx ^= 0x80000000;
}
if(n==0) return(__ieee754_j0f(x));
if(n==1) return(__ieee754_j1f(x));
sgn = (n&1)&(hx>>31); /* even n -- 0, odd n -- sign(x) */
x = fabsf(x);
if(FLT_UWORD_IS_ZERO(ix)||FLT_UWORD_IS_INFINITE(ix))
b = zero;
else if((float)n<=x) {
/* Safe to use J(n+1,x)=2n/x *J(n,x)-J(n-1,x) */
a = __ieee754_j0f(x);
b = __ieee754_j1f(x);
for(i=1;i<n;i++){
temp = b;
b = b*((float)(i+i)/x) - a; /* avoid underflow */
a = temp;
}
} else {
if(ix<0x30800000) { /* x < 2**-29 */
/* x is tiny, return the first Taylor expansion of J(n,x)
* J(n,x) = 1/n!*(x/2)^n - ...
*/
if(n>33) /* underflow */
b = zero;
else {
temp = x*(float)0.5; b = temp;
for (a=one,i=2;i<=n;i++) {
a *= (float)i; /* a = n! */
b *= temp; /* b = (x/2)^n */
}
b = b/a;
}
} else {
/* use backward recurrence */
/* x x^2 x^2
* J(n,x)/J(n-1,x) = ---- ------ ------ .....
* 2n - 2(n+1) - 2(n+2)
*
* 1 1 1
* (for large x) = ---- ------ ------ .....
* 2n 2(n+1) 2(n+2)
* -- - ------ - ------ -
* x x x
*
* Let w = 2n/x and h=2/x, then the above quotient
* is equal to the continued fraction:
* 1
* = -----------------------
* 1
* w - -----------------
* 1
* w+h - ---------
* w+2h - ...
*
* To determine how many terms needed, let
* Q(0) = w, Q(1) = w(w+h) - 1,
* Q(k) = (w+k*h)*Q(k-1) - Q(k-2),
* When Q(k) > 1e4 good for single
* When Q(k) > 1e9 good for double
* When Q(k) > 1e17 good for quadruple
*/
/* determine k */
float t,v;
float q0,q1,h,tmp; __int32_t k,m;
w = (n+n)/(float)x; h = (float)2.0/(float)x;
q0 = w; z = w+h; q1 = w*z - (float)1.0; k=1;
while(q1<(float)1.0e9) {
k += 1; z += h;
tmp = z*q1 - q0;
q0 = q1;
q1 = tmp;
}
m = n+n;
for(t=zero, i = 2*(n+k); i>=m; i -= 2) t = one/(i/x-t);
a = t;
b = one;
/* estimate log((2/x)^n*n!) = n*log(2/x)+n*ln(n)
* Hence, if n*(log(2n/x)) > ...
* single 8.8722839355e+01
* double 7.09782712893383973096e+02
* long double 1.1356523406294143949491931077970765006170e+04
* then recurrent value may overflow and the result is
* likely underflow to zero
*/
tmp = n;
v = two/x;
tmp = tmp*__ieee754_logf(fabsf(v*tmp));
if(tmp<(float)8.8721679688e+01) {
for(i=n-1,di=(float)(i+i);i>0;i--){
temp = b;
b *= di;
b = b/x - a;
a = temp;
di -= two;
}
} else {
for(i=n-1,di=(float)(i+i);i>0;i--){
temp = b;
b *= di;
b = b/x - a;
a = temp;
di -= two;
/* scale b to avoid spurious overflow */
if(b>(float)1e10) {
a /= b;
t /= b;
b = one;
}
}
}
b = (t*__ieee754_j0f(x)/b);
}
}
if(sgn==1) return -b; else return b;
}
 
#ifdef __STDC__
float __ieee754_ynf(int n, float x)
#else
float __ieee754_ynf(n,x)
int n; float x;
#endif
{
__int32_t i,hx,ix,ib;
__int32_t sign;
float a, b, temp;
 
GET_FLOAT_WORD(hx,x);
ix = 0x7fffffff&hx;
/* if Y(n,NaN) is NaN */
if(FLT_UWORD_IS_NAN(ix)) return x+x;
if(FLT_UWORD_IS_ZERO(ix)) return -one/zero;
if(hx<0) return zero/zero;
sign = 1;
if(n<0){
n = -n;
sign = 1 - ((n&1)<<1);
}
if(n==0) return(__ieee754_y0f(x));
if(n==1) return(sign*__ieee754_y1f(x));
if(FLT_UWORD_IS_INFINITE(ix)) return zero;
 
a = __ieee754_y0f(x);
b = __ieee754_y1f(x);
/* quit if b is -inf */
GET_FLOAT_WORD(ib,b);
for(i=1;i<n&&ib!=0xff800000;i++){
temp = b;
b = ((float)(i+i)/x)*b - a;
GET_FLOAT_WORD(ib,b);
a = temp;
}
if(sign>0) return b; else return -b;
}
/programs/develop/libraries/newlib/math/ef_log.c
0,0 → 1,92
/* ef_log.c -- float version of e_log.c.
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
*/
 
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#include "fdlibm.h"
 
#ifdef __STDC__
static const float
#else
static float
#endif
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 */
 
#ifdef __STDC__
static const float zero = 0.0;
#else
static float zero = 0.0;
#endif
 
#ifdef __STDC__
float __ieee754_logf(float x)
#else
float __ieee754_logf(x)
float x;
#endif
{
float hfsq,f,s,z,R,w,t1,t2,dk;
__int32_t k,ix,i,j;
 
GET_FLOAT_WORD(ix,x);
 
k=0;
if (FLT_UWORD_IS_ZERO(ix&0x7fffffff))
return -two25/zero; /* log(+-0)=-inf */
if (ix<0) return (x-x)/zero; /* log(-#) = NaN */
if (!FLT_UWORD_IS_FINITE(ix)) return x+x;
if (FLT_UWORD_IS_SUBNORMAL(ix)) {
k -= 25; x *= two25; /* subnormal number, scale up x */
GET_FLOAT_WORD(ix,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);
}
}
/programs/develop/libraries/newlib/math/ef_log10.c
0,0 → 1,62
/* ef_log10.c -- float version of e_log10.c.
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
*/
 
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#include "fdlibm.h"
 
#ifdef __STDC__
static const float
#else
static float
#endif
two25 = 3.3554432000e+07, /* 0x4c000000 */
ivln10 = 4.3429449201e-01, /* 0x3ede5bd9 */
log10_2hi = 3.0102920532e-01, /* 0x3e9a2080 */
log10_2lo = 7.9034151668e-07; /* 0x355427db */
 
#ifdef __STDC__
static const float zero = 0.0;
#else
static float zero = 0.0;
#endif
 
#ifdef __STDC__
float __ieee754_log10f(float x)
#else
float __ieee754_log10f(x)
float x;
#endif
{
float y,z;
__int32_t i,k,hx;
 
GET_FLOAT_WORD(hx,x);
 
k=0;
if (FLT_UWORD_IS_ZERO(hx&0x7fffffff))
return -two25/zero; /* log(+-0)=-inf */
if (hx<0) return (x-x)/zero; /* log(-#) = NaN */
if (!FLT_UWORD_IS_FINITE(hx)) return x+x;
if (FLT_UWORD_IS_SUBNORMAL(hx)) {
k -= 25; x *= two25; /* subnormal number, scale up x */
GET_FLOAT_WORD(hx,x);
}
k += (hx>>23)-127;
i = ((__uint32_t)k&0x80000000)>>31;
hx = (hx&0x007fffff)|((0x7f-i)<<23);
y = (float)(k+i);
SET_FLOAT_WORD(x,hx);
z = y*log10_2lo + ivln10*__ieee754_logf(x);
return z+y*log10_2hi;
}
/programs/develop/libraries/newlib/math/ef_pow.c
0,0 → 1,255
/* ef_pow.c -- float version of e_pow.c.
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
*/
 
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#include "fdlibm.h"
 
#ifdef __v810__
#define const
#endif
 
#ifdef __STDC__
static const float
#else
static float
#endif
bp[] = {1.0, 1.5,},
dp_h[] = { 0.0, 5.84960938e-01,}, /* 0x3f15c000 */
dp_l[] = { 0.0, 1.56322085e-06,}, /* 0x35d1cfdc */
zero = 0.0,
one = 1.0,
two = 2.0,
two24 = 16777216.0, /* 0x4b800000 */
huge = 1.0e30,
tiny = 1.0e-30,
/* poly coefs for (3/2)*(log(x)-2s-2/3*s**3 */
L1 = 6.0000002384e-01, /* 0x3f19999a */
L2 = 4.2857143283e-01, /* 0x3edb6db7 */
L3 = 3.3333334327e-01, /* 0x3eaaaaab */
L4 = 2.7272811532e-01, /* 0x3e8ba305 */
L5 = 2.3066075146e-01, /* 0x3e6c3255 */
L6 = 2.0697501302e-01, /* 0x3e53f142 */
P1 = 1.6666667163e-01, /* 0x3e2aaaab */
P2 = -2.7777778450e-03, /* 0xbb360b61 */
P3 = 6.6137559770e-05, /* 0x388ab355 */
P4 = -1.6533901999e-06, /* 0xb5ddea0e */
P5 = 4.1381369442e-08, /* 0x3331bb4c */
lg2 = 6.9314718246e-01, /* 0x3f317218 */
lg2_h = 6.93145752e-01, /* 0x3f317200 */
lg2_l = 1.42860654e-06, /* 0x35bfbe8c */
ovt = 4.2995665694e-08, /* -(128-log2(ovfl+.5ulp)) */
cp = 9.6179670095e-01, /* 0x3f76384f =2/(3ln2) */
cp_h = 9.6179199219e-01, /* 0x3f763800 =head of cp */
cp_l = 4.7017383622e-06, /* 0x369dc3a0 =tail of cp_h */
ivln2 = 1.4426950216e+00, /* 0x3fb8aa3b =1/ln2 */
ivln2_h = 1.4426879883e+00, /* 0x3fb8aa00 =16b 1/ln2*/
ivln2_l = 7.0526075433e-06; /* 0x36eca570 =1/ln2 tail*/
 
#ifdef __STDC__
float __ieee754_powf(float x, float y)
#else
float __ieee754_powf(x,y)
float x, y;
#endif
{
float z,ax,z_h,z_l,p_h,p_l;
float y1,t1,t2,r,s,t,u,v,w;
__int32_t i,j,k,yisint,n;
__int32_t hx,hy,ix,iy,is;
 
GET_FLOAT_WORD(hx,x);
GET_FLOAT_WORD(hy,y);
ix = hx&0x7fffffff; iy = hy&0x7fffffff;
 
/* y==zero: x**0 = 1 */
if(FLT_UWORD_IS_ZERO(iy)) return one;
 
/* x|y==NaN return NaN unless x==1 then return 1 */
if(FLT_UWORD_IS_NAN(ix) ||
FLT_UWORD_IS_NAN(iy)) {
if(ix==0x3f800000) return one;
else return nanf("");
}
 
/* determine if y is an odd int when x < 0
* yisint = 0 ... y is not an integer
* yisint = 1 ... y is an odd int
* yisint = 2 ... y is an even int
*/
yisint = 0;
if(hx<0) {
if(iy>=0x4b800000) yisint = 2; /* even integer y */
else if(iy>=0x3f800000) {
k = (iy>>23)-0x7f; /* exponent */
j = iy>>(23-k);
if((j<<(23-k))==iy) yisint = 2-(j&1);
}
}
 
/* special value of y */
if (FLT_UWORD_IS_INFINITE(iy)) { /* y is +-inf */
if (ix==0x3f800000)
return one; /* +-1**+-inf = 1 */
else if (ix > 0x3f800000)/* (|x|>1)**+-inf = inf,0 */
return (hy>=0)? y: zero;
else /* (|x|<1)**-,+inf = inf,0 */
return (hy<0)?-y: zero;
}
if(iy==0x3f800000) { /* y is +-1 */
if(hy<0) return one/x; else return x;
}
if(hy==0x40000000) return x*x; /* y is 2 */
if(hy==0x3f000000) { /* y is 0.5 */
if(hx>=0) /* x >= +0 */
return __ieee754_sqrtf(x);
}
 
ax = fabsf(x);
/* special value of x */
if(FLT_UWORD_IS_INFINITE(ix)||FLT_UWORD_IS_ZERO(ix)||ix==0x3f800000){
z = ax; /*x is +-0,+-inf,+-1*/
if(hy<0) z = one/z; /* z = (1/|x|) */
if(hx<0) {
if(((ix-0x3f800000)|yisint)==0) {
z = (z-z)/(z-z); /* (-1)**non-int is NaN */
} else if(yisint==1)
z = -z; /* (x<0)**odd = -(|x|**odd) */
}
return z;
}
/* (x<0)**(non-int) is NaN */
if(((((__uint32_t)hx>>31)-1)|yisint)==0) return (x-x)/(x-x);
 
/* |y| is huge */
if(iy>0x4d000000) { /* if |y| > 2**27 */
/* over/underflow if x is not close to one */
if(ix<0x3f7ffff8) return (hy<0)? huge*huge:tiny*tiny;
if(ix>0x3f800007) return (hy>0)? huge*huge:tiny*tiny;
/* now |1-x| is tiny <= 2**-20, suffice to compute
log(x) by x-x^2/2+x^3/3-x^4/4 */
t = ax-1; /* t has 20 trailing zeros */
w = (t*t)*((float)0.5-t*((float)0.333333333333-t*(float)0.25));
u = ivln2_h*t; /* ivln2_h has 16 sig. bits */
v = t*ivln2_l-w*ivln2;
t1 = u+v;
GET_FLOAT_WORD(is,t1);
SET_FLOAT_WORD(t1,is&0xfffff000);
t2 = v-(t1-u);
} else {
float s2,s_h,s_l,t_h,t_l;
n = 0;
/* take care subnormal number */
if(FLT_UWORD_IS_SUBNORMAL(ix))
{ax *= two24; n -= 24; GET_FLOAT_WORD(ix,ax); }
n += ((ix)>>23)-0x7f;
j = ix&0x007fffff;
/* determine interval */
ix = j|0x3f800000; /* normalize ix */
if(j<=0x1cc471) k=0; /* |x|<sqrt(3/2) */
else if(j<0x5db3d7) k=1; /* |x|<sqrt(3) */
else {k=0;n+=1;ix -= 0x00800000;}
SET_FLOAT_WORD(ax,ix);
 
/* compute s = s_h+s_l = (x-1)/(x+1) or (x-1.5)/(x+1.5) */
u = ax-bp[k]; /* bp[0]=1.0, bp[1]=1.5 */
v = one/(ax+bp[k]);
s = u*v;
s_h = s;
GET_FLOAT_WORD(is,s_h);
SET_FLOAT_WORD(s_h,is&0xfffff000);
/* t_h=ax+bp[k] High */
SET_FLOAT_WORD(t_h,((ix>>1)|0x20000000)+0x0040000+(k<<21));
t_l = ax - (t_h-bp[k]);
s_l = v*((u-s_h*t_h)-s_h*t_l);
/* compute log(ax) */
s2 = s*s;
r = s2*s2*(L1+s2*(L2+s2*(L3+s2*(L4+s2*(L5+s2*L6)))));
r += s_l*(s_h+s);
s2 = s_h*s_h;
t_h = (float)3.0+s2+r;
GET_FLOAT_WORD(is,t_h);
SET_FLOAT_WORD(t_h,is&0xfffff000);
t_l = r-((t_h-(float)3.0)-s2);
/* u+v = s*(1+...) */
u = s_h*t_h;
v = s_l*t_h+t_l*s;
/* 2/(3log2)*(s+...) */
p_h = u+v;
GET_FLOAT_WORD(is,p_h);
SET_FLOAT_WORD(p_h,is&0xfffff000);
p_l = v-(p_h-u);
z_h = cp_h*p_h; /* cp_h+cp_l = 2/(3*log2) */
z_l = cp_l*p_h+p_l*cp+dp_l[k];
/* log2(ax) = (s+..)*2/(3*log2) = n + dp_h + z_h + z_l */
t = (float)n;
t1 = (((z_h+z_l)+dp_h[k])+t);
GET_FLOAT_WORD(is,t1);
SET_FLOAT_WORD(t1,is&0xfffff000);
t2 = z_l-(((t1-t)-dp_h[k])-z_h);
}
 
s = one; /* s (sign of result -ve**odd) = -1 else = 1 */
if(((((__uint32_t)hx>>31)-1)|(yisint-1))==0)
s = -one; /* (-ve)**(odd int) */
 
/* split up y into y1+y2 and compute (y1+y2)*(t1+t2) */
GET_FLOAT_WORD(is,y);
SET_FLOAT_WORD(y1,is&0xfffff000);
p_l = (y-y1)*t1+y*t2;
p_h = y1*t1;
z = p_l+p_h;
GET_FLOAT_WORD(j,z);
i = j&0x7fffffff;
if (j>0) {
if (i>FLT_UWORD_EXP_MAX)
return s*huge*huge; /* overflow */
else if (i==FLT_UWORD_EXP_MAX)
if(p_l+ovt>z-p_h) return s*huge*huge; /* overflow */
} else {
if (i>FLT_UWORD_EXP_MIN)
return s*tiny*tiny; /* underflow */
else if (i==FLT_UWORD_EXP_MIN)
if(p_l<=z-p_h) return s*tiny*tiny; /* underflow */
}
/*
* compute 2**(p_h+p_l)
*/
k = (i>>23)-0x7f;
n = 0;
if(i>0x3f000000) { /* if |z| > 0.5, set n = [z+0.5] */
n = j+(0x00800000>>(k+1));
k = ((n&0x7fffffff)>>23)-0x7f; /* new k for n */
SET_FLOAT_WORD(t,n&~(0x007fffff>>k));
n = ((n&0x007fffff)|0x00800000)>>(23-k);
if(j<0) n = -n;
p_h -= t;
}
t = p_l+p_h;
GET_FLOAT_WORD(is,t);
SET_FLOAT_WORD(t,is&0xfffff000);
u = t*lg2_h;
v = (p_l-(t-p_h))*lg2+t*lg2_l;
z = u+v;
w = v-(z-u);
t = z*z;
t1 = z - t*(P1+t*(P2+t*(P3+t*(P4+t*P5))));
r = (z*t1)/(t1-two)-(w+z*w);
z = one-(r-z);
GET_FLOAT_WORD(j,z);
j += (n<<23);
if((j>>23)<=0) z = scalbnf(z,(int)n); /* subnormal output */
else SET_FLOAT_WORD(z,j);
return s*z;
}
/programs/develop/libraries/newlib/math/ef_rem_pio2.c
0,0 → 1,193
/* ef_rem_pio2.c -- float version of e_rem_pio2.c
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
*/
 
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*
*/
 
/* __ieee754_rem_pio2f(x,y)
*
* return the remainder of x rem pi/2 in y[0]+y[1]
* use __kernel_rem_pio2f()
*/
 
#include "fdlibm.h"
 
/*
* Table of constants for 2/pi, 396 Hex digits (476 decimal) of 2/pi
*/
#ifdef __STDC__
static const __int32_t two_over_pi[] = {
#else
static __int32_t two_over_pi[] = {
#endif
0xA2, 0xF9, 0x83, 0x6E, 0x4E, 0x44, 0x15, 0x29, 0xFC,
0x27, 0x57, 0xD1, 0xF5, 0x34, 0xDD, 0xC0, 0xDB, 0x62,
0x95, 0x99, 0x3C, 0x43, 0x90, 0x41, 0xFE, 0x51, 0x63,
0xAB, 0xDE, 0xBB, 0xC5, 0x61, 0xB7, 0x24, 0x6E, 0x3A,
0x42, 0x4D, 0xD2, 0xE0, 0x06, 0x49, 0x2E, 0xEA, 0x09,
0xD1, 0x92, 0x1C, 0xFE, 0x1D, 0xEB, 0x1C, 0xB1, 0x29,
0xA7, 0x3E, 0xE8, 0x82, 0x35, 0xF5, 0x2E, 0xBB, 0x44,
0x84, 0xE9, 0x9C, 0x70, 0x26, 0xB4, 0x5F, 0x7E, 0x41,
0x39, 0x91, 0xD6, 0x39, 0x83, 0x53, 0x39, 0xF4, 0x9C,
0x84, 0x5F, 0x8B, 0xBD, 0xF9, 0x28, 0x3B, 0x1F, 0xF8,
0x97, 0xFF, 0xDE, 0x05, 0x98, 0x0F, 0xEF, 0x2F, 0x11,
0x8B, 0x5A, 0x0A, 0x6D, 0x1F, 0x6D, 0x36, 0x7E, 0xCF,
0x27, 0xCB, 0x09, 0xB7, 0x4F, 0x46, 0x3F, 0x66, 0x9E,
0x5F, 0xEA, 0x2D, 0x75, 0x27, 0xBA, 0xC7, 0xEB, 0xE5,
0xF1, 0x7B, 0x3D, 0x07, 0x39, 0xF7, 0x8A, 0x52, 0x92,
0xEA, 0x6B, 0xFB, 0x5F, 0xB1, 0x1F, 0x8D, 0x5D, 0x08,
0x56, 0x03, 0x30, 0x46, 0xFC, 0x7B, 0x6B, 0xAB, 0xF0,
0xCF, 0xBC, 0x20, 0x9A, 0xF4, 0x36, 0x1D, 0xA9, 0xE3,
0x91, 0x61, 0x5E, 0xE6, 0x1B, 0x08, 0x65, 0x99, 0x85,
0x5F, 0x14, 0xA0, 0x68, 0x40, 0x8D, 0xFF, 0xD8, 0x80,
0x4D, 0x73, 0x27, 0x31, 0x06, 0x06, 0x15, 0x56, 0xCA,
0x73, 0xA8, 0xC9, 0x60, 0xE2, 0x7B, 0xC0, 0x8C, 0x6B,
};
 
/* This array is like the one in e_rem_pio2.c, but the numbers are
single precision and the last 8 bits are forced to 0. */
#ifdef __STDC__
static const __int32_t npio2_hw[] = {
#else
static __int32_t npio2_hw[] = {
#endif
0x3fc90f00, 0x40490f00, 0x4096cb00, 0x40c90f00, 0x40fb5300, 0x4116cb00,
0x412fed00, 0x41490f00, 0x41623100, 0x417b5300, 0x418a3a00, 0x4196cb00,
0x41a35c00, 0x41afed00, 0x41bc7e00, 0x41c90f00, 0x41d5a000, 0x41e23100,
0x41eec200, 0x41fb5300, 0x4203f200, 0x420a3a00, 0x42108300, 0x4216cb00,
0x421d1400, 0x42235c00, 0x4229a500, 0x422fed00, 0x42363600, 0x423c7e00,
0x4242c700, 0x42490f00
};
 
/*
* invpio2: 24 bits of 2/pi
* pio2_1: first 17 bit of pi/2
* pio2_1t: pi/2 - pio2_1
* pio2_2: second 17 bit of pi/2
* pio2_2t: pi/2 - (pio2_1+pio2_2)
* pio2_3: third 17 bit of pi/2
* pio2_3t: pi/2 - (pio2_1+pio2_2+pio2_3)
*/
 
#ifdef __STDC__
static const float
#else
static float
#endif
zero = 0.0000000000e+00, /* 0x00000000 */
half = 5.0000000000e-01, /* 0x3f000000 */
two8 = 2.5600000000e+02, /* 0x43800000 */
invpio2 = 6.3661980629e-01, /* 0x3f22f984 */
pio2_1 = 1.5707855225e+00, /* 0x3fc90f80 */
pio2_1t = 1.0804334124e-05, /* 0x37354443 */
pio2_2 = 1.0804273188e-05, /* 0x37354400 */
pio2_2t = 6.0770999344e-11, /* 0x2e85a308 */
pio2_3 = 6.0770943833e-11, /* 0x2e85a300 */
pio2_3t = 6.1232342629e-17; /* 0x248d3132 */
 
#ifdef __STDC__
__int32_t __ieee754_rem_pio2f(float x, float *y)
#else
__int32_t __ieee754_rem_pio2f(x,y)
float x,y[];
#endif
{
float z,w,t,r,fn;
float tx[3];
__int32_t i,j,n,ix,hx;
int e0,nx;
 
GET_FLOAT_WORD(hx,x);
ix = hx&0x7fffffff;
if(ix<=0x3f490fd8) /* |x| ~<= pi/4 , no need for reduction */
{y[0] = x; y[1] = 0; return 0;}
if(ix<0x4016cbe4) { /* |x| < 3pi/4, special case with n=+-1 */
if(hx>0) {
z = x - pio2_1;
if((ix&0xfffffff0)!=0x3fc90fd0) { /* 24+24 bit pi OK */
y[0] = z - pio2_1t;
y[1] = (z-y[0])-pio2_1t;
} else { /* near pi/2, use 24+24+24 bit pi */
z -= pio2_2;
y[0] = z - pio2_2t;
y[1] = (z-y[0])-pio2_2t;
}
return 1;
} else { /* negative x */
z = x + pio2_1;
if((ix&0xfffffff0)!=0x3fc90fd0) { /* 24+24 bit pi OK */
y[0] = z + pio2_1t;
y[1] = (z-y[0])+pio2_1t;
} else { /* near pi/2, use 24+24+24 bit pi */
z += pio2_2;
y[0] = z + pio2_2t;
y[1] = (z-y[0])+pio2_2t;
}
return -1;
}
}
if(ix<=0x43490f80) { /* |x| ~<= 2^7*(pi/2), medium size */
t = fabsf(x);
n = (__int32_t) (t*invpio2+half);
fn = (float)n;
r = t-fn*pio2_1;
w = fn*pio2_1t; /* 1st round good to 40 bit */
if(n<32&&(ix&0xffffff00)!=npio2_hw[n-1]) {
y[0] = r-w; /* quick check no cancellation */
} else {
__uint32_t high;
j = ix>>23;
y[0] = r-w;
GET_FLOAT_WORD(high,y[0]);
i = j-((high>>23)&0xff);
if(i>8) { /* 2nd iteration needed, good to 57 */
t = r;
w = fn*pio2_2;
r = t-w;
w = fn*pio2_2t-((t-r)-w);
y[0] = r-w;
GET_FLOAT_WORD(high,y[0]);
i = j-((high>>23)&0xff);
if(i>25) { /* 3rd iteration need, 74 bits acc */
t = r; /* will cover all possible cases */
w = fn*pio2_3;
r = t-w;
w = fn*pio2_3t-((t-r)-w);
y[0] = r-w;
}
}
}
y[1] = (r-y[0])-w;
if(hx<0) {y[0] = -y[0]; y[1] = -y[1]; return -n;}
else return n;
}
/*
* all other (large) arguments
*/
if(!FLT_UWORD_IS_FINITE(ix)) {
y[0]=y[1]=x-x; return 0;
}
/* set z = scalbn(|x|,ilogb(x)-7) */
e0 = (int)((ix>>23)-134); /* e0 = ilogb(z)-7; */
SET_FLOAT_WORD(z, ix - ((__int32_t)e0<<23));
for(i=0;i<2;i++) {
tx[i] = (float)((__int32_t)(z));
z = (z-tx[i])*two8;
}
tx[2] = z;
nx = 3;
while(tx[nx-1]==zero) nx--; /* skip zero term */
n = __kernel_rem_pio2f(tx,y,e0,nx,2,two_over_pi);
if(hx<0) {y[0] = -y[0]; y[1] = -y[1]; return -n;}
return n;
}
/programs/develop/libraries/newlib/math/ef_remainder.c
0,0 → 1,68
/* ef_remainder.c -- float version of e_remainder.c.
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
*/
 
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#include "fdlibm.h"
 
#ifdef __STDC__
static const float zero = 0.0;
#else
static float zero = 0.0;
#endif
 
 
#ifdef __STDC__
float __ieee754_remainderf(float x, float p)
#else
float __ieee754_remainderf(x,p)
float x,p;
#endif
{
__int32_t hx,hp;
__uint32_t sx;
float p_half;
 
GET_FLOAT_WORD(hx,x);
GET_FLOAT_WORD(hp,p);
sx = hx&0x80000000;
hp &= 0x7fffffff;
hx &= 0x7fffffff;
 
/* purge off exception values */
if(FLT_UWORD_IS_ZERO(hp)||
!FLT_UWORD_IS_FINITE(hx)||
FLT_UWORD_IS_NAN(hp))
return (x*p)/(x*p);
 
 
if (hp<=FLT_UWORD_HALF_MAX) x = __ieee754_fmodf(x,p+p); /* now x < 2p */
if ((hx-hp)==0) return zero*x;
x = fabsf(x);
p = fabsf(p);
if (hp<0x01000000) {
if(x+x>p) {
x-=p;
if(x+x>=p) x -= p;
}
} else {
p_half = (float)0.5*p;
if(x>p_half) {
x-=p;
if(x>=p_half) x -= p;
}
}
GET_FLOAT_WORD(hx,x);
SET_FLOAT_WORD(x,hx^sx);
return x;
}
/programs/develop/libraries/newlib/math/ef_scalb.c
0,0 → 1,53
/* ef_scalb.c -- float version of e_scalb.c.
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
*/
 
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#include "fdlibm.h"
#include <limits.h>
 
#ifdef _SCALB_INT
#ifdef __STDC__
float __ieee754_scalbf(float x, int fn)
#else
float __ieee754_scalbf(x,fn)
float x; int fn;
#endif
#else
#ifdef __STDC__
float __ieee754_scalbf(float x, float fn)
#else
float __ieee754_scalbf(x,fn)
float x, fn;
#endif
#endif
{
#ifdef _SCALB_INT
return scalbnf(x,fn);
#else
if (isnan(x)||isnan(fn)) return x*fn;
if (!finitef(fn)) {
if(fn>(float)0.0) return x*fn;
else return x/(-fn);
}
if (rintf(fn)!=fn) return (fn-fn)/(fn-fn);
#if INT_MAX > 65000
if ( fn > (float)65000.0) return scalbnf(x, 65000);
if (-fn > (float)65000.0) return scalbnf(x,-65000);
#else
if ( fn > (float)32000.0) return scalbnf(x, 32000);
if (-fn > (float)32000.0) return scalbnf(x,-32000);
#endif
return scalbnf(x,(int)fn);
#endif
}
/programs/develop/libraries/newlib/math/ef_sinh.c
0,0 → 1,63
/* ef_sinh.c -- float version of e_sinh.c.
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
*/
 
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#include "fdlibm.h"
 
#ifdef __STDC__
static const float one = 1.0, shuge = 1.0e37;
#else
static float one = 1.0, shuge = 1.0e37;
#endif
 
#ifdef __STDC__
float __ieee754_sinhf(float x)
#else
float __ieee754_sinhf(x)
float x;
#endif
{
float t,w,h;
__int32_t ix,jx;
 
GET_FLOAT_WORD(jx,x);
ix = jx&0x7fffffff;
 
/* x is INF or NaN */
if(!FLT_UWORD_IS_FINITE(ix)) return x+x;
 
h = 0.5;
if (jx<0) h = -h;
/* |x| in [0,22], return sign(x)*0.5*(E+E/(E+1))) */
if (ix < 0x41b00000) { /* |x|<22 */
if (ix<0x31800000) /* |x|<2**-28 */
if(shuge+x>one) return x;/* sinh(tiny) = tiny with inexact */
t = expm1f(fabsf(x));
if(ix<0x3f800000) return h*((float)2.0*t-t*t/(t+one));
return h*(t+t/(t+one));
}
 
/* |x| in [22, log(maxdouble)] return 0.5*exp(|x|) */
if (ix<=FLT_UWORD_LOG_MAX) return h*__ieee754_expf(fabsf(x));
 
/* |x| in [log(maxdouble), overflowthresold] */
if (ix<=FLT_UWORD_LOG_2MAX) {
w = __ieee754_expf((float)0.5*fabsf(x));
t = h*w;
return t*w;
}
 
/* |x| > overflowthresold, sinh(x) overflow */
return x*shuge;
}
/programs/develop/libraries/newlib/math/ef_sqrt.c
0,0 → 1,89
/* ef_sqrtf.c -- float version of e_sqrt.c.
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
*/
 
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#include "fdlibm.h"
 
#ifdef __STDC__
static const float one = 1.0, tiny=1.0e-30;
#else
static float one = 1.0, tiny=1.0e-30;
#endif
 
#ifdef __STDC__
float __ieee754_sqrtf(float x)
#else
float __ieee754_sqrtf(x)
float x;
#endif
{
float z;
__uint32_t r,hx;
__int32_t ix,s,q,m,t,i;
 
GET_FLOAT_WORD(ix,x);
hx = ix&0x7fffffff;
 
/* take care of Inf and NaN */
if(!FLT_UWORD_IS_FINITE(hx))
return x*x+x; /* sqrt(NaN)=NaN, sqrt(+inf)=+inf
sqrt(-inf)=sNaN */
/* take care of zero and -ves */
if(FLT_UWORD_IS_ZERO(hx)) return x;/* sqrt(+-0) = +-0 */
if(ix<0) return (x-x)/(x-x); /* sqrt(-ve) = sNaN */
 
/* normalize x */
m = (ix>>23);
if(FLT_UWORD_IS_SUBNORMAL(hx)) { /* subnormal x */
for(i=0;(ix&0x00800000L)==0;i++) ix<<=1;
m -= i-1;
}
m -= 127; /* unbias exponent */
ix = (ix&0x007fffffL)|0x00800000L;
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 = 0x01000000L; /* 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)+0x3f000000L;
ix += (m <<23);
SET_FLOAT_WORD(z,ix);
return z;
}
/programs/develop/libraries/newlib/math/er_gamma.c
0,0 → 1,32
 
/* @(#)er_gamma.c 5.1 93/09/24 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*
*/
 
/* __ieee754_gamma_r(x, signgamp)
* Reentrant version of the logarithm of the Gamma function
* with user provide pointer for the sign of Gamma(x).
*
* Method: See __ieee754_lgamma_r
*/
 
#include "fdlibm.h"
 
#ifdef __STDC__
double __ieee754_gamma_r(double x, int *signgamp)
#else
double __ieee754_gamma_r(x,signgamp)
double x; int *signgamp;
#endif
{
return __ieee754_exp (__ieee754_lgamma_r(x,signgamp));
}
/programs/develop/libraries/newlib/math/er_lgamma.c
0,0 → 1,309
 
/* @(#)er_lgamma.c 5.1 93/09/24 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*
*/
 
/* __ieee754_lgamma_r(x, signgamp)
* Reentrant version of the logarithm of the Gamma function
* with user provide pointer for the sign of Gamma(x).
*
* Method:
* 1. Argument Reduction for 0 < x <= 8
* Since gamma(1+s)=s*gamma(s), for x in [0,8], we may
* reduce x to a number in [1.5,2.5] by
* lgamma(1+s) = log(s) + lgamma(s)
* for example,
* lgamma(7.3) = log(6.3) + lgamma(6.3)
* = log(6.3*5.3) + lgamma(5.3)
* = log(6.3*5.3*4.3*3.3*2.3) + lgamma(2.3)
* 2. Polynomial approximation of lgamma around its
* minimun ymin=1.461632144968362245 to maintain monotonicity.
* On [ymin-0.23, ymin+0.27] (i.e., [1.23164,1.73163]), use
* Let z = x-ymin;
* lgamma(x) = -1.214862905358496078218 + z^2*poly(z)
* where
* poly(z) is a 14 degree polynomial.
* 2. Rational approximation in the primary interval [2,3]
* We use the following approximation:
* s = x-2.0;
* lgamma(x) = 0.5*s + s*P(s)/Q(s)
* with accuracy
* |P/Q - (lgamma(x)-0.5s)| < 2**-61.71
* Our algorithms are based on the following observation
*
* zeta(2)-1 2 zeta(3)-1 3
* lgamma(2+s) = s*(1-Euler) + --------- * s - --------- * s + ...
* 2 3
*
* where Euler = 0.5771... is the Euler constant, which is very
* close to 0.5.
*
* 3. For x>=8, we have
* lgamma(x)~(x-0.5)log(x)-x+0.5*log(2pi)+1/(12x)-1/(360x**3)+....
* (better formula:
* lgamma(x)~(x-0.5)*(log(x)-1)-.5*(log(2pi)-1) + ...)
* Let z = 1/x, then we approximation
* f(z) = lgamma(x) - (x-0.5)(log(x)-1)
* by
* 3 5 11
* w = w0 + w1*z + w2*z + w3*z + ... + w6*z
* where
* |w - f(z)| < 2**-58.74
*
* 4. For negative x, since (G is gamma function)
* -x*G(-x)*G(x) = pi/sin(pi*x),
* we have
* G(x) = pi/(sin(pi*x)*(-x)*G(-x))
* since G(-x) is positive, sign(G(x)) = sign(sin(pi*x)) for x<0
* Hence, for x<0, signgam = sign(sin(pi*x)) and
* lgamma(x) = log(|Gamma(x)|)
* = log(pi/(|x*sin(pi*x)|)) - lgamma(-x);
* Note: one should avoid compute pi*(-x) directly in the
* computation of sin(pi*(-x)).
*
* 5. Special Cases
* lgamma(2+s) ~ s*(1-Euler) for tiny s
* lgamma(1)=lgamma(2)=0
* lgamma(x) ~ -log(x) for tiny x
* lgamma(0) = lgamma(inf) = inf
* lgamma(-integer) = +-inf
*
*/
 
#include "fdlibm.h"
 
#ifdef __STDC__
static const double
#else
static double
#endif
two52= 4.50359962737049600000e+15, /* 0x43300000, 0x00000000 */
half= 5.00000000000000000000e-01, /* 0x3FE00000, 0x00000000 */
one = 1.00000000000000000000e+00, /* 0x3FF00000, 0x00000000 */
pi = 3.14159265358979311600e+00, /* 0x400921FB, 0x54442D18 */
a0 = 7.72156649015328655494e-02, /* 0x3FB3C467, 0xE37DB0C8 */
a1 = 3.22467033424113591611e-01, /* 0x3FD4A34C, 0xC4A60FAD */
a2 = 6.73523010531292681824e-02, /* 0x3FB13E00, 0x1A5562A7 */
a3 = 2.05808084325167332806e-02, /* 0x3F951322, 0xAC92547B */
a4 = 7.38555086081402883957e-03, /* 0x3F7E404F, 0xB68FEFE8 */
a5 = 2.89051383673415629091e-03, /* 0x3F67ADD8, 0xCCB7926B */
a6 = 1.19270763183362067845e-03, /* 0x3F538A94, 0x116F3F5D */
a7 = 5.10069792153511336608e-04, /* 0x3F40B6C6, 0x89B99C00 */
a8 = 2.20862790713908385557e-04, /* 0x3F2CF2EC, 0xED10E54D */
a9 = 1.08011567247583939954e-04, /* 0x3F1C5088, 0x987DFB07 */
a10 = 2.52144565451257326939e-05, /* 0x3EFA7074, 0x428CFA52 */
a11 = 4.48640949618915160150e-05, /* 0x3F07858E, 0x90A45837 */
tc = 1.46163214496836224576e+00, /* 0x3FF762D8, 0x6356BE3F */
tf = -1.21486290535849611461e-01, /* 0xBFBF19B9, 0xBCC38A42 */
/* tt = -(tail of tf) */
tt = -3.63867699703950536541e-18, /* 0xBC50C7CA, 0xA48A971F */
t0 = 4.83836122723810047042e-01, /* 0x3FDEF72B, 0xC8EE38A2 */
t1 = -1.47587722994593911752e-01, /* 0xBFC2E427, 0x8DC6C509 */
t2 = 6.46249402391333854778e-02, /* 0x3FB08B42, 0x94D5419B */
t3 = -3.27885410759859649565e-02, /* 0xBFA0C9A8, 0xDF35B713 */
t4 = 1.79706750811820387126e-02, /* 0x3F9266E7, 0x970AF9EC */
t5 = -1.03142241298341437450e-02, /* 0xBF851F9F, 0xBA91EC6A */
t6 = 6.10053870246291332635e-03, /* 0x3F78FCE0, 0xE370E344 */
t7 = -3.68452016781138256760e-03, /* 0xBF6E2EFF, 0xB3E914D7 */
t8 = 2.25964780900612472250e-03, /* 0x3F6282D3, 0x2E15C915 */
t9 = -1.40346469989232843813e-03, /* 0xBF56FE8E, 0xBF2D1AF1 */
t10 = 8.81081882437654011382e-04, /* 0x3F4CDF0C, 0xEF61A8E9 */
t11 = -5.38595305356740546715e-04, /* 0xBF41A610, 0x9C73E0EC */
t12 = 3.15632070903625950361e-04, /* 0x3F34AF6D, 0x6C0EBBF7 */
t13 = -3.12754168375120860518e-04, /* 0xBF347F24, 0xECC38C38 */
t14 = 3.35529192635519073543e-04, /* 0x3F35FD3E, 0xE8C2D3F4 */
u0 = -7.72156649015328655494e-02, /* 0xBFB3C467, 0xE37DB0C8 */
u1 = 6.32827064025093366517e-01, /* 0x3FE4401E, 0x8B005DFF */
u2 = 1.45492250137234768737e+00, /* 0x3FF7475C, 0xD119BD6F */
u3 = 9.77717527963372745603e-01, /* 0x3FEF4976, 0x44EA8450 */
u4 = 2.28963728064692451092e-01, /* 0x3FCD4EAE, 0xF6010924 */
u5 = 1.33810918536787660377e-02, /* 0x3F8B678B, 0xBF2BAB09 */
v1 = 2.45597793713041134822e+00, /* 0x4003A5D7, 0xC2BD619C */
v2 = 2.12848976379893395361e+00, /* 0x40010725, 0xA42B18F5 */
v3 = 7.69285150456672783825e-01, /* 0x3FE89DFB, 0xE45050AF */
v4 = 1.04222645593369134254e-01, /* 0x3FBAAE55, 0xD6537C88 */
v5 = 3.21709242282423911810e-03, /* 0x3F6A5ABB, 0x57D0CF61 */
s0 = -7.72156649015328655494e-02, /* 0xBFB3C467, 0xE37DB0C8 */
s1 = 2.14982415960608852501e-01, /* 0x3FCB848B, 0x36E20878 */
s2 = 3.25778796408930981787e-01, /* 0x3FD4D98F, 0x4F139F59 */
s3 = 1.46350472652464452805e-01, /* 0x3FC2BB9C, 0xBEE5F2F7 */
s4 = 2.66422703033638609560e-02, /* 0x3F9B481C, 0x7E939961 */
s5 = 1.84028451407337715652e-03, /* 0x3F5E26B6, 0x7368F239 */
s6 = 3.19475326584100867617e-05, /* 0x3F00BFEC, 0xDD17E945 */
r1 = 1.39200533467621045958e+00, /* 0x3FF645A7, 0x62C4AB74 */
r2 = 7.21935547567138069525e-01, /* 0x3FE71A18, 0x93D3DCDC */
r3 = 1.71933865632803078993e-01, /* 0x3FC601ED, 0xCCFBDF27 */
r4 = 1.86459191715652901344e-02, /* 0x3F9317EA, 0x742ED475 */
r5 = 7.77942496381893596434e-04, /* 0x3F497DDA, 0xCA41A95B */
r6 = 7.32668430744625636189e-06, /* 0x3EDEBAF7, 0xA5B38140 */
w0 = 4.18938533204672725052e-01, /* 0x3FDACFE3, 0x90C97D69 */
w1 = 8.33333333333329678849e-02, /* 0x3FB55555, 0x5555553B */
w2 = -2.77777777728775536470e-03, /* 0xBF66C16C, 0x16B02E5C */
w3 = 7.93650558643019558500e-04, /* 0x3F4A019F, 0x98CF38B6 */
w4 = -5.95187557450339963135e-04, /* 0xBF4380CB, 0x8C0FE741 */
w5 = 8.36339918996282139126e-04, /* 0x3F4B67BA, 0x4CDAD5D1 */
w6 = -1.63092934096575273989e-03; /* 0xBF5AB89D, 0x0B9E43E4 */
 
#ifdef __STDC__
static const double zero= 0.00000000000000000000e+00;
#else
static double zero= 0.00000000000000000000e+00;
#endif
 
#ifdef __STDC__
static double sin_pi(double x)
#else
static double sin_pi(x)
double x;
#endif
{
double y,z;
__int32_t n,ix;
 
GET_HIGH_WORD(ix,x);
ix &= 0x7fffffff;
 
if(ix<0x3fd00000) return __kernel_sin(pi*x,zero,0);
y = -x; /* x is assume negative */
 
/*
* argument reduction, make sure inexact flag not raised if input
* is an integer
*/
z = floor(y);
if(z!=y) { /* inexact anyway */
y *= 0.5;
y = 2.0*(y - floor(y)); /* y = |x| mod 2.0 */
n = (__int32_t) (y*4.0);
} else {
if(ix>=0x43400000) {
y = zero; n = 0; /* y must be even */
} else {
if(ix<0x43300000) z = y+two52; /* exact */
GET_LOW_WORD(n,z);
n &= 1;
y = n;
n<<= 2;
}
}
switch (n) {
case 0: y = __kernel_sin(pi*y,zero,0); break;
case 1:
case 2: y = __kernel_cos(pi*(0.5-y),zero); break;
case 3:
case 4: y = __kernel_sin(pi*(one-y),zero,0); break;
case 5:
case 6: y = -__kernel_cos(pi*(y-1.5),zero); break;
default: y = __kernel_sin(pi*(y-2.0),zero,0); break;
}
return -y;
}
 
 
#ifdef __STDC__
double __ieee754_lgamma_r(double x, int *signgamp)
#else
double __ieee754_lgamma_r(x,signgamp)
double x; int *signgamp;
#endif
{
double t,y,z,nadj = 0.0,p,p1,p2,p3,q,r,w;
__int32_t i,hx,lx,ix;
 
EXTRACT_WORDS(hx,lx,x);
 
/* purge off +-inf, NaN, +-0, and negative arguments */
*signgamp = 1;
ix = hx&0x7fffffff;
if(ix>=0x7ff00000) return x*x;
if((ix|lx)==0) return one/zero;
if(ix<0x3b900000) { /* |x|<2**-70, return -log(|x|) */
if(hx<0) {
*signgamp = -1;
return -__ieee754_log(-x);
} else return -__ieee754_log(x);
}
if(hx<0) {
if(ix>=0x43300000) /* |x|>=2**52, must be -integer */
return one/zero;
t = sin_pi(x);
if(t==zero) return one/zero; /* -integer */
nadj = __ieee754_log(pi/fabs(t*x));
if(t<zero) *signgamp = -1;
x = -x;
}
 
/* purge off 1 and 2 */
if((((ix-0x3ff00000)|lx)==0)||(((ix-0x40000000)|lx)==0)) r = 0;
/* for x < 2.0 */
else if(ix<0x40000000) {
if(ix<=0x3feccccc) { /* lgamma(x) = lgamma(x+1)-log(x) */
r = -__ieee754_log(x);
if(ix>=0x3FE76944) {y = one-x; i= 0;}
else if(ix>=0x3FCDA661) {y= x-(tc-one); i=1;}
else {y = x; i=2;}
} else {
r = zero;
if(ix>=0x3FFBB4C3) {y=2.0-x;i=0;} /* [1.7316,2] */
else if(ix>=0x3FF3B4C4) {y=x-tc;i=1;} /* [1.23,1.73] */
else {y=x-one;i=2;}
}
switch(i) {
case 0:
z = y*y;
p1 = a0+z*(a2+z*(a4+z*(a6+z*(a8+z*a10))));
p2 = z*(a1+z*(a3+z*(a5+z*(a7+z*(a9+z*a11)))));
p = y*p1+p2;
r += (p-0.5*y); break;
case 1:
z = y*y;
w = z*y;
p1 = t0+w*(t3+w*(t6+w*(t9 +w*t12))); /* parallel comp */
p2 = t1+w*(t4+w*(t7+w*(t10+w*t13)));
p3 = t2+w*(t5+w*(t8+w*(t11+w*t14)));
p = z*p1-(tt-w*(p2+y*p3));
r += (tf + p); break;
case 2:
p1 = y*(u0+y*(u1+y*(u2+y*(u3+y*(u4+y*u5)))));
p2 = one+y*(v1+y*(v2+y*(v3+y*(v4+y*v5))));
r += (-0.5*y + p1/p2);
}
}
else if(ix<0x40200000) { /* x < 8.0 */
i = (__int32_t)x;
t = zero;
y = x-(double)i;
p = y*(s0+y*(s1+y*(s2+y*(s3+y*(s4+y*(s5+y*s6))))));
q = one+y*(r1+y*(r2+y*(r3+y*(r4+y*(r5+y*r6)))));
r = half*y+p/q;
z = one; /* lgamma(1+s) = log(s) + lgamma(s) */
switch(i) {
case 7: z *= (y+6.0); /* FALLTHRU */
case 6: z *= (y+5.0); /* FALLTHRU */
case 5: z *= (y+4.0); /* FALLTHRU */
case 4: z *= (y+3.0); /* FALLTHRU */
case 3: z *= (y+2.0); /* FALLTHRU */
r += __ieee754_log(z); break;
}
/* 8.0 <= x < 2**58 */
} else if (ix < 0x43900000) {
t = __ieee754_log(x);
z = one/x;
y = z*z;
w = w0+z*(w1+y*(w2+y*(w3+y*(w4+y*(w5+y*w6)))));
r = (x-half)*(t-one)+w;
} else
/* 2**58 <= x <= inf */
r = x*(__ieee754_log(x)-one);
if(hx<0) r = nadj - r;
return r;
}
/programs/develop/libraries/newlib/math/erf_gamma.c
0,0 → 1,34
/* erf_gamma.c -- float version of er_gamma.c.
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
*/
 
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*
*/
 
/* __ieee754_gammaf_r(x, signgamp)
* Reentrant version of the logarithm of the Gamma function
* with user provide pointer for the sign of Gamma(x).
*
* Method: See __ieee754_lgammaf_r
*/
 
#include "fdlibm.h"
 
#ifdef __STDC__
float __ieee754_gammaf_r(float x, int *signgamp)
#else
float __ieee754_gammaf_r(x,signgamp)
float x; int *signgamp;
#endif
{
return __ieee754_expf (__ieee754_lgammaf_r(x,signgamp));
}
/programs/develop/libraries/newlib/math/erf_lgamma.c
0,0 → 1,244
/* erf_lgamma.c -- float version of er_lgamma.c.
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
*/
 
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*
*/
 
#include "fdlibm.h"
 
#ifdef __STDC__
static const float
#else
static float
#endif
two23= 8.3886080000e+06, /* 0x4b000000 */
half= 5.0000000000e-01, /* 0x3f000000 */
one = 1.0000000000e+00, /* 0x3f800000 */
pi = 3.1415927410e+00, /* 0x40490fdb */
a0 = 7.7215664089e-02, /* 0x3d9e233f */
a1 = 3.2246702909e-01, /* 0x3ea51a66 */
a2 = 6.7352302372e-02, /* 0x3d89f001 */
a3 = 2.0580807701e-02, /* 0x3ca89915 */
a4 = 7.3855509982e-03, /* 0x3bf2027e */
a5 = 2.8905137442e-03, /* 0x3b3d6ec6 */
a6 = 1.1927076848e-03, /* 0x3a9c54a1 */
a7 = 5.1006977446e-04, /* 0x3a05b634 */
a8 = 2.2086278477e-04, /* 0x39679767 */
a9 = 1.0801156895e-04, /* 0x38e28445 */
a10 = 2.5214456400e-05, /* 0x37d383a2 */
a11 = 4.4864096708e-05, /* 0x383c2c75 */
tc = 1.4616321325e+00, /* 0x3fbb16c3 */
tf = -1.2148628384e-01, /* 0xbdf8cdcd */
/* tt = -(tail of tf) */
tt = 6.6971006518e-09, /* 0x31e61c52 */
t0 = 4.8383611441e-01, /* 0x3ef7b95e */
t1 = -1.4758771658e-01, /* 0xbe17213c */
t2 = 6.4624942839e-02, /* 0x3d845a15 */
t3 = -3.2788541168e-02, /* 0xbd064d47 */
t4 = 1.7970675603e-02, /* 0x3c93373d */
t5 = -1.0314224288e-02, /* 0xbc28fcfe */
t6 = 6.1005386524e-03, /* 0x3bc7e707 */
t7 = -3.6845202558e-03, /* 0xbb7177fe */
t8 = 2.2596477065e-03, /* 0x3b141699 */
t9 = -1.4034647029e-03, /* 0xbab7f476 */
t10 = 8.8108185446e-04, /* 0x3a66f867 */
t11 = -5.3859531181e-04, /* 0xba0d3085 */
t12 = 3.1563205994e-04, /* 0x39a57b6b */
t13 = -3.1275415677e-04, /* 0xb9a3f927 */
t14 = 3.3552918467e-04, /* 0x39afe9f7 */
u0 = -7.7215664089e-02, /* 0xbd9e233f */
u1 = 6.3282704353e-01, /* 0x3f2200f4 */
u2 = 1.4549225569e+00, /* 0x3fba3ae7 */
u3 = 9.7771751881e-01, /* 0x3f7a4bb2 */
u4 = 2.2896373272e-01, /* 0x3e6a7578 */
u5 = 1.3381091878e-02, /* 0x3c5b3c5e */
v1 = 2.4559779167e+00, /* 0x401d2ebe */
v2 = 2.1284897327e+00, /* 0x4008392d */
v3 = 7.6928514242e-01, /* 0x3f44efdf */
v4 = 1.0422264785e-01, /* 0x3dd572af */
v5 = 3.2170924824e-03, /* 0x3b52d5db */
s0 = -7.7215664089e-02, /* 0xbd9e233f */
s1 = 2.1498242021e-01, /* 0x3e5c245a */
s2 = 3.2577878237e-01, /* 0x3ea6cc7a */
s3 = 1.4635047317e-01, /* 0x3e15dce6 */
s4 = 2.6642270386e-02, /* 0x3cda40e4 */
s5 = 1.8402845599e-03, /* 0x3af135b4 */
s6 = 3.1947532989e-05, /* 0x3805ff67 */
r1 = 1.3920053244e+00, /* 0x3fb22d3b */
r2 = 7.2193557024e-01, /* 0x3f38d0c5 */
r3 = 1.7193385959e-01, /* 0x3e300f6e */
r4 = 1.8645919859e-02, /* 0x3c98bf54 */
r5 = 7.7794247773e-04, /* 0x3a4beed6 */
r6 = 7.3266842264e-06, /* 0x36f5d7bd */
w0 = 4.1893854737e-01, /* 0x3ed67f1d */
w1 = 8.3333335817e-02, /* 0x3daaaaab */
w2 = -2.7777778450e-03, /* 0xbb360b61 */
w3 = 7.9365057172e-04, /* 0x3a500cfd */
w4 = -5.9518753551e-04, /* 0xba1c065c */
w5 = 8.3633989561e-04, /* 0x3a5b3dd2 */
w6 = -1.6309292987e-03; /* 0xbad5c4e8 */
 
#ifdef __STDC__
static const float zero= 0.0000000000e+00;
#else
static float zero= 0.0000000000e+00;
#endif
 
#ifdef __STDC__
static float sin_pif(float x)
#else
static float sin_pif(x)
float x;
#endif
{
float y,z;
__int32_t n,ix;
 
GET_FLOAT_WORD(ix,x);
ix &= 0x7fffffff;
 
if(ix<0x3e800000) return __kernel_sinf(pi*x,zero,0);
y = -x; /* x is assume negative */
 
/*
* argument reduction, make sure inexact flag not raised if input
* is an integer
*/
z = floorf(y);
if(z!=y) { /* inexact anyway */
y *= (float)0.5;
y = (float)2.0*(y - floorf(y)); /* y = |x| mod 2.0 */
n = (__int32_t) (y*(float)4.0);
} else {
if(ix>=0x4b800000) {
y = zero; n = 0; /* y must be even */
} else {
if(ix<0x4b000000) z = y+two23; /* exact */
GET_FLOAT_WORD(n,z);
n &= 1;
y = n;
n<<= 2;
}
}
switch (n) {
case 0: y = __kernel_sinf(pi*y,zero,0); break;
case 1:
case 2: y = __kernel_cosf(pi*((float)0.5-y),zero); break;
case 3:
case 4: y = __kernel_sinf(pi*(one-y),zero,0); break;
case 5:
case 6: y = -__kernel_cosf(pi*(y-(float)1.5),zero); break;
default: y = __kernel_sinf(pi*(y-(float)2.0),zero,0); break;
}
return -y;
}
 
 
#ifdef __STDC__
float __ieee754_lgammaf_r(float x, int *signgamp)
#else
float __ieee754_lgammaf_r(x,signgamp)
float x; int *signgamp;
#endif
{
float t,y,z,nadj = 0.0,p,p1,p2,p3,q,r,w;
__int32_t i,hx,ix;
 
GET_FLOAT_WORD(hx,x);
 
/* purge off +-inf, NaN, +-0, and negative arguments */
*signgamp = 1;
ix = hx&0x7fffffff;
if(ix>=0x7f800000) return x*x;
if(ix==0) return one/zero;
if(ix<0x1c800000) { /* |x|<2**-70, return -log(|x|) */
if(hx<0) {
*signgamp = -1;
return -__ieee754_logf(-x);
} else return -__ieee754_logf(x);
}
if(hx<0) {
if(ix>=0x4b000000) /* |x|>=2**23, must be -integer */
return one/zero;
t = sin_pif(x);
if(t==zero) return one/zero; /* -integer */
nadj = __ieee754_logf(pi/fabsf(t*x));
if(t<zero) *signgamp = -1;
x = -x;
}
 
/* purge off 1 and 2 */
if (ix==0x3f800000||ix==0x40000000) r = 0;
/* for x < 2.0 */
else if(ix<0x40000000) {
if(ix<=0x3f666666) { /* lgamma(x) = lgamma(x+1)-log(x) */
r = -__ieee754_logf(x);
if(ix>=0x3f3b4a20) {y = one-x; i= 0;}
else if(ix>=0x3e6d3308) {y= x-(tc-one); i=1;}
else {y = x; i=2;}
} else {
r = zero;
if(ix>=0x3fdda618) {y=(float)2.0-x;i=0;} /* [1.7316,2] */
else if(ix>=0x3F9da620) {y=x-tc;i=1;} /* [1.23,1.73] */
else {y=x-one;i=2;}
}
switch(i) {
case 0:
z = y*y;
p1 = a0+z*(a2+z*(a4+z*(a6+z*(a8+z*a10))));
p2 = z*(a1+z*(a3+z*(a5+z*(a7+z*(a9+z*a11)))));
p = y*p1+p2;
r += (p-(float)0.5*y); break;
case 1:
z = y*y;
w = z*y;
p1 = t0+w*(t3+w*(t6+w*(t9 +w*t12))); /* parallel comp */
p2 = t1+w*(t4+w*(t7+w*(t10+w*t13)));
p3 = t2+w*(t5+w*(t8+w*(t11+w*t14)));
p = z*p1-(tt-w*(p2+y*p3));
r += (tf + p); break;
case 2:
p1 = y*(u0+y*(u1+y*(u2+y*(u3+y*(u4+y*u5)))));
p2 = one+y*(v1+y*(v2+y*(v3+y*(v4+y*v5))));
r += (-(float)0.5*y + p1/p2);
}
}
else if(ix<0x41000000) { /* x < 8.0 */
i = (__int32_t)x;
t = zero;
y = x-(float)i;
p = y*(s0+y*(s1+y*(s2+y*(s3+y*(s4+y*(s5+y*s6))))));
q = one+y*(r1+y*(r2+y*(r3+y*(r4+y*(r5+y*r6)))));
r = half*y+p/q;
z = one; /* lgamma(1+s) = log(s) + lgamma(s) */
switch(i) {
case 7: z *= (y+(float)6.0); /* FALLTHRU */
case 6: z *= (y+(float)5.0); /* FALLTHRU */
case 5: z *= (y+(float)4.0); /* FALLTHRU */
case 4: z *= (y+(float)3.0); /* FALLTHRU */
case 3: z *= (y+(float)2.0); /* FALLTHRU */
r += __ieee754_logf(z); break;
}
/* 8.0 <= x < 2**58 */
} else if (ix < 0x5c800000) {
t = __ieee754_logf(x);
z = one/x;
y = z*z;
w = w0+z*(w1+y*(w2+y*(w3+y*(w4+y*(w5+y*w6)))));
r = (x-half)*(t-one)+w;
} else
/* 2**58 <= x <= inf */
r = x*(__ieee754_logf(x)-one);
if(hx<0) r = nadj - r;
return r;
}
/programs/develop/libraries/newlib/math/f_atan2.S
0,0 → 1,37
/*
* ====================================================
* Copyright (C) 1998, 2002 by Red Hat Inc. All rights reserved.
*
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#if !defined(_SOFT_FLOAT)
 
/*
Fast version of atan2 using Intel float instructions.
 
double _f_atan2 (double y, double x);
 
Function computes arctan ( y / x ).
There is no error checking or setting of errno.
*/
#include "i386mach.h"
 
.global SYM (_f_atan2)
SOTYPE_FUNCTION(_f_atan2)
 
SYM (_f_atan2):
pushl ebp
movl esp,ebp
fldl 8(ebp)
fldl 16(ebp)
fpatan
 
leave
ret
 
#endif
/programs/develop/libraries/newlib/math/f_atan2f.S
0,0 → 1,37
/*
* ====================================================
* Copyright (C) 1998, 2002 by Red Hat Inc. All rights reserved.
*
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#if !defined(_SOFT_FLOAT)
 
/*
Fast version of atan2f using Intel float instructions.
 
float _f_atan2f (float y, float x);
 
Function computes arctan ( y / x ).
There is no error checking or setting of errno.
*/
 
#include "i386mach.h"
 
.global SYM (_f_atan2f)
SOTYPE_FUNCTION(_f_atan2f)
 
SYM (_f_atan2f):
pushl ebp
movl esp,ebp
flds 8(ebp)
flds 12(ebp)
fpatan
 
leave
ret
 
#endif
/programs/develop/libraries/newlib/math/f_exp.c
0,0 → 1,47
/*
* ====================================================
* Copyright (C) 1998,2002 by Red Hat Inc. All rights reserved.
*
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#if !defined(_SOFT_FLOAT)
 
/*
Fast version of exp using Intel float instructions.
 
double _f_exp (double x);
 
Function computes e ** x. The following special cases exist:
1. if x is 0.0 ==> return 1.0
2. if x is infinity ==> return infinity
3. if x is -infinity ==> return 0.0
4. if x is NaN ==> return x
There is no error checking or setting of errno.
*/
 
 
#include <math.h>
#include <ieeefp.h>
#include "f_math.h"
 
double _f_exp (double x)
{
if (check_finite(x))
{
double result;
asm ("fldl2e; fmulp; fld %%st; frndint; fsub %%st,%%st(1); fxch;" \
"fchs; f2xm1; fld1; faddp; fxch; fld1; fscale; fstp %%st(1); fmulp" :
"=t"(result) : "0"(x));
return result;
}
else if (x == -infinity())
return 0.0;
 
return x;
}
 
#endif
/programs/develop/libraries/newlib/math/f_expf.c
0,0 → 1,47
/*
* ====================================================
* Copyright (C) 1998, 2002 by Red Hat Inc. All rights reserved.
*
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#if !defined(_SOFT_FLOAT)
 
/*
Fast version of exp using Intel float instructions.
 
float _f_expf (float x);
 
Function computes e ** x. The following special cases exist:
1. if x is 0.0 ==> return 1.0
2. if x is infinity ==> return infinity
3. if x is -infinity ==> return 0.0
4. if x is NaN ==> return x
There is no error checking or setting of errno.
*/
 
 
#include <math.h>
#include <ieeefp.h>
#include "f_math.h"
 
float _f_expf (float x)
{
if (check_finitef(x))
{
float result;
asm ("fldl2e; fmulp; fld %%st; frndint; fsub %%st,%%st(1); fxch;" \
"fchs; f2xm1; fld1; faddp; fxch; fld1; fscale; fstp %%st(1); fmulp" :
"=t"(result) : "0"(x));
return result;
}
else if (x == -infinityf())
return 0.0;
 
return x;
}
 
#endif
/programs/develop/libraries/newlib/math/f_frexpf.S
0,0 → 1,48
/*
* ====================================================
* Copyright (C) 1998, 2002 by Red Hat Inc. All rights reserved.
*
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#if !defined(_SOFT_FLOAT)
 
/*
Fast version of frexpf using Intel float instructions.
 
float _f_frexpf (float x, int *exp);
 
Function splits x into y * 2 ** z. It then
returns the value of y and updates *exp with z.
There is no error checking or setting of errno.
*/
 
#include "i386mach.h"
 
.global SYM (_f_frexpf)
SOTYPE_FUNCTION(_f_frexpf)
 
SYM (_f_frexpf):
pushl ebp
movl esp,ebp
flds 8(ebp)
movl 12(ebp),eax
 
fxtract
fld1
fchs
fxch
fscale
fstp st1
fxch
fld1
faddp
fistpl 0(eax)
 
leave
ret
 
#endif
/programs/develop/libraries/newlib/math/f_ldexp.S
0,0 → 1,38
/*
* ====================================================
* Copyright (C) 1998, 2002 by Red Hat Inc. All rights reserved.
*
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#if !defined(_SOFT_FLOAT)
 
/*
Fast version of ldexp using Intel float instructions.
 
double _f_ldexp (double x, int exp);
 
Function calculates x * 2 ** exp.
There is no error checking or setting of errno.
*/
 
#include "i386mach.h"
 
.global SYM (_f_ldexp)
SOTYPE_FUNCTION(_f_ldexp)
 
SYM (_f_ldexp):
pushl ebp
movl esp,ebp
fild 16(ebp)
fldl 8(ebp)
fscale
fstp st1
 
leave
ret
 
#endif
/programs/develop/libraries/newlib/math/f_ldexpf.S
0,0 → 1,38
/*
* ====================================================
* Copyright (C) 1998, 2002 by Red Hat Inc. All rights reserved.
*
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#if !defined(_SOFT_FLOAT)
 
/*
Fast version of ldexpf using Intel float instructions.
 
float _f_ldexpf (float x, int exp);
 
Function calculates x * 2 ** exp.
There is no error checking or setting of errno.
*/
 
#include "i386mach.h"
 
.global SYM (_f_ldexpf)
SOTYPE_FUNCTION(_f_ldexpf)
 
SYM (_f_ldexpf):
pushl ebp
movl esp,ebp
fild 12(ebp)
flds 8(ebp)
fscale
fstp st1
 
leave
ret
 
#endif
/programs/develop/libraries/newlib/math/f_llrint.c
0,0 → 1,70
/*
* ====================================================
* x87 FP implementation contributed to Newlib by
* Dave Korn, November 2007. This file is placed in the
* public domain. Permission to use, copy, modify, and
* distribute this software is freely granted.
* ====================================================
*/
 
#ifdef __GNUC__
#if !defined(_SOFT_FLOAT)
 
#include <math.h>
 
/*
FUNCTION
<<llrint>>, <<llrintf>>, <<llrintl>>---round and convert to long long integer
INDEX
llrint
INDEX
llrintf
INDEX
llrintl
 
ANSI_SYNOPSIS
#include <math.h>
long long int llrint(double x);
long long int llrintf(float x);
long long int llrintl(long double x);
 
TRAD_SYNOPSIS
ANSI-only.
 
DESCRIPTION
The <<llrint>>, <<llrintf>> and <<llrintl>> functions round <[x]> to the nearest integer value,
according to the current rounding direction. If the rounded value is outside the
range of the return type, the numeric result is unspecified. A range error may
occur if the magnitude of <[x]> is too large.
 
RETURNS
These functions return the rounded integer value of <[x]>.
<<llrint>>, <<llrintf>> and <<llrintl>> return the result as a long long integer.
 
PORTABILITY
<<llrint>>, <<llrintf>> and <<llrintl>> are ANSI.
The fast math versions of <<llrint>>, <<llrintf>> and <<llrintl>> are only
available on i386 platforms when hardware floating point support is available
and when compiling with GCC.
 
*/
 
/*
* Fast math version of llrint(x)
* Return x rounded to integral value according to the prevailing
* rounding mode.
* Method:
* Using inline x87 asms.
* Exception:
* Governed by x87 FPCR.
*/
 
long long int _f_llrint (double x)
{
long long int _result;
asm ("fistpll %0" : "=m" (_result) : "t" (x) : "st");
return _result;
}
 
#endif /* !_SOFT_FLOAT */
#endif /* __GNUC__ */
/programs/develop/libraries/newlib/math/f_llrintf.c
0,0 → 1,33
/*
* ====================================================
* x87 FP implementation contributed to Newlib by
* Dave Korn, November 2007. This file is placed in the
* public domain. Permission to use, copy, modify, and
* distribute this software is freely granted.
* ====================================================
*/
 
#ifdef __GNUC__
#if !defined(_SOFT_FLOAT)
 
#include <math.h>
 
/*
* Fast math version of llrintf(x)
* Return x rounded to integral value according to the prevailing
* rounding mode.
* Method:
* Using inline x87 asms.
* Exception:
* Governed by x87 FPCR.
*/
 
long long int _f_llrintf (float x)
{
long long int _result;
asm ("fistpll %0" : "=m" (_result) : "t" (x) : "st");
return _result;
}
 
#endif /* !_SOFT_FLOAT */
#endif /* __GNUC__ */
/programs/develop/libraries/newlib/math/f_llrintl.c
0,0 → 1,38
/*
* ====================================================
* x87 FP implementation contributed to Newlib by
* Dave Korn, November 2007. This file is placed in the
* public domain. Permission to use, copy, modify, and
* distribute this software is freely granted.
* ====================================================
*/
 
#ifdef __GNUC__
#if !defined(_SOFT_FLOAT)
 
#include <math.h>
 
/*
* Fast math version of llrintl(x)
* Return x rounded to integral value according to the prevailing
* rounding mode.
* Method:
* Using inline x87 asms.
* Exception:
* Governed by x87 FPCR.
*/
 
long long int _f_llrintl (long double x)
{
long long int _result;
asm ("fistpll %0" : "=m" (_result) : "t" (x) : "st");
return _result;
}
 
/* For now, we only have the fast math version. */
long long int llrintl (long double x) {
return _f_llrintl(x);
}
 
#endif /* !_SOFT_FLOAT */
#endif /* __GNUC__ */
/programs/develop/libraries/newlib/math/f_log.S
0,0 → 1,40
/*
* ====================================================
* Copyright (C) 1998, 2002 by Red Hat Inc. All rights reserved.
*
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#if !defined(_SOFT_FLOAT)
 
/*
Fast version of log using Intel float instructions.
 
double _f_log (double x);
 
Function calculates the log base e of x.
There is no error checking or setting of errno.
*/
 
#include "i386mach.h"
 
.global SYM (_f_log)
SOTYPE_FUNCTION(_f_log)
 
SYM (_f_log):
pushl ebp
movl esp,ebp
 
fld1
fldl2e
fdivrp
fldl 8(ebp)
fyl2x
 
leave
ret
 
#endif
/programs/develop/libraries/newlib/math/f_log10.S
0,0 → 1,40
/*
* ====================================================
* Copyright (C) 1998, 2002 by Red Hat Inc. All rights reserved.
*
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#if !defined(_SOFT_FLOAT)
 
/*
Fast version of log10 using Intel float instructions.
 
double _f_log10 (double x);
 
Function calculates the log base 10 of x.
There is no error checking or setting of errno.
*/
 
#include "i386mach.h"
 
.global SYM (_f_log10)
SOTYPE_FUNCTION(_f_log10)
 
SYM (_f_log10):
pushl ebp
movl esp,ebp
 
fld1
fldl2t
fdivrp
fldl 8(ebp)
fyl2x
 
leave
ret
 
#endif
/programs/develop/libraries/newlib/math/f_log10f.S
0,0 → 1,40
/*
* ====================================================
* Copyright (C) 1998, 2002 by Red Hat Inc. All rights reserved.
*
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#if !defined(_SOFT_FLOAT)
 
/*
Fast version of logf using Intel float instructions.
 
float _f_log10f (float x);
 
Function calculates the log base 10 of x.
There is no error checking or setting of errno.
*/
 
#include "i386mach.h"
 
.global SYM (_f_log10f)
SOTYPE_FUNCTION(_f_log10f)
 
SYM (_f_log10f):
pushl ebp
movl esp,ebp
 
fld1
fldl2t
fdivrp
flds 8(ebp)
fyl2x
 
leave
ret
 
#endif
/programs/develop/libraries/newlib/math/f_logf.S
0,0 → 1,40
/*
* ====================================================
* Copyright (C) 1998, 2002 by Red Hat Inc. All rights reserved.
*
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#if !defined(_SOFT_FLOAT)
 
/*
Fast version of logf using Intel float instructions.
 
float _f_logf (float x);
 
Function calculates the log base e of x.
There is no error checking or setting of errno.
*/
 
#include "i386mach.h"
 
.global SYM (_f_logf)
SOTYPE_FUNCTION(_f_logf)
 
SYM (_f_logf):
pushl ebp
movl esp,ebp
 
fld1
fldl2e
fdivrp
flds 8(ebp)
fyl2x
 
leave
ret
 
#endif
/programs/develop/libraries/newlib/math/f_lrint.c
0,0 → 1,69
/*
* ====================================================
* x87 FP implementation contributed to Newlib by
* Dave Korn, November 2007. This file is placed in the
* public domain. Permission to use, copy, modify, and
* distribute this software is freely granted.
* ====================================================
*/
 
#if defined(__GNUC__) && !defined(_SOFT_FLOAT)
 
#include <math.h>
 
/*
FUNCTION
<<lrint>>, <<lrintf>>, <<lrintl>>---round and convert to long integer
INDEX
lrint
INDEX
lrintf
INDEX
lrintl
 
ANSI_SYNOPSIS
#include <math.h>
long int lrint(double x);
long int lrintf(float x);
long int lrintl(long double x);
 
TRAD_SYNOPSIS
ANSI-only.
 
DESCRIPTION
The <<lrint>>, <<lrintf>> and <<lrintl>> functions round <[x]> to the nearest integer value,
according to the current rounding direction. If the rounded value is outside the
range of the return type, the numeric result is unspecified. A range error may
occur if the magnitude of <[x]> is too large.
 
RETURNS
These functions return the rounded integer value of <[x]>.
<<lrint>>, <<lrintf>> and <<lrintl>> return the result as a long integer.
 
PORTABILITY
<<lrint>>, <<lrintf>>, and <<lrintl>> are ANSI.
<<lrint>> and <<lrintf>> are available on all platforms.
<<lrintl>> is only available on i386 platforms when hardware
floating point support is available and when compiling with GCC.
 
*/
 
/*
* Fast math version of lrint(x)
* Return x rounded to integral value according to the prevailing
* rounding mode.
* Method:
* Using inline x87 asms.
* Exception:
* Governed by x87 FPCR.
*/
 
long int _f_lrint (double x)
{
long int _result;
asm ("fistpl %0" : "=m" (_result) : "t" (x) : "st");
return _result;
}
 
#endif /* !__GNUC__ || _SOFT_FLOAT */
 
/programs/develop/libraries/newlib/math/f_lrintf.c
0,0 → 1,32
/*
* ====================================================
* x87 FP implementation contributed to Newlib by
* Dave Korn, November 2007. This file is placed in the
* public domain. Permission to use, copy, modify, and
* distribute this software is freely granted.
* ====================================================
*/
 
#if defined(__GNUC__) && !defined(_SOFT_FLOAT)
 
#include <math.h>
 
/*
* Fast math version of lrintf(x)
* Return x rounded to integral value according to the prevailing
* rounding mode.
* Method:
* Using inline x87 asms.
* Exception:
* Governed by x87 FPCR.
*/
 
long int _f_lrintf (float x)
{
long int _result;
asm ("fistpl %0" : "=m" (_result) : "t" (x) : "st");
return _result;
}
 
#endif /* !__GNUC__ || _SOFT_FLOAT */
 
/programs/develop/libraries/newlib/math/f_lrintl.c
0,0 → 1,38
/*
* ====================================================
* x87 FP implementation contributed to Newlib by
* Dave Korn, November 2007. This file is placed in the
* public domain. Permission to use, copy, modify, and
* distribute this software is freely granted.
* ====================================================
*/
 
#ifdef __GNUC__
#if !defined(_SOFT_FLOAT)
 
#include <math.h>
 
/*
* Fast math version of lrintl(x)
* Return x rounded to integral value according to the prevailing
* rounding mode.
* Method:
* Using inline x87 asms.
* Exception:
* Governed by x87 FPCR.
*/
 
long int _f_lrintl (long double x)
{
long int _result;
asm ("fistpl %0" : "=m" (_result) : "t" (x) : "st");
return _result;
}
 
/* For now, there is only the fast math version so we use it. */
long int lrintl (long double x) {
return _f_lrintl(x);
}
 
#endif /* !_SOFT_FLOAT */
#endif /* __GNUC__ */
/programs/develop/libraries/newlib/math/f_math.h
0,0 → 1,29
#ifndef __F_MATH_H__
#define __F_MATH_H__
 
#include <_ansi.h>
#include "fdlibm.h"
 
__inline__
static
int
_DEFUN (check_finite, (x),
double x)
{
__int32_t hx;
GET_HIGH_WORD(hx,x);
return (int)((__uint32_t)((hx&0x7fffffff)-0x7ff00000)>>31);
}
 
__inline__
static
int
_DEFUN (check_finitef, (x),
float x)
{
__int32_t ix;
GET_FLOAT_WORD(ix,x);
return (int)((__uint32_t)((ix&0x7fffffff)-0x7f800000)>>31);
}
 
#endif /* __F_MATH_H__ */
/programs/develop/libraries/newlib/math/f_pow.c
0,0 → 1,47
/*
* ====================================================
* Copyright (C) 1998, 2002 by Red Hat Inc. All rights reserved.
*
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#if !defined(_SOFT_FLOAT)
 
/*
Fast version of pow using Intel float instructions.
 
double _f_pow (double x, double y);
 
Function calculates x to power of y.
The function optimizes the case where x is >0.0 and y is finite.
In such a case, there is no error checking or setting of errno.
All other cases defer to normal pow() function which will
set errno as normal.
*/
 
#include <math.h>
#include <ieeefp.h>
#include "f_math.h"
 
double _f_pow (double x, double y)
{
/* following sequence handles the majority of cases for pow() */
if (x > 0.0 && check_finite(y))
{
double result;
/* calculate x ** y as 2 ** (y log2(x)). On Intel, can only
raise 2 to an integer or a small fraction, thus, we have
to perform two steps 2**integer portion * 2**fraction. */
asm ("fyl2x; fld %%st; frndint; fsub %%st,%%st(1);"\
"fxch; fchs; f2xm1; fld1; faddp; fxch; fld1; fscale; fstp %%st(1);"\
"fmulp" : "=t" (result) : "0" (x), "u" (y) : "st(1)" );
return result;
}
else /* all other strange cases, defer to normal pow() */
return pow (x,y);
}
 
#endif
/programs/develop/libraries/newlib/math/f_powf.c
0,0 → 1,47
/*
* ====================================================
* Copyright (C) 1998, 2002 by Red Hat Inc. All rights reserved.
*
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#if !defined(_SOFT_FLOAT)
 
/*
Fast version of pow using Intel float instructions.
 
float _f_powf (float x, float y);
 
Function calculates x to power of y.
The function optimizes the case where x is >0.0 and y is finite.
In such a case, there is no error checking or setting of errno.
All other cases defer to normal powf() function which will
set errno as normal.
*/
 
#include <math.h>
#include <ieeefp.h>
#include "f_math.h"
 
float _f_powf (float x, float y)
{
/* following sequence handles the majority of cases for pow() */
if (x > 0.0 && check_finitef(y))
{
float result;
/* calculate x ** y as 2 ** (y log2(x)). On Intel, can only
raise 2 to an integer or a small fraction, thus, we have
to perform two steps 2**integer portion * 2**fraction. */
asm ("fyl2x; fld %%st; frndint; fsub %%st,%%st(1);"\
"fxch; fchs; f2xm1; fld1; faddp; fxch; fld1; fscale; fstp %%st(1);"\
"fmulp" : "=t" (result) : "0" (x), "u" (y) : "st(1)" );
return result;
}
else /* all other strange cases, defer to normal pow() */
return powf (x,y);
}
 
#endif
/programs/develop/libraries/newlib/math/f_rint.c
0,0 → 1,67
/*
* ====================================================
* x87 FP implementation contributed to Newlib by
* Dave Korn, November 2007. This file is placed in the
* public domain. Permission to use, copy, modify, and
* distribute this software is freely granted.
* ====================================================
*/
 
#if defined(__GNUC__) && !defined(_SOFT_FLOAT)
 
#include <math.h>
 
/*
FUNCTION
<<rint>>, <<rintf>>, <<rintl>>---round to integer
INDEX
rint
INDEX
rintf
INDEX
rintl
 
ANSI_SYNOPSIS
#include <math.h>
double rint(double x);
float rintf(float x);
long double rintl(long double x);
 
TRAD_SYNOPSIS
ANSI-only.
 
DESCRIPTION
The <<rint>>, <<rintf>> and <<rintl>> functions round <[x]> to an integer value
in floating-point format, using the current rounding direction. They may
raise the inexact exception if the result differs in value from the argument.
 
RETURNS
These functions return the rounded integer value of <[x]>.
 
PORTABILITY
<<rint>>, <<rintf>> and <<rintl>> are ANSI.
<<rint>> and <<rintf>> are available on all platforms.
<<rintl>> is only available on i386 platforms when hardware
floating point support is available and when compiling with GCC.
 
*/
 
/*
* Fast math version of rint(x)
* Return x rounded to integral value according to the prevailing
* rounding mode.
* Method:
* Using inline x87 asms.
* Exception:
* Governed by x87 FPCR.
*/
 
double _f_rint (double x)
{
double _result;
asm ("frndint" : "=t" (_result) : "0" (x));
return _result;
}
 
#endif /* !__GNUC__ || _SOFT_FLOAT */
 
/programs/develop/libraries/newlib/math/f_rintf.c
0,0 → 1,32
/*
* ====================================================
* x87 FP implementation contributed to Newlib by
* Dave Korn, November 2007. This file is placed in the
* public domain. Permission to use, copy, modify, and
* distribute this software is freely granted.
* ====================================================
*/
 
#if defined(__GNUC__) && !defined(_SOFT_FLOAT)
 
#include <math.h>
 
/*
* Fast math version of rintf(x)
* Return x rounded to integral value according to the prevailing
* rounding mode.
* Method:
* Using inline x87 asms.
* Exception:
* Governed by x87 FPCR.
*/
 
float _f_rintf (float x)
{
float _result;
asm ("frndint" : "=t" (_result) : "0" (x));
return _result;
}
 
#endif /* !__GNUC__ || _SOFT_FLOAT */
 
/programs/develop/libraries/newlib/math/f_rintl.c
0,0 → 1,38
/*
* ====================================================
* x87 FP implementation contributed to Newlib by
* Dave Korn, November 2007. This file is placed in the
* public domain. Permission to use, copy, modify, and
* distribute this software is freely granted.
* ====================================================
*/
 
#ifdef __GNUC__
#if !defined(_SOFT_FLOAT)
 
#include <math.h>
 
/*
* Fast math version of rintl(x)
* Return x rounded to integral value according to the prevailing
* rounding mode.
* Method:
* Using inline x87 asms.
* Exception:
* Governed by x87 FPCR.
*/
 
long double _f_rintl (long double x)
{
long double _result;
asm ("frndint" : "=t" (_result) : "0" (x));
return _result;
}
 
/* For now, we only have the fast math version. */
long double rintl (long double x) {
return _f_rintl(x);
}
 
#endif /* !_SOFT_FLOAT */
#endif /* __GNUC__ */
/programs/develop/libraries/newlib/math/f_tan.S
0,0 → 1,38
/*
* ====================================================
* Copyright (C) 1998, 2002 by Red Hat Inc. All rights reserved.
*
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#if !defined(_SOFT_FLOAT)
 
/*
Fast version of tan using Intel float instructions.
 
double _f_tan (double x);
 
Function calculates the tangent of x.
There is no error checking or setting of errno.
*/
 
#include "i386mach.h"
 
.global SYM (_f_tan)
SOTYPE_FUNCTION(_f_tan)
 
SYM (_f_tan):
pushl ebp
movl esp,ebp
fldl 8(ebp)
fptan
ffree %st(0)
fincstp
 
leave
ret
 
#endif
/programs/develop/libraries/newlib/math/f_tanf.S
0,0 → 1,38
/*
* ====================================================
* Copyright (C) 1998, 2002 by Red Hat Inc. All rights reserved.
*
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#if !defined(_SOFT_FLOAT)
 
/*
Fast version of tanf using Intel float instructions.
 
float _f_tanf (float x);
 
Function calculates the tangent of x.
There is no error checking or setting of errno.
*/
 
#include "i386mach.h"
 
.global SYM (_f_tanf)
SOTYPE_FUNCTION(_f_tanf)
 
SYM (_f_tanf):
pushl ebp
movl esp,ebp
flds 8(ebp)
fptan
ffree %st(0)
fincstp
 
leave
ret
 
#endif
/programs/develop/libraries/newlib/math/fdlibm.h
139,7 → 139,6
 
/* Functions that are not documented, and are not in <math.h>. */
 
extern double logb __P((double));
#ifdef _SCALB_INT
extern double scalb __P((double, int));
#else
186,7 → 185,6
extern int __kernel_rem_pio2 __P((double*,double*,int,int,int,const __int32_t*));
 
/* Undocumented float functions. */
extern float logbf __P((float));
#ifdef _SCALB_INT
extern float scalbf __P((float, int));
#else
363,3 → 361,44
sf_u.word = (i); \
(d) = sf_u.value; \
} while (0)
 
/* Macros to avoid undefined behaviour that can arise if the amount
of a shift is exactly equal to the size of the shifted operand. */
 
#define SAFE_LEFT_SHIFT(op,amt) \
(((amt) < 8 * sizeof(op)) ? ((op) << (amt)) : 0)
 
#define SAFE_RIGHT_SHIFT(op,amt) \
(((amt) < 8 * sizeof(op)) ? ((op) >> (amt)) : 0)
 
#ifdef _COMPLEX_H
 
/*
* Quoting from ISO/IEC 9899:TC2:
*
* 6.2.5.13 Types
* Each complex type has the same representation and alignment requirements as
* an array type containing exactly two elements of the corresponding real type;
* the first element is equal to the real part, and the second element to the
* imaginary part, of the complex number.
*/
typedef union {
float complex z;
float parts[2];
} float_complex;
 
typedef union {
double complex z;
double parts[2];
} double_complex;
 
typedef union {
long double complex z;
long double parts[2];
} long_double_complex;
 
#define REAL_PART(z) ((z).parts[0])
#define IMAG_PART(z) ((z).parts[1])
 
#endif /* _COMPLEX_H */
 
/programs/develop/libraries/newlib/math/k_cos.c
0,0 → 1,96
 
/* @(#)k_cos.c 5.1 93/09/24 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
/*
* __kernel_cos( x, y )
* kernel cos function on [-pi/4, pi/4], pi/4 ~ 0.785398164
* Input x is assumed to be bounded by ~pi/4 in magnitude.
* Input y is the tail of x.
*
* Algorithm
* 1. Since cos(-x) = cos(x), we need only to consider positive x.
* 2. if x < 2^-27 (hx<0x3e400000 0), return 1 with inexact if x!=0.
* 3. cos(x) is approximated by a polynomial of degree 14 on
* [0,pi/4]
* 4 14
* cos(x) ~ 1 - x*x/2 + C1*x + ... + C6*x
* where the remez error is
*
* | 2 4 6 8 10 12 14 | -58
* |cos(x)-(1-.5*x +C1*x +C2*x +C3*x +C4*x +C5*x +C6*x )| <= 2
* | |
*
* 4 6 8 10 12 14
* 4. let r = C1*x +C2*x +C3*x +C4*x +C5*x +C6*x , then
* cos(x) = 1 - x*x/2 + r
* since cos(x+y) ~ cos(x) - sin(x)*y
* ~ cos(x) - x*y,
* a correction term is necessary in cos(x) and hence
* cos(x+y) = 1 - (x*x/2 - (r - x*y))
* For better accuracy when x > 0.3, let qx = |x|/4 with
* the last 32 bits mask off, and if x > 0.78125, let qx = 0.28125.
* Then
* cos(x+y) = (1-qx) - ((x*x/2-qx) - (r-x*y)).
* Note that 1-qx and (x*x/2-qx) is EXACT here, and the
* magnitude of the latter is at least a quarter of x*x/2,
* thus, reducing the rounding error in the subtraction.
*/
 
#include "fdlibm.h"
 
#ifndef _DOUBLE_IS_32BITS
 
#ifdef __STDC__
static const double
#else
static double
#endif
one = 1.00000000000000000000e+00, /* 0x3FF00000, 0x00000000 */
C1 = 4.16666666666666019037e-02, /* 0x3FA55555, 0x5555554C */
C2 = -1.38888888888741095749e-03, /* 0xBF56C16C, 0x16C15177 */
C3 = 2.48015872894767294178e-05, /* 0x3EFA01A0, 0x19CB1590 */
C4 = -2.75573143513906633035e-07, /* 0xBE927E4F, 0x809C52AD */
C5 = 2.08757232129817482790e-09, /* 0x3E21EE9E, 0xBDB4B1C4 */
C6 = -1.13596475577881948265e-11; /* 0xBDA8FAE9, 0xBE8838D4 */
 
#ifdef __STDC__
double __kernel_cos(double x, double y)
#else
double __kernel_cos(x, y)
double x,y;
#endif
{
double a,hz,z,r,qx;
__int32_t ix;
GET_HIGH_WORD(ix,x);
ix &= 0x7fffffff; /* ix = |x|'s high word*/
if(ix<0x3e400000) { /* if x < 2**27 */
if(((int)x)==0) return one; /* generate inexact */
}
z = x*x;
r = z*(C1+z*(C2+z*(C3+z*(C4+z*(C5+z*C6)))));
if(ix < 0x3FD33333) /* if |x| < 0.3 */
return one - (0.5*z - (z*r - x*y));
else {
if(ix > 0x3fe90000) { /* x > 0.78125 */
qx = 0.28125;
} else {
INSERT_WORDS(qx,ix-0x00200000,0); /* x/4 */
}
hz = 0.5*z-qx;
a = one-qx;
return a - (hz - (z*r-x*y));
}
}
 
#endif /* defined(_DOUBLE_IS_32BITS) */
/programs/develop/libraries/newlib/math/k_rem_pio2.c
0,0 → 1,320
 
/* @(#)k_rem_pio2.c 5.1 93/09/24 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
/*
* __kernel_rem_pio2(x,y,e0,nx,prec,ipio2)
* double x[],y[]; int e0,nx,prec; int ipio2[];
*
* __kernel_rem_pio2 return the last three digits of N with
* y = x - N*pi/2
* so that |y| < pi/2.
*
* The method is to compute the integer (mod 8) and fraction parts of
* (2/pi)*x without doing the full multiplication. In general we
* skip the part of the product that are known to be a huge integer (
* more accurately, = 0 mod 8 ). Thus the number of operations are
* independent of the exponent of the input.
*
* (2/pi) is represented by an array of 24-bit integers in ipio2[].
*
* Input parameters:
* x[] The input value (must be positive) is broken into nx
* pieces of 24-bit integers in double precision format.
* x[i] will be the i-th 24 bit of x. The scaled exponent
* of x[0] is given in input parameter e0 (i.e., x[0]*2^e0
* match x's up to 24 bits.
*
* Example of breaking a double positive z into x[0]+x[1]+x[2]:
* e0 = ilogb(z)-23
* z = scalbn(z,-e0)
* for i = 0,1,2
* x[i] = floor(z)
* z = (z-x[i])*2**24
*
*
* y[] ouput result in an array of double precision numbers.
* The dimension of y[] is:
* 24-bit precision 1
* 53-bit precision 2
* 64-bit precision 2
* 113-bit precision 3
* The actual value is the sum of them. Thus for 113-bit
* precison, one may have to do something like:
*
* long double t,w,r_head, r_tail;
* t = (long double)y[2] + (long double)y[1];
* w = (long double)y[0];
* r_head = t+w;
* r_tail = w - (r_head - t);
*
* e0 The exponent of x[0]
*
* nx dimension of x[]
*
* prec an integer indicating the precision:
* 0 24 bits (single)
* 1 53 bits (double)
* 2 64 bits (extended)
* 3 113 bits (quad)
*
* ipio2[]
* integer array, contains the (24*i)-th to (24*i+23)-th
* bit of 2/pi after binary point. The corresponding
* floating value is
*
* ipio2[i] * 2^(-24(i+1)).
*
* External function:
* double scalbn(), floor();
*
*
* Here is the description of some local variables:
*
* jk jk+1 is the initial number of terms of ipio2[] needed
* in the computation. The recommended value is 2,3,4,
* 6 for single, double, extended,and quad.
*
* jz local integer variable indicating the number of
* terms of ipio2[] used.
*
* jx nx - 1
*
* jv index for pointing to the suitable ipio2[] for the
* computation. In general, we want
* ( 2^e0*x[0] * ipio2[jv-1]*2^(-24jv) )/8
* is an integer. Thus
* e0-3-24*jv >= 0 or (e0-3)/24 >= jv
* Hence jv = max(0,(e0-3)/24).
*
* jp jp+1 is the number of terms in PIo2[] needed, jp = jk.
*
* q[] double array with integral value, representing the
* 24-bits chunk of the product of x and 2/pi.
*
* q0 the corresponding exponent of q[0]. Note that the
* exponent for q[i] would be q0-24*i.
*
* PIo2[] double precision array, obtained by cutting pi/2
* into 24 bits chunks.
*
* f[] ipio2[] in floating point
*
* iq[] integer array by breaking up q[] in 24-bits chunk.
*
* fq[] final product of x*(2/pi) in fq[0],..,fq[jk]
*
* ih integer. If >0 it indicates q[] is >= 0.5, hence
* it also indicates the *sign* of the result.
*
*/
 
 
/*
* Constants:
* The hexadecimal values are the intended ones for the following
* constants. The decimal values may be used, provided that the
* compiler will convert from decimal to binary accurately enough
* to produce the hexadecimal values shown.
*/
 
#include "fdlibm.h"
 
#ifndef _DOUBLE_IS_32BITS
 
#ifdef __STDC__
static const int init_jk[] = {2,3,4,6}; /* initial value for jk */
#else
static int init_jk[] = {2,3,4,6};
#endif
 
#ifdef __STDC__
static const double PIo2[] = {
#else
static double PIo2[] = {
#endif
1.57079625129699707031e+00, /* 0x3FF921FB, 0x40000000 */
7.54978941586159635335e-08, /* 0x3E74442D, 0x00000000 */
5.39030252995776476554e-15, /* 0x3CF84698, 0x80000000 */
3.28200341580791294123e-22, /* 0x3B78CC51, 0x60000000 */
1.27065575308067607349e-29, /* 0x39F01B83, 0x80000000 */
1.22933308981111328932e-36, /* 0x387A2520, 0x40000000 */
2.73370053816464559624e-44, /* 0x36E38222, 0x80000000 */
2.16741683877804819444e-51, /* 0x3569F31D, 0x00000000 */
};
 
#ifdef __STDC__
static const double
#else
static double
#endif
zero = 0.0,
one = 1.0,
two24 = 1.67772160000000000000e+07, /* 0x41700000, 0x00000000 */
twon24 = 5.96046447753906250000e-08; /* 0x3E700000, 0x00000000 */
 
#ifdef __STDC__
int __kernel_rem_pio2(double *x, double *y, int e0, int nx, int prec, const __int32_t *ipio2)
#else
int __kernel_rem_pio2(x,y,e0,nx,prec,ipio2)
double x[], y[]; int e0,nx,prec; __int32_t ipio2[];
#endif
{
__int32_t jz,jx,jv,jp,jk,carry,n,iq[20],i,j,k,m,q0,ih;
double z,fw,f[20],fq[20],q[20];
 
/* initialize jk*/
jk = init_jk[prec];
jp = jk;
 
/* determine jx,jv,q0, note that 3>q0 */
jx = nx-1;
jv = (e0-3)/24; if(jv<0) jv=0;
q0 = e0-24*(jv+1);
 
/* set up f[0] to f[jx+jk] where f[jx+jk] = ipio2[jv+jk] */
j = jv-jx; m = jx+jk;
for(i=0;i<=m;i++,j++) f[i] = (j<0)? zero : (double) ipio2[j];
 
/* compute q[0],q[1],...q[jk] */
for (i=0;i<=jk;i++) {
for(j=0,fw=0.0;j<=jx;j++) fw += x[j]*f[jx+i-j]; q[i] = fw;
}
 
jz = jk;
recompute:
/* distill q[] into iq[] reversingly */
for(i=0,j=jz,z=q[jz];j>0;i++,j--) {
fw = (double)((__int32_t)(twon24* z));
iq[i] = (__int32_t)(z-two24*fw);
z = q[j-1]+fw;
}
 
/* compute n */
z = scalbn(z,(int)q0); /* actual value of z */
z -= 8.0*floor(z*0.125); /* trim off integer >= 8 */
n = (__int32_t) z;
z -= (double)n;
ih = 0;
if(q0>0) { /* need iq[jz-1] to determine n */
i = (iq[jz-1]>>(24-q0)); n += i;
iq[jz-1] -= i<<(24-q0);
ih = iq[jz-1]>>(23-q0);
}
else if(q0==0) ih = iq[jz-1]>>23;
else if(z>=0.5) ih=2;
 
if(ih>0) { /* q > 0.5 */
n += 1; carry = 0;
for(i=0;i<jz ;i++) { /* compute 1-q */
j = iq[i];
if(carry==0) {
if(j!=0) {
carry = 1; iq[i] = 0x1000000- j;
}
} else iq[i] = 0xffffff - j;
}
if(q0>0) { /* rare case: chance is 1 in 12 */
switch(q0) {
case 1:
iq[jz-1] &= 0x7fffff; break;
case 2:
iq[jz-1] &= 0x3fffff; break;
}
}
if(ih==2) {
z = one - z;
if(carry!=0) z -= scalbn(one,(int)q0);
}
}
 
/* check if recomputation is needed */
if(z==zero) {
j = 0;
for (i=jz-1;i>=jk;i--) j |= iq[i];
if(j==0) { /* need recomputation */
for(k=1;iq[jk-k]==0;k++); /* k = no. of terms needed */
 
for(i=jz+1;i<=jz+k;i++) { /* add q[jz+1] to q[jz+k] */
f[jx+i] = (double) ipio2[jv+i];
for(j=0,fw=0.0;j<=jx;j++) fw += x[j]*f[jx+i-j];
q[i] = fw;
}
jz += k;
goto recompute;
}
}
 
/* chop off zero terms */
if(z==0.0) {
jz -= 1; q0 -= 24;
while(iq[jz]==0) { jz--; q0-=24;}
} else { /* break z into 24-bit if necessary */
z = scalbn(z,-(int)q0);
if(z>=two24) {
fw = (double)((__int32_t)(twon24*z));
iq[jz] = (__int32_t)(z-two24*fw);
jz += 1; q0 += 24;
iq[jz] = (__int32_t) fw;
} else iq[jz] = (__int32_t) z ;
}
 
/* convert integer "bit" chunk to floating-point value */
fw = scalbn(one,(int)q0);
for(i=jz;i>=0;i--) {
q[i] = fw*(double)iq[i]; fw*=twon24;
}
 
/* compute PIo2[0,...,jp]*q[jz,...,0] */
for(i=jz;i>=0;i--) {
for(fw=0.0,k=0;k<=jp&&k<=jz-i;k++) fw += PIo2[k]*q[i+k];
fq[jz-i] = fw;
}
 
/* compress fq[] into y[] */
switch(prec) {
case 0:
fw = 0.0;
for (i=jz;i>=0;i--) fw += fq[i];
y[0] = (ih==0)? fw: -fw;
break;
case 1:
case 2:
fw = 0.0;
for (i=jz;i>=0;i--) fw += fq[i];
y[0] = (ih==0)? fw: -fw;
fw = fq[0]-fw;
for (i=1;i<=jz;i++) fw += fq[i];
y[1] = (ih==0)? fw: -fw;
break;
case 3: /* painful */
for (i=jz;i>0;i--) {
fw = fq[i-1]+fq[i];
fq[i] += fq[i-1]-fw;
fq[i-1] = fw;
}
for (i=jz;i>1;i--) {
fw = fq[i-1]+fq[i];
fq[i] += fq[i-1]-fw;
fq[i-1] = fw;
}
for (fw=0.0,i=jz;i>=2;i--) fw += fq[i];
if(ih==0) {
y[0] = fq[0]; y[1] = fq[1]; y[2] = fw;
} else {
y[0] = -fq[0]; y[1] = -fq[1]; y[2] = -fw;
}
}
return n&7;
}
 
#endif /* defined(_DOUBLE_IS_32BITS) */
/programs/develop/libraries/newlib/math/k_sin.c
0,0 → 1,79
 
/* @(#)k_sin.c 5.1 93/09/24 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
/* __kernel_sin( x, y, iy)
* kernel sin function on [-pi/4, pi/4], pi/4 ~ 0.7854
* Input x is assumed to be bounded by ~pi/4 in magnitude.
* Input y is the tail of x.
* Input iy indicates whether y is 0. (if iy=0, y assume to be 0).
*
* Algorithm
* 1. Since sin(-x) = -sin(x), we need only to consider positive x.
* 2. if x < 2^-27 (hx<0x3e400000 0), return x with inexact if x!=0.
* 3. sin(x) is approximated by a polynomial of degree 13 on
* [0,pi/4]
* 3 13
* sin(x) ~ x + S1*x + ... + S6*x
* where
*
* |sin(x) 2 4 6 8 10 12 | -58
* |----- - (1+S1*x +S2*x +S3*x +S4*x +S5*x +S6*x )| <= 2
* | x |
*
* 4. sin(x+y) = sin(x) + sin'(x')*y
* ~ sin(x) + (1-x*x/2)*y
* For better accuracy, let
* 3 2 2 2 2
* r = x *(S2+x *(S3+x *(S4+x *(S5+x *S6))))
* then 3 2
* sin(x) = x + (S1*x + (x *(r-y/2)+y))
*/
 
#include "fdlibm.h"
 
#ifndef _DOUBLE_IS_32BITS
 
#ifdef __STDC__
static const double
#else
static double
#endif
half = 5.00000000000000000000e-01, /* 0x3FE00000, 0x00000000 */
S1 = -1.66666666666666324348e-01, /* 0xBFC55555, 0x55555549 */
S2 = 8.33333333332248946124e-03, /* 0x3F811111, 0x1110F8A6 */
S3 = -1.98412698298579493134e-04, /* 0xBF2A01A0, 0x19C161D5 */
S4 = 2.75573137070700676789e-06, /* 0x3EC71DE3, 0x57B1FE7D */
S5 = -2.50507602534068634195e-08, /* 0xBE5AE5E6, 0x8A2B9CEB */
S6 = 1.58969099521155010221e-10; /* 0x3DE5D93A, 0x5ACFD57C */
 
#ifdef __STDC__
double __kernel_sin(double x, double y, int iy)
#else
double __kernel_sin(x, y, iy)
double x,y; int iy; /* iy=0 if y is zero */
#endif
{
double z,r,v;
__int32_t ix;
GET_HIGH_WORD(ix,x);
ix &= 0x7fffffff; /* high word of x */
if(ix<0x3e400000) /* |x| < 2**-27 */
{if((int)x==0) return x;} /* generate inexact */
z = x*x;
v = z*x;
r = S2+z*(S3+z*(S4+z*(S5+z*S6)));
if(iy==0) return x+v*(S1+z*r);
else return x-((z*(half*y-v*r)-y)-v*S1);
}
 
#endif /* defined(_DOUBLE_IS_32BITS) */
/programs/develop/libraries/newlib/math/k_standard.c
0,0 → 1,784
 
/* @(#)k_standard.c 5.1 93/09/24 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*
*/
 
#include "fdlibm.h"
#include <errno.h>
 
#ifndef _USE_WRITE
#include <stdio.h> /* fputs(), stderr */
#define WRITE2(u,v) fputs(u, stderr)
#else /* !defined(_USE_WRITE) */
#include <unistd.h> /* write */
#define WRITE2(u,v) write(2, u, v)
#undef fflush
#endif /* !defined(_USE_WRITE) */
 
#ifdef __STDC__
static const double zero = 0.0; /* used as const */
#else
static double zero = 0.0; /* used as const */
#endif
 
/*
* Standard conformance (non-IEEE) on exception cases.
* Mapping:
* 1 -- acos(|x|>1)
* 2 -- asin(|x|>1)
* 3 -- atan2(+-0,+-0)
* 4 -- hypot overflow
* 5 -- cosh overflow
* 6 -- exp overflow
* 7 -- exp underflow
* 8 -- y0(0)
* 9 -- y0(-ve)
* 10-- y1(0)
* 11-- y1(-ve)
* 12-- yn(0)
* 13-- yn(-ve)
* 14-- lgamma(finite) overflow
* 15-- lgamma(-integer)
* 16-- log(0)
* 17-- log(x<0)
* 18-- log10(0)
* 19-- log10(x<0)
* 20-- pow(0.0,0.0)
* 21-- pow(x,y) overflow
* 22-- pow(x,y) underflow
* 23-- pow(0,negative)
* 24-- pow(neg,non-integral)
* 25-- sinh(finite) overflow
* 26-- sqrt(negative)
* 27-- fmod(x,0)
* 28-- remainder(x,0)
* 29-- acosh(x<1)
* 30-- atanh(|x|>1)
* 31-- atanh(|x|=1)
* 32-- scalb overflow
* 33-- scalb underflow
* 34-- j0(|x|>X_TLOSS)
* 35-- y0(x>X_TLOSS)
* 36-- j1(|x|>X_TLOSS)
* 37-- y1(x>X_TLOSS)
* 38-- jn(|x|>X_TLOSS, n)
* 39-- yn(x>X_TLOSS, n)
* 40-- gamma(finite) overflow
* 41-- gamma(-integer)
* 42-- pow(NaN,0.0)
*/
 
 
#ifdef __STDC__
double __kernel_standard(double x, double y, int type)
#else
double __kernel_standard(x,y,type)
double x,y; int type;
#endif
{
struct exception exc;
#ifndef HUGE_VAL /* this is the only routine that uses HUGE_VAL */
#define HUGE_VAL inf
double inf = 0.0;
 
SET_HIGH_WORD(inf,0x7ff00000); /* set inf to infinite */
#endif
 
#ifdef _USE_WRITE
/* (void) fflush(_stdout_r(p)); */
#endif
exc.arg1 = x;
exc.arg2 = y;
exc.err = 0;
switch(type) {
case 1:
case 101:
/* acos(|x|>1) */
exc.type = DOMAIN;
exc.name = type < 100 ? "acos" : "acosf";
exc.retval = zero;
if (_LIB_VERSION == _POSIX_)
errno = EDOM;
else if (!matherr(&exc)) {
/* if(_LIB_VERSION == _SVID_) {
(void) WRITE2("acos: DOMAIN error\n", 19);
} */
errno = EDOM;
}
break;
case 2:
case 102:
/* asin(|x|>1) */
exc.type = DOMAIN;
exc.name = type < 100 ? "asin" : "asinf";
exc.retval = zero;
if(_LIB_VERSION == _POSIX_)
errno = EDOM;
else if (!matherr(&exc)) {
/* if(_LIB_VERSION == _SVID_) {
(void) WRITE2("asin: DOMAIN error\n", 19);
} */
errno = EDOM;
}
break;
case 3:
case 103:
/* atan2(+-0,+-0) */
exc.arg1 = y;
exc.arg2 = x;
exc.type = DOMAIN;
exc.name = type < 100 ? "atan2" : "atan2f";
exc.retval = zero;
if(_LIB_VERSION == _POSIX_)
errno = EDOM;
else if (!matherr(&exc)) {
/* if(_LIB_VERSION == _SVID_) {
(void) WRITE2("atan2: DOMAIN error\n", 20);
} */
errno = EDOM;
}
break;
case 4:
case 104:
/* hypot(finite,finite) overflow */
exc.type = OVERFLOW;
exc.name = type < 100 ? "hypot" : "hypotf";
if (_LIB_VERSION == _SVID_)
exc.retval = HUGE;
else
exc.retval = HUGE_VAL;
if (_LIB_VERSION == _POSIX_)
errno = ERANGE;
else if (!matherr(&exc)) {
errno = ERANGE;
}
break;
case 5:
case 105:
/* cosh(finite) overflow */
exc.type = OVERFLOW;
exc.name = type < 100 ? "cosh" : "coshf";
if (_LIB_VERSION == _SVID_)
exc.retval = HUGE;
else
exc.retval = HUGE_VAL;
if (_LIB_VERSION == _POSIX_)
errno = ERANGE;
else if (!matherr(&exc)) {
errno = ERANGE;
}
break;
case 6:
case 106:
/* exp(finite) overflow */
exc.type = OVERFLOW;
exc.name = type < 100 ? "exp" : "expf";
if (_LIB_VERSION == _SVID_)
exc.retval = HUGE;
else
exc.retval = HUGE_VAL;
if (_LIB_VERSION == _POSIX_)
errno = ERANGE;
else if (!matherr(&exc)) {
errno = ERANGE;
}
break;
case 7:
case 107:
/* exp(finite) underflow */
exc.type = UNDERFLOW;
exc.name = type < 100 ? "exp" : "expf";
exc.retval = zero;
if (_LIB_VERSION == _POSIX_)
errno = ERANGE;
else if (!matherr(&exc)) {
errno = ERANGE;
}
break;
case 8:
case 108:
/* y0(0) = -inf */
exc.type = DOMAIN; /* should be SING for IEEE */
exc.name = type < 100 ? "y0" : "y0f";
if (_LIB_VERSION == _SVID_)
exc.retval = -HUGE;
else
exc.retval = -HUGE_VAL;
if (_LIB_VERSION == _POSIX_)
errno = EDOM;
else if (!matherr(&exc)) {
/* if (_LIB_VERSION == _SVID_) {
(void) WRITE2("y0: DOMAIN error\n", 17);
} */
errno = EDOM;
}
break;
case 9:
case 109:
/* y0(x<0) = NaN */
exc.type = DOMAIN;
exc.name = type < 100 ? "y0" : "y0f";
if (_LIB_VERSION == _SVID_)
exc.retval = -HUGE;
else
exc.retval = -HUGE_VAL;
if (_LIB_VERSION == _POSIX_)
errno = EDOM;
else if (!matherr(&exc)) {
/*if (_LIB_VERSION == _SVID_) {
(void) WRITE2("y0: DOMAIN error\n", 17);
} */
errno = EDOM;
}
break;
case 10:
case 110:
/* y1(0) = -inf */
exc.type = DOMAIN; /* should be SING for IEEE */
exc.name = type < 100 ? "y1" : "y1f";
if (_LIB_VERSION == _SVID_)
exc.retval = -HUGE;
else
exc.retval = -HUGE_VAL;
if (_LIB_VERSION == _POSIX_)
errno = EDOM;
else if (!matherr(&exc)) {
/* if (_LIB_VERSION == _SVID_) {
(void) WRITE2("y1: DOMAIN error\n", 17);
} */
errno = EDOM;
}
break;
case 11:
case 111:
/* y1(x<0) = NaN */
exc.type = DOMAIN;
exc.name = type < 100 ? "y1" : "y1f";
if (_LIB_VERSION == _SVID_)
exc.retval = -HUGE;
else
exc.retval = -HUGE_VAL;
if (_LIB_VERSION == _POSIX_)
errno = EDOM;
else if (!matherr(&exc)) {
/* if (_LIB_VERSION == _SVID_) {
(void) WRITE2("y1: DOMAIN error\n", 17);
} */
errno = EDOM;
}
break;
case 12:
case 112:
/* yn(n,0) = -inf */
exc.type = DOMAIN; /* should be SING for IEEE */
exc.name = type < 100 ? "yn" : "ynf";
if (_LIB_VERSION == _SVID_)
exc.retval = -HUGE;
else
exc.retval = -HUGE_VAL;
if (_LIB_VERSION == _POSIX_)
errno = EDOM;
else if (!matherr(&exc)) {
/* if (_LIB_VERSION == _SVID_) {
(void) WRITE2("yn: DOMAIN error\n", 17);
} */
errno = EDOM;
}
break;
case 13:
case 113:
/* yn(x<0) = NaN */
exc.type = DOMAIN;
exc.name = type < 100 ? "yn" : "ynf";
if (_LIB_VERSION == _SVID_)
exc.retval = -HUGE;
else
exc.retval = -HUGE_VAL;
if (_LIB_VERSION == _POSIX_)
errno = EDOM;
else if (!matherr(&exc)) {
/* if (_LIB_VERSION == _SVID_) {
(void) WRITE2("yn: DOMAIN error\n", 17);
} */
errno = EDOM;
}
break;
case 14:
case 114:
/* lgamma(finite) overflow */
exc.type = OVERFLOW;
exc.name = type < 100 ? "lgamma" : "lgammaf";
if (_LIB_VERSION == _SVID_)
exc.retval = HUGE;
else
exc.retval = HUGE_VAL;
if (_LIB_VERSION == _POSIX_)
errno = ERANGE;
else if (!matherr(&exc)) {
errno = ERANGE;
}
break;
case 15:
case 115:
/* lgamma(-integer) or lgamma(0) */
exc.type = SING;
exc.name = type < 100 ? "lgamma" : "lgammaf";
if (_LIB_VERSION == _SVID_)
exc.retval = HUGE;
else
exc.retval = HUGE_VAL;
if (_LIB_VERSION == _POSIX_)
errno = EDOM;
else if (!matherr(&exc)) {
/* if (_LIB_VERSION == _SVID_) {
(void) WRITE2("lgamma: SING error\n", 19);
} */
errno = EDOM;
}
break;
case 16:
case 116:
/* log(0) */
exc.type = SING;
exc.name = type < 100 ? "log" : "logf";
if (_LIB_VERSION == _SVID_)
exc.retval = -HUGE;
else
exc.retval = -HUGE_VAL;
if (_LIB_VERSION == _POSIX_)
errno = ERANGE;
else if (!matherr(&exc)) {
/* if (_LIB_VERSION == _SVID_) {
(void) WRITE2("log: SING error\n", 16);
} */
errno = EDOM;
}
break;
case 17:
case 117:
/* log(x<0) */
exc.type = DOMAIN;
exc.name = type < 100 ? "log" : "logf";
if (_LIB_VERSION == _SVID_)
exc.retval = -HUGE;
else
exc.retval = -HUGE_VAL;
if (_LIB_VERSION == _POSIX_)
errno = EDOM;
else if (!matherr(&exc)) {
/* if (_LIB_VERSION == _SVID_) {
(void) WRITE2("log: DOMAIN error\n", 18);
} */
errno = EDOM;
}
break;
case 18:
case 118:
/* log10(0) */
exc.type = SING;
exc.name = type < 100 ? "log10" : "log10f";
if (_LIB_VERSION == _SVID_)
exc.retval = -HUGE;
else
exc.retval = -HUGE_VAL;
if (_LIB_VERSION == _POSIX_)
errno = ERANGE;
else if (!matherr(&exc)) {
/* if (_LIB_VERSION == _SVID_) {
(void) WRITE2("log10: SING error\n", 18);
} */
errno = EDOM;
}
break;
case 19:
case 119:
/* log10(x<0) */
exc.type = DOMAIN;
exc.name = type < 100 ? "log10" : "log10f";
if (_LIB_VERSION == _SVID_)
exc.retval = -HUGE;
else
exc.retval = -HUGE_VAL;
if (_LIB_VERSION == _POSIX_)
errno = EDOM;
else if (!matherr(&exc)) {
/* if (_LIB_VERSION == _SVID_) {
(void) WRITE2("log10: DOMAIN error\n", 20);
} */
errno = EDOM;
}
break;
case 20:
case 120:
/* pow(0.0,0.0) */
/* error only if _LIB_VERSION == _SVID_ */
exc.type = DOMAIN;
exc.name = type < 100 ? "pow" : "powf";
exc.retval = zero;
if (_LIB_VERSION != _SVID_) exc.retval = 1.0;
else if (!matherr(&exc)) {
/* (void) WRITE2("pow(0,0): DOMAIN error\n", 23); */
errno = EDOM;
}
break;
case 21:
case 121:
/* pow(x,y) overflow */
exc.type = OVERFLOW;
exc.name = type < 100 ? "pow" : "powf";
if (_LIB_VERSION == _SVID_) {
exc.retval = HUGE;
y *= 0.5;
if(x<zero&&rint(y)!=y) exc.retval = -HUGE;
} else {
exc.retval = HUGE_VAL;
y *= 0.5;
if(x<zero&&rint(y)!=y) exc.retval = -HUGE_VAL;
}
if (_LIB_VERSION == _POSIX_)
errno = ERANGE;
else if (!matherr(&exc)) {
errno = ERANGE;
}
break;
case 22:
case 122:
/* pow(x,y) underflow */
exc.type = UNDERFLOW;
exc.name = type < 100 ? "pow" : "powf";
exc.retval = zero;
if (_LIB_VERSION == _POSIX_)
errno = ERANGE;
else if (!matherr(&exc)) {
errno = ERANGE;
}
break;
case 23:
case 123:
/* 0**neg */
exc.type = DOMAIN;
exc.name = type < 100 ? "pow" : "powf";
if (_LIB_VERSION == _SVID_)
exc.retval = zero;
else
exc.retval = -HUGE_VAL;
if (_LIB_VERSION == _POSIX_)
errno = EDOM;
else if (!matherr(&exc)) {
/* if (_LIB_VERSION == _SVID_) {
(void) WRITE2("pow(0,neg): DOMAIN error\n", 25);
} */
errno = EDOM;
}
break;
case 24:
case 124:
/* neg**non-integral */
exc.type = DOMAIN;
exc.name = type < 100 ? "pow" : "powf";
if (_LIB_VERSION == _SVID_)
exc.retval = zero;
else
exc.retval = zero/zero; /* X/Open allow NaN */
if (_LIB_VERSION == _POSIX_)
errno = EDOM;
else if (!matherr(&exc)) {
/* if (_LIB_VERSION == _SVID_) {
(void) WRITE2("neg**non-integral: DOMAIN error\n", 32);
} */
errno = EDOM;
}
break;
case 25:
case 125:
/* sinh(finite) overflow */
exc.type = OVERFLOW;
exc.name = type < 100 ? "sinh" : "sinhf";
if (_LIB_VERSION == _SVID_)
exc.retval = ( (x>zero) ? HUGE : -HUGE);
else
exc.retval = ( (x>zero) ? HUGE_VAL : -HUGE_VAL);
if (_LIB_VERSION == _POSIX_)
errno = ERANGE;
else if (!matherr(&exc)) {
errno = ERANGE;
}
break;
case 26:
case 126:
/* sqrt(x<0) */
exc.type = DOMAIN;
exc.name = type < 100 ? "sqrt" : "sqrtf";
if (_LIB_VERSION == _SVID_)
exc.retval = zero;
else
exc.retval = zero/zero;
if (_LIB_VERSION == _POSIX_)
errno = EDOM;
else if (!matherr(&exc)) {
/* if (_LIB_VERSION == _SVID_) {
(void) WRITE2("sqrt: DOMAIN error\n", 19);
} */
errno = EDOM;
}
break;
case 27:
case 127:
/* fmod(x,0) */
exc.type = DOMAIN;
exc.name = type < 100 ? "fmod" : "fmodf";
if (_LIB_VERSION == _SVID_)
exc.retval = x;
else
exc.retval = zero/zero;
if (_LIB_VERSION == _POSIX_)
errno = EDOM;
else if (!matherr(&exc)) {
/* if (_LIB_VERSION == _SVID_) {
(void) WRITE2("fmod: DOMAIN error\n", 20);
} */
errno = EDOM;
}
break;
case 28:
case 128:
/* remainder(x,0) */
exc.type = DOMAIN;
exc.name = type < 100 ? "remainder" : "remainderf";
exc.retval = zero/zero;
if (_LIB_VERSION == _POSIX_)
errno = EDOM;
else if (!matherr(&exc)) {
/* if (_LIB_VERSION == _SVID_) {
(void) WRITE2("remainder: DOMAIN error\n", 24);
} */
errno = EDOM;
}
break;
case 29:
case 129:
/* acosh(x<1) */
exc.type = DOMAIN;
exc.name = type < 100 ? "acosh" : "acoshf";
exc.retval = zero/zero;
if (_LIB_VERSION == _POSIX_)
errno = EDOM;
else if (!matherr(&exc)) {
/* if (_LIB_VERSION == _SVID_) {
(void) WRITE2("acosh: DOMAIN error\n", 20);
} */
errno = EDOM;
}
break;
case 30:
case 130:
/* atanh(|x|>1) */
exc.type = DOMAIN;
exc.name = type < 100 ? "atanh" : "atanhf";
exc.retval = zero/zero;
if (_LIB_VERSION == _POSIX_)
errno = EDOM;
else if (!matherr(&exc)) {
/* if (_LIB_VERSION == _SVID_) {
(void) WRITE2("atanh: DOMAIN error\n", 20);
} */
errno = EDOM;
}
break;
case 31:
case 131:
/* atanh(|x|=1) */
exc.type = SING;
exc.name = type < 100 ? "atanh" : "atanhf";
exc.retval = x/zero; /* sign(x)*inf */
if (_LIB_VERSION == _POSIX_)
errno = EDOM;
else if (!matherr(&exc)) {
/* if (_LIB_VERSION == _SVID_) {
(void) WRITE2("atanh: SING error\n", 18);
} */
errno = EDOM;
}
break;
case 32:
case 132:
/* scalb overflow; SVID also returns +-HUGE_VAL */
exc.type = OVERFLOW;
exc.name = type < 100 ? "scalb" : "scalbf";
exc.retval = x > zero ? HUGE_VAL : -HUGE_VAL;
if (_LIB_VERSION == _POSIX_)
errno = ERANGE;
else if (!matherr(&exc)) {
errno = ERANGE;
}
break;
case 33:
case 133:
/* scalb underflow */
exc.type = UNDERFLOW;
exc.name = type < 100 ? "scalb" : "scalbf";
exc.retval = copysign(zero,x);
if (_LIB_VERSION == _POSIX_)
errno = ERANGE;
else if (!matherr(&exc)) {
errno = ERANGE;
}
break;
case 34:
case 134:
/* j0(|x|>X_TLOSS) */
exc.type = TLOSS;
exc.name = type < 100 ? "j0" : "j0f";
exc.retval = zero;
if (_LIB_VERSION == _POSIX_)
errno = ERANGE;
else if (!matherr(&exc)) {
/* if (_LIB_VERSION == _SVID_) {
(void) WRITE2(exc.name, 2);
(void) WRITE2(": TLOSS error\n", 14);
} */
errno = ERANGE;
}
break;
case 35:
case 135:
/* y0(x>X_TLOSS) */
exc.type = TLOSS;
exc.name = type < 100 ? "y0" : "y0f";
exc.retval = zero;
if (_LIB_VERSION == _POSIX_)
errno = ERANGE;
else if (!matherr(&exc)) {
/* if (_LIB_VERSION == _SVID_) {
(void) WRITE2(exc.name, 2);
(void) WRITE2(": TLOSS error\n", 14);
} */
errno = ERANGE;
}
break;
case 36:
case 136:
/* j1(|x|>X_TLOSS) */
exc.type = TLOSS;
exc.name = type < 100 ? "j1" : "j1f";
exc.retval = zero;
if (_LIB_VERSION == _POSIX_)
errno = ERANGE;
else if (!matherr(&exc)) {
/* if (_LIB_VERSION == _SVID_) {
(void) WRITE2(exc.name, 2);
(void) WRITE2(": TLOSS error\n", 14);
} */
errno = ERANGE;
}
break;
case 37:
case 137:
/* y1(x>X_TLOSS) */
exc.type = TLOSS;
exc.name = type < 100 ? "y1" : "y1f";
exc.retval = zero;
if (_LIB_VERSION == _POSIX_)
errno = ERANGE;
else if (!matherr(&exc)) {
/* if (_LIB_VERSION == _SVID_) {
(void) WRITE2(exc.name, 2);
(void) WRITE2(": TLOSS error\n", 14);
} */
errno = ERANGE;
}
break;
case 38:
case 138:
/* jn(|x|>X_TLOSS) */
exc.type = TLOSS;
exc.name = type < 100 ? "jn" : "jnf";
exc.retval = zero;
if (_LIB_VERSION == _POSIX_)
errno = ERANGE;
else if (!matherr(&exc)) {
/* if (_LIB_VERSION == _SVID_) {
(void) WRITE2(exc.name, 2);
(void) WRITE2(": TLOSS error\n", 14);
} */
errno = ERANGE;
}
break;
case 39:
case 139:
/* yn(x>X_TLOSS) */
exc.type = TLOSS;
exc.name = type < 100 ? "yn" : "ynf";
exc.retval = zero;
if (_LIB_VERSION == _POSIX_)
errno = ERANGE;
else if (!matherr(&exc)) {
/* if (_LIB_VERSION == _SVID_) {
(void) WRITE2(exc.name, 2);
(void) WRITE2(": TLOSS error\n", 14);
} */
errno = ERANGE;
}
break;
case 40:
case 140:
/* gamma(finite) overflow */
exc.type = OVERFLOW;
exc.name = type < 100 ? "gamma" : "gammaf";
if (_LIB_VERSION == _SVID_)
exc.retval = HUGE;
else
exc.retval = HUGE_VAL;
if (_LIB_VERSION == _POSIX_)
errno = ERANGE;
else if (!matherr(&exc)) {
errno = ERANGE;
}
break;
case 41:
case 141:
/* gamma(-integer) or gamma(0) */
exc.type = SING;
exc.name = type < 100 ? "gamma" : "gammaf";
if (_LIB_VERSION == _SVID_)
exc.retval = HUGE;
else
exc.retval = HUGE_VAL;
if (_LIB_VERSION == _POSIX_)
errno = EDOM;
else if (!matherr(&exc)) {
/* if (_LIB_VERSION == _SVID_) {
(void) WRITE2("gamma: SING error\n", 18);
} */
errno = EDOM;
}
break;
case 42:
case 142:
/* pow(NaN,0.0) */
/* error only if _LIB_VERSION == _SVID_ & _XOPEN_ */
exc.type = DOMAIN;
exc.name = type < 100 ? "pow" : "powf";
exc.retval = x;
if (_LIB_VERSION == _IEEE_ ||
_LIB_VERSION == _POSIX_) exc.retval = 1.0;
else if (!matherr(&exc)) {
errno = EDOM;
}
break;
}
if (exc.err != 0)
errno = exc.err;
return exc.retval;
}
 
 
/programs/develop/libraries/newlib/math/k_tan.c
0,0 → 1,132
 
/* @(#)k_tan.c 5.1 93/09/24 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
/* __kernel_tan( x, y, k )
* kernel tan function on [-pi/4, pi/4], pi/4 ~ 0.7854
* Input x is assumed to be bounded by ~pi/4 in magnitude.
* Input y is the tail of x.
* Input k indicates whether tan (if k=1) or
* -1/tan (if k= -1) is returned.
*
* Algorithm
* 1. Since tan(-x) = -tan(x), we need only to consider positive x.
* 2. if x < 2^-28 (hx<0x3e300000 0), return x with inexact if x!=0.
* 3. tan(x) is approximated by a odd polynomial of degree 27 on
* [0,0.67434]
* 3 27
* tan(x) ~ x + T1*x + ... + T13*x
* where
*
* |tan(x) 2 4 26 | -59.2
* |----- - (1+T1*x +T2*x +.... +T13*x )| <= 2
* | x |
*
* Note: tan(x+y) = tan(x) + tan'(x)*y
* ~ tan(x) + (1+x*x)*y
* Therefore, for better accuracy in computing tan(x+y), let
* 3 2 2 2 2
* r = x *(T2+x *(T3+x *(...+x *(T12+x *T13))))
* then
* 3 2
* tan(x+y) = x + (T1*x + (x *(r+y)+y))
*
* 4. For x in [0.67434,pi/4], let y = pi/4 - x, then
* tan(x) = tan(pi/4-y) = (1-tan(y))/(1+tan(y))
* = 1 - 2*(tan(y) - (tan(y)^2)/(1+tan(y)))
*/
 
#include "fdlibm.h"
 
#ifndef _DOUBLE_IS_32BITS
 
#ifdef __STDC__
static const double
#else
static double
#endif
one = 1.00000000000000000000e+00, /* 0x3FF00000, 0x00000000 */
pio4 = 7.85398163397448278999e-01, /* 0x3FE921FB, 0x54442D18 */
pio4lo= 3.06161699786838301793e-17, /* 0x3C81A626, 0x33145C07 */
T[] = {
3.33333333333334091986e-01, /* 0x3FD55555, 0x55555563 */
1.33333333333201242699e-01, /* 0x3FC11111, 0x1110FE7A */
5.39682539762260521377e-02, /* 0x3FABA1BA, 0x1BB341FE */
2.18694882948595424599e-02, /* 0x3F9664F4, 0x8406D637 */
8.86323982359930005737e-03, /* 0x3F8226E3, 0xE96E8493 */
3.59207910759131235356e-03, /* 0x3F6D6D22, 0xC9560328 */
1.45620945432529025516e-03, /* 0x3F57DBC8, 0xFEE08315 */
5.88041240820264096874e-04, /* 0x3F4344D8, 0xF2F26501 */
2.46463134818469906812e-04, /* 0x3F3026F7, 0x1A8D1068 */
7.81794442939557092300e-05, /* 0x3F147E88, 0xA03792A6 */
7.14072491382608190305e-05, /* 0x3F12B80F, 0x32F0A7E9 */
-1.85586374855275456654e-05, /* 0xBEF375CB, 0xDB605373 */
2.59073051863633712884e-05, /* 0x3EFB2A70, 0x74BF7AD4 */
};
 
#ifdef __STDC__
double __kernel_tan(double x, double y, int iy)
#else
double __kernel_tan(x, y, iy)
double x,y; int iy;
#endif
{
double z,r,v,w,s;
__int32_t ix,hx;
GET_HIGH_WORD(hx,x);
ix = hx&0x7fffffff; /* high word of |x| */
if(ix<0x3e300000) /* x < 2**-28 */
{if((int)x==0) { /* generate inexact */
__uint32_t low;
GET_LOW_WORD(low,x);
if(((ix|low)|(iy+1))==0) return one/fabs(x);
else return (iy==1)? x: -one/x;
}
}
if(ix>=0x3FE59428) { /* |x|>=0.6744 */
if(hx<0) {x = -x; y = -y;}
z = pio4-x;
w = pio4lo-y;
x = z+w; y = 0.0;
}
z = x*x;
w = z*z;
/* Break x^5*(T[1]+x^2*T[2]+...) into
* x^5(T[1]+x^4*T[3]+...+x^20*T[11]) +
* x^5(x^2*(T[2]+x^4*T[4]+...+x^22*[T12]))
*/
r = T[1]+w*(T[3]+w*(T[5]+w*(T[7]+w*(T[9]+w*T[11]))));
v = z*(T[2]+w*(T[4]+w*(T[6]+w*(T[8]+w*(T[10]+w*T[12])))));
s = z*x;
r = y + z*(s*(r+v)+y);
r += T[0]*s;
w = x+r;
if(ix>=0x3FE59428) {
v = (double)iy;
return (double)(1-((hx>>30)&2))*(v-2.0*(x-(w*w/(w+v)-r)));
}
if(iy==1) return w;
else { /* if allow error up to 2 ulp,
simply return -1.0/(x+r) here */
/* compute -1.0/(x+r) accurately */
double a,t;
z = w;
SET_LOW_WORD(z,0);
v = r-(z - x); /* z+v = r+x */
t = a = -1.0/w; /* a = -1.0/w */
SET_LOW_WORD(t,0);
s = 1.0+t*z;
return t+a*(s+t*v);
}
}
 
#endif /* defined(_DOUBLE_IS_32BITS) */
/programs/develop/libraries/newlib/math/kf_cos.c
0,0 → 1,59
/* kf_cos.c -- float version of k_cos.c
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
*/
 
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#include "fdlibm.h"
 
#ifdef __STDC__
static const float
#else
static float
#endif
one = 1.0000000000e+00, /* 0x3f800000 */
C1 = 4.1666667908e-02, /* 0x3d2aaaab */
C2 = -1.3888889225e-03, /* 0xbab60b61 */
C3 = 2.4801587642e-05, /* 0x37d00d01 */
C4 = -2.7557314297e-07, /* 0xb493f27c */
C5 = 2.0875723372e-09, /* 0x310f74f6 */
C6 = -1.1359647598e-11; /* 0xad47d74e */
 
#ifdef __STDC__
float __kernel_cosf(float x, float y)
#else
float __kernel_cosf(x, y)
float x,y;
#endif
{
float a,hz,z,r,qx;
__int32_t ix;
GET_FLOAT_WORD(ix,x);
ix &= 0x7fffffff; /* ix = |x|'s high word*/
if(ix<0x32000000) { /* if x < 2**27 */
if(((int)x)==0) return one; /* generate inexact */
}
z = x*x;
r = z*(C1+z*(C2+z*(C3+z*(C4+z*(C5+z*C6)))));
if(ix < 0x3e99999a) /* if |x| < 0.3 */
return one - ((float)0.5*z - (z*r - x*y));
else {
if(ix > 0x3f480000) { /* x > 0.78125 */
qx = (float)0.28125;
} else {
SET_FLOAT_WORD(qx,ix-0x01000000); /* x/4 */
}
hz = (float)0.5*z-qx;
a = one-qx;
return a - (hz - (z*r-x*y));
}
}
/programs/develop/libraries/newlib/math/kf_rem_pio2.c
0,0 → 1,208
/* kf_rem_pio2.c -- float version of k_rem_pio2.c
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
*/
 
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#include "fdlibm.h"
 
/* In the float version, the input parameter x contains 8 bit
integers, not 24 bit integers. 113 bit precision is not supported. */
 
#ifdef __STDC__
static const int init_jk[] = {4,7,9}; /* initial value for jk */
#else
static int init_jk[] = {4,7,9};
#endif
 
#ifdef __STDC__
static const float PIo2[] = {
#else
static float PIo2[] = {
#endif
1.5703125000e+00, /* 0x3fc90000 */
4.5776367188e-04, /* 0x39f00000 */
2.5987625122e-05, /* 0x37da0000 */
7.5437128544e-08, /* 0x33a20000 */
6.0026650317e-11, /* 0x2e840000 */
7.3896444519e-13, /* 0x2b500000 */
5.3845816694e-15, /* 0x27c20000 */
5.6378512969e-18, /* 0x22d00000 */
8.3009228831e-20, /* 0x1fc40000 */
3.2756352257e-22, /* 0x1bc60000 */
6.3331015649e-25, /* 0x17440000 */
};
 
#ifdef __STDC__
static const float
#else
static float
#endif
zero = 0.0,
one = 1.0,
two8 = 2.5600000000e+02, /* 0x43800000 */
twon8 = 3.9062500000e-03; /* 0x3b800000 */
 
#ifdef __STDC__
int __kernel_rem_pio2f(float *x, float *y, int e0, int nx, int prec, const __int32_t *ipio2)
#else
int __kernel_rem_pio2f(x,y,e0,nx,prec,ipio2)
float x[], y[]; int e0,nx,prec; __int32_t ipio2[];
#endif
{
__int32_t jz,jx,jv,jp,jk,carry,n,iq[20],i,j,k,m,q0,ih;
float z,fw,f[20],fq[20],q[20];
 
/* initialize jk*/
jk = init_jk[prec];
jp = jk;
 
/* determine jx,jv,q0, note that 3>q0 */
jx = nx-1;
jv = (e0-3)/8; if(jv<0) jv=0;
q0 = e0-8*(jv+1);
 
/* set up f[0] to f[jx+jk] where f[jx+jk] = ipio2[jv+jk] */
j = jv-jx; m = jx+jk;
for(i=0;i<=m;i++,j++) f[i] = (j<0)? zero : (float) ipio2[j];
 
/* compute q[0],q[1],...q[jk] */
for (i=0;i<=jk;i++) {
for(j=0,fw=0.0;j<=jx;j++) fw += x[j]*f[jx+i-j]; q[i] = fw;
}
 
jz = jk;
recompute:
/* distill q[] into iq[] reversingly */
for(i=0,j=jz,z=q[jz];j>0;i++,j--) {
fw = (float)((__int32_t)(twon8* z));
iq[i] = (__int32_t)(z-two8*fw);
z = q[j-1]+fw;
}
 
/* compute n */
z = scalbnf(z,(int)q0); /* actual value of z */
z -= (float)8.0*floorf(z*(float)0.125); /* trim off integer >= 8 */
n = (__int32_t) z;
z -= (float)n;
ih = 0;
if(q0>0) { /* need iq[jz-1] to determine n */
i = (iq[jz-1]>>(8-q0)); n += i;
iq[jz-1] -= i<<(8-q0);
ih = iq[jz-1]>>(7-q0);
}
else if(q0==0) ih = iq[jz-1]>>8;
else if(z>=(float)0.5) ih=2;
 
if(ih>0) { /* q > 0.5 */
n += 1; carry = 0;
for(i=0;i<jz ;i++) { /* compute 1-q */
j = iq[i];
if(carry==0) {
if(j!=0) {
carry = 1; iq[i] = 0x100- j;
}
} else iq[i] = 0xff - j;
}
if(q0>0) { /* rare case: chance is 1 in 12 */
switch(q0) {
case 1:
iq[jz-1] &= 0x7f; break;
case 2:
iq[jz-1] &= 0x3f; break;
}
}
if(ih==2) {
z = one - z;
if(carry!=0) z -= scalbnf(one,(int)q0);
}
}
 
/* check if recomputation is needed */
if(z==zero) {
j = 0;
for (i=jz-1;i>=jk;i--) j |= iq[i];
if(j==0) { /* need recomputation */
for(k=1;iq[jk-k]==0;k++); /* k = no. of terms needed */
 
for(i=jz+1;i<=jz+k;i++) { /* add q[jz+1] to q[jz+k] */
f[jx+i] = (float) ipio2[jv+i];
for(j=0,fw=0.0;j<=jx;j++) fw += x[j]*f[jx+i-j];
q[i] = fw;
}
jz += k;
goto recompute;
}
}
 
/* chop off zero terms */
if(z==(float)0.0) {
jz -= 1; q0 -= 8;
while(iq[jz]==0) { jz--; q0-=8;}
} else { /* break z into 8-bit if necessary */
z = scalbnf(z,-(int)q0);
if(z>=two8) {
fw = (float)((__int32_t)(twon8*z));
iq[jz] = (__int32_t)(z-two8*fw);
jz += 1; q0 += 8;
iq[jz] = (__int32_t) fw;
} else iq[jz] = (__int32_t) z ;
}
 
/* convert integer "bit" chunk to floating-point value */
fw = scalbnf(one,(int)q0);
for(i=jz;i>=0;i--) {
q[i] = fw*(float)iq[i]; fw*=twon8;
}
 
/* compute PIo2[0,...,jp]*q[jz,...,0] */
for(i=jz;i>=0;i--) {
for(fw=0.0,k=0;k<=jp&&k<=jz-i;k++) fw += PIo2[k]*q[i+k];
fq[jz-i] = fw;
}
 
/* compress fq[] into y[] */
switch(prec) {
case 0:
fw = 0.0;
for (i=jz;i>=0;i--) fw += fq[i];
y[0] = (ih==0)? fw: -fw;
break;
case 1:
case 2:
fw = 0.0;
for (i=jz;i>=0;i--) fw += fq[i];
y[0] = (ih==0)? fw: -fw;
fw = fq[0]-fw;
for (i=1;i<=jz;i++) fw += fq[i];
y[1] = (ih==0)? fw: -fw;
break;
case 3: /* painful */
for (i=jz;i>0;i--) {
fw = fq[i-1]+fq[i];
fq[i] += fq[i-1]-fw;
fq[i-1] = fw;
}
for (i=jz;i>1;i--) {
fw = fq[i-1]+fq[i];
fq[i] += fq[i-1]-fw;
fq[i-1] = fw;
}
for (fw=0.0,i=jz;i>=2;i--) fw += fq[i];
if(ih==0) {
y[0] = fq[0]; y[1] = fq[1]; y[2] = fw;
} else {
y[0] = -fq[0]; y[1] = -fq[1]; y[2] = -fw;
}
}
return n&7;
}
/programs/develop/libraries/newlib/math/kf_sin.c
0,0 → 1,49
/* kf_sin.c -- float version of k_sin.c
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
*/
 
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#include "fdlibm.h"
 
#ifdef __STDC__
static const float
#else
static float
#endif
half = 5.0000000000e-01,/* 0x3f000000 */
S1 = -1.6666667163e-01, /* 0xbe2aaaab */
S2 = 8.3333337680e-03, /* 0x3c088889 */
S3 = -1.9841270114e-04, /* 0xb9500d01 */
S4 = 2.7557314297e-06, /* 0x3638ef1b */
S5 = -2.5050759689e-08, /* 0xb2d72f34 */
S6 = 1.5896910177e-10; /* 0x2f2ec9d3 */
 
#ifdef __STDC__
float __kernel_sinf(float x, float y, int iy)
#else
float __kernel_sinf(x, y, iy)
float x,y; int iy; /* iy=0 if y is zero */
#endif
{
float z,r,v;
__int32_t ix;
GET_FLOAT_WORD(ix,x);
ix &= 0x7fffffff; /* high word of x */
if(ix<0x32000000) /* |x| < 2**-27 */
{if((int)x==0) return x;} /* generate inexact */
z = x*x;
v = z*x;
r = S2+z*(S3+z*(S4+z*(S5+z*S6)));
if(iy==0) return x+v*(S1+z*r);
else return x-((z*(half*y-v*r)-y)-v*S1);
}
/programs/develop/libraries/newlib/math/kf_tan.c
0,0 → 1,96
/* kf_tan.c -- float version of k_tan.c
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
*/
 
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#include "fdlibm.h"
#ifdef __STDC__
static const float
#else
static float
#endif
one = 1.0000000000e+00, /* 0x3f800000 */
pio4 = 7.8539812565e-01, /* 0x3f490fda */
pio4lo= 3.7748947079e-08, /* 0x33222168 */
T[] = {
3.3333334327e-01, /* 0x3eaaaaab */
1.3333334029e-01, /* 0x3e088889 */
5.3968254477e-02, /* 0x3d5d0dd1 */
2.1869488060e-02, /* 0x3cb327a4 */
8.8632395491e-03, /* 0x3c11371f */
3.5920790397e-03, /* 0x3b6b6916 */
1.4562094584e-03, /* 0x3abede48 */
5.8804126456e-04, /* 0x3a1a26c8 */
2.4646313977e-04, /* 0x398137b9 */
7.8179444245e-05, /* 0x38a3f445 */
7.1407252108e-05, /* 0x3895c07a */
-1.8558637748e-05, /* 0xb79bae5f */
2.5907305826e-05, /* 0x37d95384 */
};
 
#ifdef __STDC__
float __kernel_tanf(float x, float y, int iy)
#else
float __kernel_tanf(x, y, iy)
float x,y; int iy;
#endif
{
float z,r,v,w,s;
__int32_t ix,hx;
GET_FLOAT_WORD(hx,x);
ix = hx&0x7fffffff; /* high word of |x| */
if(ix<0x31800000) /* x < 2**-28 */
{if((int)x==0) { /* generate inexact */
if((ix|(iy+1))==0) return one/fabsf(x);
else return (iy==1)? x: -one/x;
}
}
if(ix>=0x3f2ca140) { /* |x|>=0.6744 */
if(hx<0) {x = -x; y = -y;}
z = pio4-x;
w = pio4lo-y;
x = z+w; y = 0.0;
}
z = x*x;
w = z*z;
/* Break x^5*(T[1]+x^2*T[2]+...) into
* x^5(T[1]+x^4*T[3]+...+x^20*T[11]) +
* x^5(x^2*(T[2]+x^4*T[4]+...+x^22*[T12]))
*/
r = T[1]+w*(T[3]+w*(T[5]+w*(T[7]+w*(T[9]+w*T[11]))));
v = z*(T[2]+w*(T[4]+w*(T[6]+w*(T[8]+w*(T[10]+w*T[12])))));
s = z*x;
r = y + z*(s*(r+v)+y);
r += T[0]*s;
w = x+r;
if(ix>=0x3f2ca140) {
v = (float)iy;
return (float)(1-((hx>>30)&2))*(v-(float)2.0*(x-(w*w/(w+v)-r)));
}
if(iy==1) return w;
else { /* if allow error up to 2 ulp,
simply return -1.0/(x+r) here */
/* compute -1.0/(x+r) accurately */
float a,t;
__int32_t i;
z = w;
GET_FLOAT_WORD(i,z);
SET_FLOAT_WORD(z,i&0xfffff000);
v = r-(z - x); /* z+v = r+x */
t = a = -(float)1.0/w; /* a = -1.0/w */
GET_FLOAT_WORD(i,t);
SET_FLOAT_WORD(t,i&0xfffff000);
s = (float)1.0+t*z;
return t+a*(s+t*v);
}
}
/programs/develop/libraries/newlib/math/local.h
0,0 → 1,0
/* placeholder for future usage. */
/programs/develop/libraries/newlib/math/s_asinh.c
0,0 → 1,107
 
/* @(#)s_asinh.c 5.1 93/09/24 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
/*
FUNCTION
<<asinh>>, <<asinhf>>---inverse hyperbolic sine
 
INDEX
asinh
INDEX
asinhf
 
ANSI_SYNOPSIS
#include <math.h>
double asinh(double <[x]>);
float asinhf(float <[x]>);
 
TRAD_SYNOPSIS
#include <math.h>
double asinh(<[x]>)
double <[x]>;
 
float asinhf(<[x]>)
float <[x]>;
 
DESCRIPTION
<<asinh>> calculates the inverse hyperbolic sine of <[x]>.
<<asinh>> is defined as
@ifnottex
. sgn(<[x]>) * log(abs(<[x]>) + sqrt(1+<[x]>*<[x]>))
@end ifnottex
@tex
$$sign(x) \times ln\Bigl(|x| + \sqrt{1+x^2}\Bigr)$$
@end tex
 
<<asinhf>> is identical, other than taking and returning floats.
 
RETURNS
<<asinh>> and <<asinhf>> return the calculated value.
 
PORTABILITY
Neither <<asinh>> nor <<asinhf>> are ANSI C.
 
*/
 
/* asinh(x)
* Method :
* Based on
* asinh(x) = sign(x) * log [ |x| + sqrt(x*x+1) ]
* we have
* asinh(x) := x if 1+x*x=1,
* := sign(x)*(log(x)+ln2)) for large |x|, else
* := sign(x)*log(2|x|+1/(|x|+sqrt(x*x+1))) if|x|>2, else
* := sign(x)*log1p(|x| + x^2/(1 + sqrt(1+x^2)))
*/
 
#include "fdlibm.h"
 
#ifndef _DOUBLE_IS_32BITS
 
#ifdef __STDC__
static const double
#else
static double
#endif
one = 1.00000000000000000000e+00, /* 0x3FF00000, 0x00000000 */
ln2 = 6.93147180559945286227e-01, /* 0x3FE62E42, 0xFEFA39EF */
huge= 1.00000000000000000000e+300;
 
#ifdef __STDC__
double asinh(double x)
#else
double asinh(x)
double x;
#endif
{
double t,w;
__int32_t hx,ix;
GET_HIGH_WORD(hx,x);
ix = hx&0x7fffffff;
if(ix>=0x7ff00000) return x+x; /* x is inf or NaN */
if(ix< 0x3e300000) { /* |x|<2**-28 */
if(huge+x>one) return x; /* return x inexact except 0 */
}
if(ix>0x41b00000) { /* |x| > 2**28 */
w = __ieee754_log(fabs(x))+ln2;
} else if (ix>0x40000000) { /* 2**28 > |x| > 2.0 */
t = fabs(x);
w = __ieee754_log(2.0*t+one/(__ieee754_sqrt(x*x+one)+t));
} else { /* 2.0 > |x| > 2**-28 */
t = x*x;
w =log1p(fabs(x)+t/(one+__ieee754_sqrt(one+t)));
}
if(hx>0) return w; else return -w;
}
 
#endif /* _DOUBLE_IS_32BITS */
/programs/develop/libraries/newlib/math/s_atan.c
0,0 → 1,181
 
/* @(#)s_atan.c 5.1 93/09/24 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*
*/
 
/*
FUNCTION
<<atan>>, <<atanf>>---arc tangent
 
INDEX
atan
INDEX
atanf
 
ANSI_SYNOPSIS
#include <math.h>
double atan(double <[x]>);
float atanf(float <[x]>);
 
TRAD_SYNOPSIS
#include <math.h>
double atan(<[x]>);
double <[x]>;
 
float atanf(<[x]>);
float <[x]>;
 
DESCRIPTION
 
<<atan>> computes the inverse tangent (arc tangent) of the input value.
 
<<atanf>> is identical to <<atan>>, save that it operates on <<floats>>.
 
RETURNS
@ifnottex
<<atan>> returns a value in radians, in the range of -pi/2 to pi/2.
@end ifnottex
@tex
<<atan>> returns a value in radians, in the range of $-\pi/2$ to $\pi/2$.
@end tex
 
PORTABILITY
<<atan>> is ANSI C. <<atanf>> is an extension.
 
*/
 
/* atan(x)
* Method
* 1. Reduce x to positive by atan(x) = -atan(-x).
* 2. According to the integer k=4t+0.25 chopped, t=x, the argument
* is further reduced to one of the following intervals and the
* arctangent of t is evaluated by the corresponding formula:
*
* [0,7/16] atan(x) = t-t^3*(a1+t^2*(a2+...(a10+t^2*a11)...)
* [7/16,11/16] atan(x) = atan(1/2) + atan( (t-0.5)/(1+t/2) )
* [11/16.19/16] atan(x) = atan( 1 ) + atan( (t-1)/(1+t) )
* [19/16,39/16] atan(x) = atan(3/2) + atan( (t-1.5)/(1+1.5t) )
* [39/16,INF] atan(x) = atan(INF) + atan( -1/t )
*
* Constants:
* The hexadecimal values are the intended ones for the following
* constants. The decimal values may be used, provided that the
* compiler will convert from decimal to binary accurately enough
* to produce the hexadecimal values shown.
*/
 
#include "fdlibm.h"
 
#ifndef _DOUBLE_IS_32BITS
 
#ifdef __STDC__
static const double atanhi[] = {
#else
static double atanhi[] = {
#endif
4.63647609000806093515e-01, /* atan(0.5)hi 0x3FDDAC67, 0x0561BB4F */
7.85398163397448278999e-01, /* atan(1.0)hi 0x3FE921FB, 0x54442D18 */
9.82793723247329054082e-01, /* atan(1.5)hi 0x3FEF730B, 0xD281F69B */
1.57079632679489655800e+00, /* atan(inf)hi 0x3FF921FB, 0x54442D18 */
};
 
#ifdef __STDC__
static const double atanlo[] = {
#else
static double atanlo[] = {
#endif
2.26987774529616870924e-17, /* atan(0.5)lo 0x3C7A2B7F, 0x222F65E2 */
3.06161699786838301793e-17, /* atan(1.0)lo 0x3C81A626, 0x33145C07 */
1.39033110312309984516e-17, /* atan(1.5)lo 0x3C700788, 0x7AF0CBBD */
6.12323399573676603587e-17, /* atan(inf)lo 0x3C91A626, 0x33145C07 */
};
 
#ifdef __STDC__
static const double aT[] = {
#else
static double aT[] = {
#endif
3.33333333333329318027e-01, /* 0x3FD55555, 0x5555550D */
-1.99999999998764832476e-01, /* 0xBFC99999, 0x9998EBC4 */
1.42857142725034663711e-01, /* 0x3FC24924, 0x920083FF */
-1.11111104054623557880e-01, /* 0xBFBC71C6, 0xFE231671 */
9.09088713343650656196e-02, /* 0x3FB745CD, 0xC54C206E */
-7.69187620504482999495e-02, /* 0xBFB3B0F2, 0xAF749A6D */
6.66107313738753120669e-02, /* 0x3FB10D66, 0xA0D03D51 */
-5.83357013379057348645e-02, /* 0xBFADDE2D, 0x52DEFD9A */
4.97687799461593236017e-02, /* 0x3FA97B4B, 0x24760DEB */
-3.65315727442169155270e-02, /* 0xBFA2B444, 0x2C6A6C2F */
1.62858201153657823623e-02, /* 0x3F90AD3A, 0xE322DA11 */
};
 
#ifdef __STDC__
static const double
#else
static double
#endif
one = 1.0,
huge = 1.0e300;
 
#ifdef __STDC__
double atan(double x)
#else
double atan(x)
double x;
#endif
{
double w,s1,s2,z;
__int32_t ix,hx,id;
 
GET_HIGH_WORD(hx,x);
ix = hx&0x7fffffff;
if(ix>=0x44100000) { /* if |x| >= 2^66 */
__uint32_t low;
GET_LOW_WORD(low,x);
if(ix>0x7ff00000||
(ix==0x7ff00000&&(low!=0)))
return x+x; /* NaN */
if(hx>0) return atanhi[3]+atanlo[3];
else return -atanhi[3]-atanlo[3];
} if (ix < 0x3fdc0000) { /* |x| < 0.4375 */
if (ix < 0x3e200000) { /* |x| < 2^-29 */
if(huge+x>one) return x; /* raise inexact */
}
id = -1;
} else {
x = fabs(x);
if (ix < 0x3ff30000) { /* |x| < 1.1875 */
if (ix < 0x3fe60000) { /* 7/16 <=|x|<11/16 */
id = 0; x = (2.0*x-one)/(2.0+x);
} else { /* 11/16<=|x|< 19/16 */
id = 1; x = (x-one)/(x+one);
}
} else {
if (ix < 0x40038000) { /* |x| < 2.4375 */
id = 2; x = (x-1.5)/(one+1.5*x);
} else { /* 2.4375 <= |x| < 2^66 */
id = 3; x = -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;
}
}
 
#endif /* _DOUBLE_IS_32BITS */
/programs/develop/libraries/newlib/math/s_cbrt.c
0,0 → 1,123
 
/* @(#)s_cbrt.c 5.1 93/09/24 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*
*/
 
/*
FUNCTION
<<cbrt>>, <<cbrtf>>---cube root
 
INDEX
cbrt
INDEX
cbrtf
 
ANSI_SYNOPSIS
#include <math.h>
double cbrt(double <[x]>);
float cbrtf(float <[x]>);
 
TRAD_SYNOPSIS
#include <math.h>
double cbrt(<[x]>);
float cbrtf(<[x]>);
 
DESCRIPTION
<<cbrt>> computes the cube root of the argument.
 
RETURNS
The cube root is returned.
 
PORTABILITY
<<cbrt>> is in System V release 4. <<cbrtf>> is an extension.
*/
 
#include "fdlibm.h"
 
#ifndef _DOUBLE_IS_32BITS
 
/* cbrt(x)
* Return cube root of x
*/
#ifdef __STDC__
static const __uint32_t
#else
static __uint32_t
#endif
B1 = 715094163, /* B1 = (682-0.03306235651)*2**20 */
B2 = 696219795; /* B2 = (664-0.03306235651)*2**20 */
 
#ifdef __STDC__
static const double
#else
static double
#endif
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 */
 
#ifdef __STDC__
double cbrt(double x)
#else
double cbrt(x)
double x;
#endif
{
__int32_t hx;
double r,s,t=0.0,w;
__uint32_t sign;
__uint32_t high,low;
 
GET_HIGH_WORD(hx,x);
sign=hx&0x80000000; /* 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);
}
 
#endif /* _DOUBLE_IS_32BITS */
/programs/develop/libraries/newlib/math/s_ceil.c
0,0 → 1,80
 
/* @(#)s_ceil.c 5.1 93/09/24 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
/*
* ceil(x)
* Return x rounded toward -inf to integral value
* Method:
* Bit twiddling.
* Exception:
* Inexact flag raised if x not equal to ceil(x).
*/
 
#include "fdlibm.h"
 
#ifndef _DOUBLE_IS_32BITS
 
#ifdef __STDC__
static const double huge = 1.0e300;
#else
static double huge = 1.0e300;
#endif
 
#ifdef __STDC__
double ceil(double x)
#else
double ceil(x)
double x;
#endif
{
__int32_t i0,i1,j0;
__uint32_t i,j;
EXTRACT_WORDS(i0,i1,x);
j0 = ((i0>>20)&0x7ff)-0x3ff;
if(j0<20) {
if(j0<0) { /* raise inexact if x != 0 */
if(huge+x>0.0) {/* return 0*sign(x) if |x|<1 */
if(i0<0) {i0=0x80000000;i1=0;}
else if((i0|i1)!=0) { i0=0x3ff00000;i1=0;}
}
} else {
i = (0x000fffff)>>j0;
if(((i0&i)|i1)==0) return x; /* x is integral */
if(huge+x>0.0) { /* raise inexact flag */
if(i0>0) i0 += (0x00100000)>>j0;
i0 &= (~i); i1=0;
}
}
} else if (j0>51) {
if(j0==0x400) return x+x; /* inf or NaN */
else return x; /* x is integral */
} else {
i = ((__uint32_t)(0xffffffff))>>(j0-20);
if((i1&i)==0) return x; /* x is integral */
if(huge+x>0.0) { /* raise inexact flag */
if(i0>0) {
if(j0==20) i0+=1;
else {
j = i1 + (1<<(52-j0));
if(j<i1) i0+=1; /* got a carry */
i1 = j;
}
}
i1 &= (~i);
}
}
INSERT_WORDS(x,i0,i1);
return x;
}
 
#endif /* _DOUBLE_IS_32BITS */
/programs/develop/libraries/newlib/math/s_copysign.c
0,0 → 1,82
 
/* @(#)s_copysign.c 5.1 93/09/24 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
/*
FUNCTION
<<copysign>>, <<copysignf>>---sign of <[y]>, magnitude of <[x]>
 
INDEX
copysign
INDEX
copysignf
 
ANSI_SYNOPSIS
#include <math.h>
double copysign (double <[x]>, double <[y]>);
float copysignf (float <[x]>, float <[y]>);
 
TRAD_SYNOPSIS
#include <math.h>
double copysign (<[x]>, <[y]>)
double <[x]>;
double <[y]>;
 
float copysignf (<[x]>, <[y]>)
float <[x]>;
float <[y]>;
 
DESCRIPTION
<<copysign>> constructs a number with the magnitude (absolute value)
of its first argument, <[x]>, and the sign of its second argument,
<[y]>.
 
<<copysignf>> does the same thing; the two functions differ only in
the type of their arguments and result.
 
RETURNS
<<copysign>> returns a <<double>> with the magnitude of
<[x]> and the sign of <[y]>.
<<copysignf>> returns a <<float>> with the magnitude of
<[x]> and the sign of <[y]>.
 
PORTABILITY
<<copysign>> is not required by either ANSI C or the System V Interface
Definition (Issue 2).
 
*/
 
/*
* copysign(double x, double y)
* copysign(x,y) returns a value with the magnitude of x and
* with the sign bit of y.
*/
 
#include "fdlibm.h"
 
#ifndef _DOUBLE_IS_32BITS
 
#ifdef __STDC__
double copysign(double x, double y)
#else
double copysign(x,y)
double x,y;
#endif
{
__uint32_t hx,hy;
GET_HIGH_WORD(hx,x);
GET_HIGH_WORD(hy,y);
SET_HIGH_WORD(x,(hx&0x7fffffff)|(hy&0x80000000));
return x;
}
 
#endif /* _DOUBLE_IS_32BITS */
/programs/develop/libraries/newlib/math/s_cos.c
0,0 → 1,82
 
/* @(#)s_cos.c 5.1 93/09/24 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
/* cos(x)
* Return cosine function of x.
*
* kernel function:
* __kernel_sin ... sine function on [-pi/4,pi/4]
* __kernel_cos ... cosine function on [-pi/4,pi/4]
* __ieee754_rem_pio2 ... argument reduction routine
*
* Method.
* Let S,C and T denote the sin, cos and tan respectively on
* [-PI/4, +PI/4]. Reduce the argument x to y1+y2 = x-k*pi/2
* in [-pi/4 , +pi/4], and let n = k mod 4.
* We have
*
* n sin(x) cos(x) tan(x)
* ----------------------------------------------------------
* 0 S C T
* 1 C -S -1/T
* 2 -S -C T
* 3 -C S -1/T
* ----------------------------------------------------------
*
* Special cases:
* Let trig be any of sin, cos, or tan.
* trig(+-INF) is NaN, with signals;
* trig(NaN) is that NaN;
*
* Accuracy:
* TRIG(x) returns trig(x) nearly rounded
*/
 
#include "fdlibm.h"
 
#ifndef _DOUBLE_IS_32BITS
 
#ifdef __STDC__
double cos(double x)
#else
double cos(x)
double x;
#endif
{
double y[2],z=0.0;
__int32_t n,ix;
 
/* High word of x. */
GET_HIGH_WORD(ix,x);
 
/* |x| ~< pi/4 */
ix &= 0x7fffffff;
if(ix <= 0x3fe921fb) return __kernel_cos(x,z);
 
/* cos(Inf or NaN) is NaN */
else if (ix>=0x7ff00000) return x-x;
 
/* argument reduction needed */
else {
n = __ieee754_rem_pio2(x,y);
switch(n&3) {
case 0: return __kernel_cos(y[0],y[1]);
case 1: return -__kernel_sin(y[0],y[1],1);
case 2: return -__kernel_cos(y[0],y[1]);
default:
return __kernel_sin(y[0],y[1],1);
}
}
}
 
#endif /* _DOUBLE_IS_32BITS */
/programs/develop/libraries/newlib/math/s_erf.c
1,10 → 1,10
 
/* @(#)s_erf.c 1.3 95/01/18 */
/* @(#)s_erf.c 5.1 93/09/24 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunSoft, a Sun Microsystems, Inc. business.
* 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.
11,6 → 11,65
* ====================================================
*/
 
/*
FUNCTION
<<erf>>, <<erff>>, <<erfc>>, <<erfcf>>---error function
INDEX
erf
INDEX
erff
INDEX
erfc
INDEX
erfcf
 
ANSI_SYNOPSIS
#include <math.h>
double erf(double <[x]>);
float erff(float <[x]>);
double erfc(double <[x]>);
float erfcf(float <[x]>);
TRAD_SYNOPSIS
#include <math.h>
 
double erf(<[x]>)
double <[x]>;
 
float erff(<[x]>)
float <[x]>;
 
double erfc(<[x]>)
double <[x]>;
 
float erfcf(<[x]>)
float <[x]>;
 
DESCRIPTION
<<erf>> calculates an approximation to the ``error function'',
which estimates the probability that an observation will fall within
<[x]> standard deviations of the mean (assuming a normal
distribution).
@tex
The error function is defined as
$${2\over\sqrt\pi}\times\int_0^x e^{-t^2}dt$$
@end tex
 
<<erfc>> calculates the complementary probability; that is,
<<erfc(<[x]>)>> is <<1 - erf(<[x]>)>>. <<erfc>> is computed directly,
so that you can use it to avoid the loss of precision that would
result from subtracting large probabilities (on large <[x]>) from 1.
 
<<erff>> and <<erfcf>> differ from <<erf>> and <<erfc>> only in the
argument and result types.
 
RETURNS
For positive arguments, <<erf>> and all its variants return a
probability---a number between 0 and 1.
 
PORTABILITY
None of the variants of <<erf>> are ANSI C.
*/
 
/* double erf(double x)
* double erfc(double x)
* x
106,41 → 165,10
*/
 
 
/* #include "fdlibm.h" */
#include "fdlibm.h"
 
#include <math.h>
#include <stdint.h>
#include <errno.h>
#ifndef _DOUBLE_IS_32BITS
 
#define __ieee754_exp exp
 
typedef union
{
double value;
struct
{
uint32_t lsw;
uint32_t msw;
} parts;
} ieee_double_shape_type;
 
 
static inline int __get_hi_word(const double x)
{
ieee_double_shape_type u;
u.value = x;
return u.parts.msw;
}
 
static inline void __trunc_lo_word(double *x)
{
ieee_double_shape_type u;
u.value = *x;
u.parts.lsw = 0;
*x = u.value;
}
 
 
#ifdef __STDC__
static const double
#else
227,12 → 255,12
double x;
#endif
{
int hx,ix,i;
__int32_t hx,ix,i;
double R,S,P,Q,s,y,z,r;
hx = __get_hi_word(x);
GET_HIGH_WORD(hx,x);
ix = hx&0x7fffffff;
if(ix>=0x7ff00000) { /* erf(nan)=nan */
i = ((unsigned)hx>>31)<<1;
i = ((__uint32_t)hx>>31)<<1;
return (double)(1-i)+one/x; /* erf(+-inf)=+-1 */
}
 
271,7 → 299,7
sb5+s*(sb6+s*sb7))))));
}
z = x;
__trunc_lo_word(&z);
SET_LOW_WORD(z,0);
r = __ieee754_exp(-z*z-0.5625)*__ieee754_exp((z-x)*(z+x)+R/S);
if(hx>=0) return one-r/x; else return r/x-one;
}
283,13 → 311,13
double x;
#endif
{
int hx,ix;
__int32_t hx,ix;
double R,S,P,Q,s,y,z,r;
hx = __get_hi_word(x);
GET_HIGH_WORD(hx,x);
ix = hx&0x7fffffff;
if(ix>=0x7ff00000) { /* erfc(nan)=nan */
/* erfc(+-inf)=0,2 */
return (double)(((unsigned)hx>>31)<<1)+one/x;
return (double)(((__uint32_t)hx>>31)<<1)+one/x;
}
 
if(ix < 0x3feb0000) { /* |x|<0.84375 */
333,13 → 361,13
sb5+s*(sb6+s*sb7))))));
}
z = x;
__trunc_lo_word(&z);
SET_LOW_WORD(z,0);
r = __ieee754_exp(-z*z-0.5625)*
__ieee754_exp((z-x)*(z+x)+R/S);
if(hx>0) return r/x; else return two-r/x;
} else {
/* set range error */
errno = ERANGE;
if(hx>0) return tiny*tiny; else return two-tiny;
}
}
 
#endif /* _DOUBLE_IS_32BITS */
/programs/develop/libraries/newlib/math/s_exp10.c
0,0 → 1,80
/* @(#)s_exp10.c 5.1 93/09/24 */
/* Modified from s_exp2.c by Yaakov Selkowitz 2007. */
 
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
/*
FUNCTION
<<exp10>>, <<exp10f>>---exponential
INDEX
exp10
INDEX
exp10f
 
ANSI_SYNOPSIS
#include <math.h>
double exp10(double <[x]>);
float exp10f(float <[x]>);
 
TRAD_SYNOPSIS
#include <math.h>
double exp10(<[x]>);
double <[x]>;
 
float exp10f(<[x]>);
float <[x]>;
 
DESCRIPTION
<<exp10>> and <<exp10f>> calculate 10 ^ <[x]>, that is,
@ifnottex
10 raised to the power <[x]>.
@end ifnottex
@tex
$10^x$
@end tex
 
You can use the (non-ANSI) function <<matherr>> to specify
error handling for these functions.
 
RETURNS
On success, <<exp10>> and <<exp10f>> return the calculated value.
If the result underflows, the returned value is <<0>>. If the
result overflows, the returned value is <<HUGE_VAL>>. In
either case, <<errno>> is set to <<ERANGE>>.
 
PORTABILITY
<<exp10>> and <<exp10f>> are GNU extensions.
 
*/
 
/*
* wrapper exp10(x)
*/
 
#undef exp10
#include "fdlibm.h"
#include <errno.h>
#include <math.h>
 
#ifndef _DOUBLE_IS_32BITS
 
#ifdef __STDC__
double exp10(double x) /* wrapper exp10 */
#else
double exp10(x) /* wrapper exp10 */
double x;
#endif
{
return pow(10.0, x);
}
 
#endif /* defined(_DOUBLE_IS_32BITS) */
/programs/develop/libraries/newlib/math/s_expm1.c
0,0 → 1,272
 
/* @(#)s_expm1.c 5.1 93/09/24 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
/*
FUNCTION
<<expm1>>, <<expm1f>>---exponential minus 1
INDEX
expm1
INDEX
expm1f
 
ANSI_SYNOPSIS
#include <math.h>
double expm1(double <[x]>);
float expm1f(float <[x]>);
 
TRAD_SYNOPSIS
#include <math.h>
double expm1(<[x]>);
double <[x]>;
 
float expm1f(<[x]>);
float <[x]>;
 
DESCRIPTION
<<expm1>> and <<expm1f>> calculate the exponential of <[x]>
and subtract 1, that is,
@ifnottex
e raised to the power <[x]> minus 1 (where e
@end ifnottex
@tex
$e^x - 1$ (where $e$
@end tex
is the base of the natural system of logarithms, approximately
2.71828). The result is accurate even for small values of
<[x]>, where using <<exp(<[x]>)-1>> would lose many
significant digits.
 
RETURNS
e raised to the power <[x]>, minus 1.
 
PORTABILITY
Neither <<expm1>> nor <<expm1f>> is required by ANSI C or by
the System V Interface Definition (Issue 2).
*/
 
/* expm1(x)
* Returns exp(x)-1, the exponential of x minus 1.
*
* Method
* 1. Argument reduction:
* Given x, find r and integer k such that
*
* x = k*ln2 + r, |r| <= 0.5*ln2 ~ 0.34658
*
* Here a correction term c will be computed to compensate
* the error in r when rounded to a floating-point number.
*
* 2. Approximating expm1(r) by a special rational function on
* the interval [0,0.34658]:
* Since
* r*(exp(r)+1)/(exp(r)-1) = 2+ r^2/6 - r^4/360 + ...
* we define R1(r*r) by
* r*(exp(r)+1)/(exp(r)-1) = 2+ r^2/6 * R1(r*r)
* That is,
* R1(r**2) = 6/r *((exp(r)+1)/(exp(r)-1) - 2/r)
* = 6/r * ( 1 + 2.0*(1/(exp(r)-1) - 1/r))
* = 1 - r^2/60 + r^4/2520 - r^6/100800 + ...
* We use a special Reme algorithm on [0,0.347] to generate
* a polynomial of degree 5 in r*r to approximate R1. The
* maximum error of this polynomial approximation is bounded
* by 2**-61. In other words,
* R1(z) ~ 1.0 + Q1*z + Q2*z**2 + Q3*z**3 + Q4*z**4 + Q5*z**5
* where Q1 = -1.6666666666666567384E-2,
* Q2 = 3.9682539681370365873E-4,
* Q3 = -9.9206344733435987357E-6,
* Q4 = 2.5051361420808517002E-7,
* Q5 = -6.2843505682382617102E-9;
* (where z=r*r, and the values of Q1 to Q5 are listed below)
* with error bounded by
* | 5 | -61
* | 1.0+Q1*z+...+Q5*z - R1(z) | <= 2
* | |
*
* expm1(r) = exp(r)-1 is then computed by the following
* specific way which minimize the accumulation rounding error:
* 2 3
* r r [ 3 - (R1 + R1*r/2) ]
* expm1(r) = r + --- + --- * [--------------------]
* 2 2 [ 6 - r*(3 - R1*r/2) ]
*
* To compensate the error in the argument reduction, we use
* expm1(r+c) = expm1(r) + c + expm1(r)*c
* ~ expm1(r) + c + r*c
* Thus c+r*c will be added in as the correction terms for
* expm1(r+c). Now rearrange the term to avoid optimization
* screw up:
* ( 2 2 )
* ({ ( r [ R1 - (3 - R1*r/2) ] ) } r )
* expm1(r+c)~r - ({r*(--- * [--------------------]-c)-c} - --- )
* ({ ( 2 [ 6 - r*(3 - R1*r/2) ] ) } 2 )
* ( )
*
* = r - E
* 3. Scale back to obtain expm1(x):
* From step 1, we have
* expm1(x) = either 2^k*[expm1(r)+1] - 1
* = or 2^k*[expm1(r) + (1-2^-k)]
* 4. Implementation notes:
* (A). To save one multiplication, we scale the coefficient Qi
* to Qi*2^i, and replace z by (x^2)/2.
* (B). To achieve maximum accuracy, we compute expm1(x) by
* (i) if x < -56*ln2, return -1.0, (raise inexact if x!=inf)
* (ii) if k=0, return r-E
* (iii) if k=-1, return 0.5*(r-E)-0.5
* (iv) if k=1 if r < -0.25, return 2*((r+0.5)- E)
* else return 1.0+2.0*(r-E);
* (v) if (k<-2||k>56) return 2^k(1-(E-r)) - 1 (or exp(x)-1)
* (vi) if k <= 20, return 2^k((1-2^-k)-(E-r)), else
* (vii) return 2^k(1-((E+2^-k)-r))
*
* Special cases:
* expm1(INF) is INF, expm1(NaN) is NaN;
* expm1(-INF) is -1, and
* for finite argument, only expm1(0)=0 is exact.
*
* Accuracy:
* according to an error analysis, the error is always less than
* 1 ulp (unit in the last place).
*
* Misc. info.
* For IEEE double
* if x > 7.09782712893383973096e+02 then expm1(x) overflow
*
* Constants:
* The hexadecimal values are the intended ones for the following
* constants. The decimal values may be used, provided that the
* compiler will convert from decimal to binary accurately enough
* to produce the hexadecimal values shown.
*/
 
#include "fdlibm.h"
 
#ifndef _DOUBLE_IS_32BITS
 
#ifdef __STDC__
static const double
#else
static double
#endif
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 */
 
#ifdef __STDC__
double expm1(double x)
#else
double expm1(x)
double x;
#endif
{
double y,hi,lo,c,t,e,hxs,hfx,r1;
__int32_t k,xsb;
__uint32_t hx;
 
GET_HIGH_WORD(hx,x);
xsb = hx&0x80000000; /* 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) {
__uint32_t 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 */
__uint32_t 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) {
__uint32_t 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 {
__uint32_t 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;
}
 
#endif /* _DOUBLE_IS_32BITS */
/programs/develop/libraries/newlib/math/s_fabs.c
0,0 → 1,73
 
/* @(#)s_fabs.c 5.1 93/09/24 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
/*
FUNCTION
<<fabs>>, <<fabsf>>---absolute value (magnitude)
INDEX
fabs
INDEX
fabsf
 
ANSI_SYNOPSIS
#include <math.h>
double fabs(double <[x]>);
float fabsf(float <[x]>);
 
TRAD_SYNOPSIS
#include <math.h>
double fabs(<[x]>)
double <[x]>;
 
float fabsf(<[x]>)
float <[x]>;
 
DESCRIPTION
<<fabs>> and <<fabsf>> calculate
@tex
$|x|$,
@end tex
the absolute value (magnitude) of the argument <[x]>, by direct
manipulation of the bit representation of <[x]>.
 
RETURNS
The calculated value is returned. No errors are detected.
 
PORTABILITY
<<fabs>> is ANSI.
<<fabsf>> is an extension.
 
*/
 
/*
* fabs(x) returns the absolute value of x.
*/
 
#include "fdlibm.h"
 
#ifndef _DOUBLE_IS_32BITS
 
#ifdef __STDC__
double fabs(double x)
#else
double fabs(x)
double x;
#endif
{
__uint32_t high;
GET_HIGH_WORD(high,x);
SET_HIGH_WORD(x,high&0x7fffffff);
return x;
}
 
#endif /* _DOUBLE_IS_32BITS */
/programs/develop/libraries/newlib/math/s_fdim.c
0,0 → 1,61
/* Copyright (C) 2002 by Red Hat, Incorporated. All rights reserved.
*
* Permission to use, copy, modify, and distribute this software
* is freely granted, provided that this notice is preserved.
*/
/*
FUNCTION
<<fdim>>, <<fdimf>>--positive difference
INDEX
fdim
INDEX
fdimf
 
ANSI_SYNOPSIS
#include <math.h>
double fdim(double <[x]>, double <[y]>);
float fdimf(float <[x]>, float <[y]>);
 
DESCRIPTION
The <<fdim>> functions determine the positive difference between their
arguments, returning:
. <[x]> - <[y]> if <[x]> > <[y]>, or
@ifnottex
. +0 if <[x]> <= <[y]>, or
@end ifnottex
@tex
. +0 if <[x]> $\leq$ <[y]>, or
@end tex
. NAN if either argument is NAN.
A range error may occur.
 
RETURNS
The <<fdim>> functions return the positive difference value.
 
PORTABILITY
ANSI C, POSIX.
 
*/
 
#include "fdlibm.h"
 
#ifndef _DOUBLE_IS_32BITS
 
#ifdef __STDC__
double fdim(double x, double y)
#else
double fdim(x,y)
double x;
double y;
#endif
{
int c = __fpclassifyd(x);
if (c == FP_NAN) return(x);
if (__fpclassifyd(y) == FP_NAN) return(y);
if (c == FP_INFINITE)
return HUGE_VAL;
 
return x > y ? x - y : 0.0;
}
 
#endif /* _DOUBLE_IS_32BITS */
/programs/develop/libraries/newlib/math/s_finite.c
0,0 → 1,35
 
/* @(#)s_finite.c 5.1 93/09/24 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
/*
* finite(x) returns 1 is x is finite, else 0;
* no branching!
*/
 
#include "fdlibm.h"
 
#ifndef _DOUBLE_IS_32BITS
 
#ifdef __STDC__
int finite(double x)
#else
int finite(x)
double x;
#endif
{
__int32_t hx;
GET_HIGH_WORD(hx,x);
return (int)((__uint32_t)((hx&0x7fffffff)-0x7ff00000)>>31);
}
 
#endif /* _DOUBLE_IS_32BITS */
/programs/develop/libraries/newlib/math/s_floor.c
0,0 → 1,134
 
/* @(#)s_floor.c 5.1 93/09/24 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
/*
FUNCTION
<<floor>>, <<floorf>>, <<ceil>>, <<ceilf>>---floor and ceiling
INDEX
floor
INDEX
floorf
INDEX
ceil
INDEX
ceilf
 
ANSI_SYNOPSIS
#include <math.h>
double floor(double <[x]>);
float floorf(float <[x]>);
double ceil(double <[x]>);
float ceilf(float <[x]>);
 
TRAD_SYNOPSIS
#include <math.h>
double floor(<[x]>)
double <[x]>;
float floorf(<[x]>)
float <[x]>;
double ceil(<[x]>)
double <[x]>;
float ceilf(<[x]>)
float <[x]>;
 
DESCRIPTION
<<floor>> and <<floorf>> find
@tex
$\lfloor x \rfloor$,
@end tex
the nearest integer less than or equal to <[x]>.
<<ceil>> and <<ceilf>> find
@tex
$\lceil x\rceil$,
@end tex
the nearest integer greater than or equal to <[x]>.
 
RETURNS
<<floor>> and <<ceil>> return the integer result as a double.
<<floorf>> and <<ceilf>> return the integer result as a float.
 
PORTABILITY
<<floor>> and <<ceil>> are ANSI.
<<floorf>> and <<ceilf>> are extensions.
 
 
*/
 
/*
* floor(x)
* Return x rounded toward -inf to integral value
* Method:
* Bit twiddling.
* Exception:
* Inexact flag raised if x not equal to floor(x).
*/
 
#include "fdlibm.h"
 
#ifndef _DOUBLE_IS_32BITS
 
#ifdef __STDC__
static const double huge = 1.0e300;
#else
static double huge = 1.0e300;
#endif
 
#ifdef __STDC__
double floor(double x)
#else
double floor(x)
double x;
#endif
{
__int32_t i0,i1,j0;
__uint32_t i,j;
EXTRACT_WORDS(i0,i1,x);
j0 = ((i0>>20)&0x7ff)-0x3ff;
if(j0<20) {
if(j0<0) { /* raise inexact if x != 0 */
if(huge+x>0.0) {/* return 0*sign(x) if |x|<1 */
if(i0>=0) {i0=i1=0;}
else if(((i0&0x7fffffff)|i1)!=0)
{ i0=0xbff00000;i1=0;}
}
} else {
i = (0x000fffff)>>j0;
if(((i0&i)|i1)==0) return x; /* x is integral */
if(huge+x>0.0) { /* raise inexact flag */
if(i0<0) i0 += (0x00100000)>>j0;
i0 &= (~i); i1=0;
}
}
} else if (j0>51) {
if(j0==0x400) return x+x; /* inf or NaN */
else return x; /* x is integral */
} else {
i = ((__uint32_t)(0xffffffff))>>(j0-20);
if((i1&i)==0) return x; /* x is integral */
if(huge+x>0.0) { /* raise inexact flag */
if(i0<0) {
if(j0==20) i0+=1;
else {
j = i1+(1<<(52-j0));
if(j<i1) i0 +=1 ; /* got a carry */
i1=j;
}
}
i1 &= (~i);
}
}
INSERT_WORDS(x,i0,i1);
return x;
}
 
#endif /* _DOUBLE_IS_32BITS */
/programs/develop/libraries/newlib/math/s_fma.c
0,0 → 1,56
/*
FUNCTION
<<fma>>, <<fmaf>>--floating multiply add
INDEX
fma
INDEX
fmaf
 
ANSI_SYNOPSIS
#include <math.h>
double fma(double <[x]>, double <[y]>, double <[z]>);
float fmaf(float <[x]>, float <[y]>, float <[z]>);
 
DESCRIPTION
The <<fma>> functions compute (<[x]> * <[y]>) + <[z]>, rounded as one ternary
operation: they compute the value (as if) to infinite precision and round once
to the result format, according to the rounding mode characterized by the value
of FLT_ROUNDS. That is, they are supposed to do this: see below.
 
RETURNS
The <<fma>> functions return (<[x]> * <[y]>) + <[z]>, rounded as one ternary
operation.
 
BUGS
This implementation does not provide the function that it should, purely
returning "(<[x]> * <[y]>) + <[z]>;" with no attempt at all to provide the
simulated infinite precision intermediates which are required. DO NOT USE THEM.
 
If double has enough more precision than float, then <<fmaf>> should provide
the expected numeric results, as it does use double for the calculation. But
since this is not the case for all platforms, this manual cannot determine
if it is so for your case.
 
PORTABILITY
ANSI C, POSIX.
 
*/
 
#include "fdlibm.h"
 
#ifndef _DOUBLE_IS_32BITS
 
#ifdef __STDC__
double fma(double x, double y, double z)
#else
double fma(x,y)
double x;
double y;
double z;
#endif
{
/* Implementation defined. */
return (x * y) + z;
}
 
#endif /* _DOUBLE_IS_32BITS */
/programs/develop/libraries/newlib/math/s_fmax.c
0,0 → 1,52
/* Copyright (C) 2002 by Red Hat, Incorporated. All rights reserved.
*
* Permission to use, copy, modify, and distribute this software
* is freely granted, provided that this notice is preserved.
*/
/*
FUNCTION
<<fmax>>, <<fmaxf>>--maximum
INDEX
fmax
INDEX
fmaxf
 
ANSI_SYNOPSIS
#include <math.h>
double fmax(double <[x]>, double <[y]>);
float fmaxf(float <[x]>, float <[y]>);
 
DESCRIPTION
The <<fmax>> functions determine the maximum numeric value of their arguments.
NaN arguments are treated as missing data: if one argument is a NaN and the
other numeric, then the <<fmax>> functions choose the numeric value.
 
RETURNS
The <<fmax>> functions return the maximum numeric value of their arguments.
 
PORTABILITY
ANSI C, POSIX.
 
*/
 
#include "fdlibm.h"
 
#ifndef _DOUBLE_IS_32BITS
 
#ifdef __STDC__
double fmax(double x, double y)
#else
double fmax(x,y)
double x;
double y;
#endif
{
if (__fpclassifyd(x) == FP_NAN)
return y;
if (__fpclassifyd(y) == FP_NAN)
return x;
return x > y ? x : y;
}
 
#endif /* _DOUBLE_IS_32BITS */
/programs/develop/libraries/newlib/math/s_fmin.c
0,0 → 1,52
/* Copyright (C) 2002 by Red Hat, Incorporated. All rights reserved.
*
* Permission to use, copy, modify, and distribute this software
* is freely granted, provided that this notice is preserved.
*/
/*
FUNCTION
<<fmin>>, <<fminf>>--minimum
INDEX
fmin
INDEX
fminf
 
ANSI_SYNOPSIS
#include <math.h>
double fmin(double <[x]>, double <[y]>);
float fminf(float <[x]>, float <[y]>);
 
DESCRIPTION
The <<fmin>> functions determine the minimum numeric value of their arguments.
NaN arguments are treated as missing data: if one argument is a NaN and the
other numeric, then the <<fmin>> functions choose the numeric value.
 
RETURNS
The <<fmin>> functions return the minimum numeric value of their arguments.
 
PORTABILITY
ANSI C, POSIX.
 
*/
 
#include "fdlibm.h"
 
#ifndef _DOUBLE_IS_32BITS
 
#ifdef __STDC__
double fmin(double x, double y)
#else
double fmin(x,y)
double x;
double y;
#endif
{
if (__fpclassifyd(x) == FP_NAN)
return y;
if (__fpclassifyd(y) == FP_NAN)
return x;
return x < y ? x : y;
}
 
#endif /* _DOUBLE_IS_32BITS */
/programs/develop/libraries/newlib/math/s_frexp.c
0,0 → 1,114
 
/* @(#)s_frexp.c 5.1 93/09/24 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
/*
FUNCTION
<<frexp>>, <<frexpf>>---split floating-point number
INDEX
frexp
INDEX
frexpf
 
ANSI_SYNOPSIS
#include <math.h>
double frexp(double <[val]>, int *<[exp]>);
float frexpf(float <[val]>, int *<[exp]>);
 
TRAD_SYNOPSIS
#include <math.h>
double frexp(<[val]>, <[exp]>)
double <[val]>;
int *<[exp]>;
 
float frexpf(<[val]>, <[exp]>)
float <[val]>;
int *<[exp]>;
 
 
DESCRIPTION
All nonzero, normal numbers can be described as <[m]> * 2**<[p]>.
<<frexp>> represents the double <[val]> as a mantissa <[m]>
and a power of two <[p]>. The resulting mantissa will always
be greater than or equal to <<0.5>>, and less than <<1.0>> (as
long as <[val]> is nonzero). The power of two will be stored
in <<*>><[exp]>.
 
@ifnottex
<[m]> and <[p]> are calculated so that
<[val]> is <[m]> times <<2>> to the power <[p]>.
@end ifnottex
@tex
<[m]> and <[p]> are calculated so that
$ val = m \times 2^p $.
@end tex
 
<<frexpf>> is identical, other than taking and returning
floats rather than doubles.
 
RETURNS
<<frexp>> returns the mantissa <[m]>. If <[val]> is <<0>>, infinity,
or Nan, <<frexp>> will set <<*>><[exp]> to <<0>> and return <[val]>.
 
PORTABILITY
<<frexp>> is ANSI.
<<frexpf>> is an extension.
 
 
*/
 
/*
* for non-zero x
* x = frexp(arg,&exp);
* return a double fp quantity x such that 0.5 <= |x| <1.0
* and the corresponding binary exponent "exp". That is
* arg = x*2^exp.
* If arg is inf, 0.0, or NaN, then frexp(arg,&exp) returns arg
* with *exp=0.
*/
 
#include "fdlibm.h"
 
#ifndef _DOUBLE_IS_32BITS
 
#ifdef __STDC__
static const double
#else
static double
#endif
two54 = 1.80143985094819840000e+16; /* 0x43500000, 0x00000000 */
 
#ifdef __STDC__
double frexp(double x, int *eptr)
#else
double frexp(x, eptr)
double x; int *eptr;
#endif
{
__int32_t hx, ix, lx;
EXTRACT_WORDS(hx,lx,x);
ix = 0x7fffffff&hx;
*eptr = 0;
if(ix>=0x7ff00000||((ix|lx)==0)) return x; /* 0,inf,nan */
if (ix<0x00100000) { /* subnormal */
x *= two54;
GET_HIGH_WORD(hx,x);
ix = hx&0x7fffffff;
*eptr = -54;
}
*eptr += (ix>>20)-1022;
hx = (hx&0x800fffff)|0x3fe00000;
SET_HIGH_WORD(x,hx);
return x;
}
 
#endif /* _DOUBLE_IS_32BITS */
/programs/develop/libraries/newlib/math/s_ilogb.c
0,0 → 1,106
 
/* @(#)s_ilogb.c 5.1 93/09/24 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
/*
FUNCTION
<<ilogb>>, <<ilogbf>>---get exponent of floating-point number
INDEX
ilogb
INDEX
ilogbf
 
ANSI_SYNOPSIS
#include <math.h>
int ilogb(double <[val]>);
int ilogbf(float <[val]>);
 
TRAD_SYNOPSIS
#include <math.h>
int ilogb(<[val]>)
double <[val]>;
 
int ilogbf(<[val]>)
float <[val]>;
 
 
DESCRIPTION
 
All nonzero, normal numbers can be described as <[m]> *
2**<[p]>. <<ilogb>> and <<ilogbf>> examine the argument
<[val]>, and return <[p]>. The functions <<frexp>> and
<<frexpf>> are similar to <<ilogb>> and <<ilogbf>>, but also
return <[m]>.
 
RETURNS
 
<<ilogb>> and <<ilogbf>> return the power of two used to form the
floating-point argument.
If <[val]> is <<0>>, they return <<FP_ILOGB0>>.
If <[val]> is infinite, they return <<INT_MAX>>.
If <[val]> is NaN, they return <<FP_ILOGBNAN>>.
(<<FP_ILOGB0>> and <<FP_ILOGBNAN>> are defined in math.h, but in turn are
defined as INT_MIN or INT_MAX from limits.h. The value of FP_ILOGB0 may be
either INT_MIN or -INT_MAX. The value of FP_ILOGBNAN may be either INT_MAX or
INT_MIN.)
 
@comment The bugs might not be worth noting, given the mass non-C99/POSIX
@comment behavior of much of the Newlib math library.
@comment BUGS
@comment On errors, errno is not set per C99 and POSIX requirements even if
@comment (math_errhandling & MATH_ERRNO) is non-zero.
 
PORTABILITY
C99, POSIX
*/
 
/* ilogb(double x)
* return the binary exponent of non-zero x
* ilogb(0) = 0x80000001
* ilogb(inf/NaN) = 0x7fffffff (no signal is raised)
*/
 
#include <limits.h>
#include "fdlibm.h"
 
#ifndef _DOUBLE_IS_32BITS
 
#ifdef __STDC__
int ilogb(double x)
#else
int ilogb(x)
double x;
#endif
{
__int32_t hx,lx,ix;
 
EXTRACT_WORDS(hx,lx,x);
hx &= 0x7fffffff;
if(hx<0x00100000) {
if((hx|lx)==0)
return FP_ILOGB0; /* ilogb(0) = special case error */
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;
#if FP_ILOGBNAN != INT_MAX
else if (hx>0x7ff00000) return FP_ILOGBNAN; /* NAN */
#endif
else return INT_MAX; /* infinite (or, possibly, NAN) */
}
 
#endif /* _DOUBLE_IS_32BITS */
/programs/develop/libraries/newlib/math/s_infconst.c
0,0 → 1,21
/* Infinity as a constant value. This is used for HUGE_VAL.
* Added by Cygnus Support.
*/
 
#include <float.h>
#include <math.h>
 
/* These should never actually be used any longer, as their use in math.h was
* removed, but they are kept here in case a user was pointing to them.
* FIXME: deprecate these identifiers and then delete them. */
/* Float version of infinity. */
const union __fmath __infinityf[1] = { { FLT_MAX+FLT_MAX } };
 
/* Double version of infinity. */
const union __dmath __infinity[1] = { { DBL_MAX+DBL_MAX } };
 
/* Long double version of infinity. */
#if defined(_HAVE_LONG_DOUBLE)
const union __ldmath __infinityld[1] = { { LDBL_MAX+LDBL_MAX } };
#endif
/programs/develop/libraries/newlib/math/s_infinity.c
0,0 → 1,49
/*
* infinity () returns the representation of infinity.
* Added by Cygnus Support.
*/
 
/*
FUNCTION
<<infinity>>, <<infinityf>>--representation of infinity
 
INDEX
infinity
INDEX
infinityf
 
ANSI_SYNOPSIS
#include <math.h>
double infinity(void);
float infinityf(void);
 
DESCRIPTION
<<infinity>> and <<infinityf>> return the special number IEEE
infinity in double- and single-precision arithmetic
respectively.
 
PORTABILITY
<<infinity>> and <<infinityf>> are neither standard C nor POSIX. C and
POSIX require macros HUGE_VAL and HUGE_VALF to be defined in math.h, which
Newlib defines to be infinities corresponding to these archaic infinity()
and infinityf() functions in floating-point implementations which do have
infinities.
 
QUICKREF
infinity - pure
 
*/
 
#include "fdlibm.h"
 
#ifndef _DOUBLE_IS_32BITS
 
double infinity()
{
double x;
 
INSERT_WORDS(x,0x7ff00000,0);
return x;
}
 
#endif /* _DOUBLE_IS_32BITS */
/programs/develop/libraries/newlib/math/s_isinf.c
0,0 → 1,29
/*
* isinf(x) returns 1 if x is infinity, else 0;
* no branching!
*
* isinf is a <math.h> macro in the C99 standard. It was previously
* implemented as a function by newlib and is declared as such in
* <ieeefp.h>. Newlib supplies it here as a function if the user
* chooses to use <ieeefp.h> or needs to link older code compiled with the
* previous <math.h> declaration.
*/
 
#include "fdlibm.h"
#include <ieeefp.h>
 
#ifndef _DOUBLE_IS_32BITS
 
int
_DEFUN (isinf, (x),
double x)
{
__int32_t hx,lx;
EXTRACT_WORDS(hx,lx,x);
hx &= 0x7fffffff;
hx |= (__uint32_t)(lx|(-lx))>>31;
hx = 0x7ff00000 - hx;
return 1 - (int)((__uint32_t)(hx|(-hx))>>31);
}
 
#endif /* _DOUBLE_IS_32BITS */
/programs/develop/libraries/newlib/math/s_isinfd.c
0,0 → 1,23
/*
* __isinfd(x) returns 1 if x is infinity, else 0;
* no branching!
* Added by Cygnus Support.
*/
 
#include "fdlibm.h"
 
#ifndef _DOUBLE_IS_32BITS
 
int
_DEFUN (__isinfd, (x),
double x)
{
__int32_t hx,lx;
EXTRACT_WORDS(hx,lx,x);
hx &= 0x7fffffff;
hx |= (__uint32_t)(lx|(-lx))>>31;
hx = 0x7ff00000 - hx;
return 1 - (int)((__uint32_t)(hx|(-hx))>>31);
}
 
#endif /* _DOUBLE_IS_32BITS */
/programs/develop/libraries/newlib/math/s_isnan.c
0,0 → 1,206
 
/* @(#)s_isnan.c 5.1 93/09/24 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
/*
FUNCTION
<<fpclassify>>, <<isfinite>>, <<isinf>>, <<isnan>>, and <<isnormal>>--floating-point classification macros; <<finite>>, <<finitef>>, <<isinf>>, <<isinff>>, <<isnan>>, <<isnanf>>--test for exceptional numbers
 
@c C99 (start
INDEX
fpclassify
INDEX
isfinite
INDEX
isinf
INDEX
isnan
INDEX
isnormal
@c C99 end)
@c SUSv2 (start
INDEX
isnan
INDEX
isinf
INDEX
finite
 
INDEX
isnanf
INDEX
isinff
INDEX
finitef
@c SUSv2 end)
 
ANSI_SYNOPSIS
[C99 standard macros:]
#include <math.h>
int fpclassify(real-floating <[x]>);
int isfinite(real-floating <[x]>);
int isinf(real-floating <[x]>);
int isnan(real-floating <[x]>);
int isnormal(real-floating <[x]>);
 
[Archaic SUSv2 functions:]
#include <ieeefp.h>
int isnan(double <[arg]>);
int isinf(double <[arg]>);
int finite(double <[arg]>);
int isnanf(float <[arg]>);
int isinff(float <[arg]>);
int finitef(float <[arg]>);
 
DESCRIPTION
<<fpclassify>>, <<isfinite>>, <<isinf>>, <<isnan>>, and <<isnormal>> are macros
defined for use in classifying floating-point numbers. This is a help because
of special "values" like NaN and infinities. In the synopses shown,
"real-floating" indicates that the argument is an expression of real floating
type. These function-like macros are C99 and POSIX-compliant, and should be
used instead of the now-archaic SUSv2 functions.
 
The <<fpclassify>> macro classifies its argument value as NaN, infinite, normal,
subnormal, zero, or into another implementation-defined category. First, an
argument represented in a format wider than its semantic type is converted to
its semantic type. Then classification is based on the type of the argument.
The <<fpclassify>> macro returns the value of the number classification macro
appropriate to the value of its argument:
 
o+
o FP_INFINITE
<[x]> is either plus or minus infinity;
o FP_NAN
<[x]> is "Not A Number" (plus or minus);
o FP_NORMAL
<[x]> is a "normal" number (i.e. is none of the other special forms);
o FP_SUBNORMAL
<[x]> is too small be stored as a regular normalized number (i.e. loss of precision is likely); or
o FP_ZERO
<[x]> is 0 (either plus or minus).
o-
 
The "<<is>>" set of macros provide a useful set of shorthand ways for
classifying floating-point numbers, providing the following equivalent
relations:
 
o+
o <<isfinite>>(<[x]>)
returns non-zero if <[x]> is finite. (It is equivalent to
(<<fpclassify>>(<[x]>) != FP_INFINITE && <<fpclassify>>(<[x]>) != FP_NAN).)
 
o <<isinf>>(<[x]>)
returns non-zero if <[x]> is infinite. (It is equivalent to
(<<fpclassify>>(<[x]>) == FP_INFINITE).)
 
o <<isnan>>(<[x]>)
returns non-zero if <[x]> is NaN. (It is equivalent to
(<<fpclassify>>(<[x]>) == FP_NAN).)
 
o <<isnormal>>(<[x]>)
returns non-zero if <[x]> is normal. (It is equivalent to
(<<fpclassify>>(<[x]>) == FP_NORMAL).)
o-
 
The archaic SUSv2 functions provide information on the floating-point
argument supplied.
 
There are five major number formats ("exponent" referring to the
biased exponent in the binary-encoded number):
o+
o zero
A number which contains all zero bits, excluding the sign bit.
o subnormal
A number with a zero exponent but a nonzero fraction.
o normal
A number with an exponent and a fraction.
o infinity
A number with an all 1's exponent and a zero fraction.
o NAN
A number with an all 1's exponent and a nonzero fraction.
 
o-
 
<<isnan>> returns 1 if the argument is a nan. <<isinf>>
returns 1 if the argument is infinity. <<finite>> returns 1 if the
argument is zero, subnormal or normal.
The <<isnanf>>, <<isinff>> and <<finitef>> functions perform the same
operations as their <<isnan>>, <<isinf>> and <<finite>>
counterparts, but on single-precision floating-point numbers.
 
It should be noted that the C99 standard dictates that <<isnan>>
and <<isinf>> are macros that operate on multiple types of
floating-point. The SUSv2 standard declares <<isnan>> as
a function taking double. Newlib has decided to declare
them both as macros in math.h and as functions in ieeefp.h to
maintain backward compatibility.
 
RETURNS
@comment Formatting note: "$@" forces a new line
The fpclassify macro returns the value corresponding to the appropriate FP_ macro.@*
The isfinite macro returns nonzero if <[x]> is finite, else 0.@*
The isinf macro returns nonzero if <[x]> is infinite, else 0.@*
The isnan macro returns nonzero if <[x]> is an NaN, else 0.@*
The isnormal macro returns nonzero if <[x]> has a normal value, else 0.
 
PORTABILITY
math.h macros are C99, POSIX.
 
ieeefp.h funtions are outdated and should be avoided.
 
QUICKREF
isnan - pure
QUICKREF
isinf - pure
QUICKREF
finite - pure
QUICKREF
isnan - pure
QUICKREF
isinf - pure
QUICKREF
finite - pure
*/
 
/*
* isnan(x) returns 1 is x is nan, else 0;
* no branching!
*
* The C99 standard dictates that isnan is a macro taking
* multiple floating-point types while the SUSv2 standard
* notes it is a function taking a double argument. Newlib
* has chosen to implement it as a macro in <math.h> and
* declare it as a function in <ieeefp.h>.
*/
 
#include "fdlibm.h"
#include <ieeefp.h>
 
#ifndef _DOUBLE_IS_32BITS
 
#ifdef __STDC__
int isnan(double x)
#else
int isnan(x)
double x;
#endif
{
__int32_t hx,lx;
EXTRACT_WORDS(hx,lx,x);
hx &= 0x7fffffff;
hx |= (__uint32_t)(lx|(-lx))>>31;
hx = 0x7ff00000 - hx;
return (int)(((__uint32_t)(hx))>>31);
}
 
#endif /* _DOUBLE_IS_32BITS */
/programs/develop/libraries/newlib/math/s_isnand.c
9,7 → 9,95
* ====================================================
*/
 
/*
FUNCTION
<<isnan>>, <<isnanf>>, <<isinf>>, <<isinff>>, <<finite>>, <<finitef>>---test for exceptional numbers
 
INDEX
isnan
INDEX
isinf
INDEX
finite
 
INDEX
isnanf
INDEX
isinff
INDEX
finitef
 
ANSI_SYNOPSIS
#include <ieeefp.h>
int isnan(double <[arg]>);
int isinf(double <[arg]>);
int finite(double <[arg]>);
int isnanf(float <[arg]>);
int isinff(float <[arg]>);
int finitef(float <[arg]>);
 
TRAD_SYNOPSIS
#include <ieeefp.h>
int isnan(<[arg]>)
double <[arg]>;
int isinf(<[arg]>)
double <[arg]>;
int finite(<[arg]>);
double <[arg]>;
int isnanf(<[arg]>);
float <[arg]>;
int isinff(<[arg]>);
float <[arg]>;
int finitef(<[arg]>);
float <[arg]>;
 
 
DESCRIPTION
These functions provide information on the floating-point
argument supplied.
 
There are five major number formats:
o+
o zero
A number which contains all zero bits.
o subnormal
A number with a zero exponent but a nonzero fraction.
o normal
A number with an exponent and a fraction.
o infinity
A number with an all 1's exponent and a zero fraction.
o NAN
A number with an all 1's exponent and a nonzero fraction.
 
o-
 
<<isnan>> returns 1 if the argument is a nan. <<isinf>>
returns 1 if the argument is infinity. <<finite>> returns 1 if the
argument is zero, subnormal or normal.
 
Note that by the C99 standard, <<isnan>> and <<isinf>> are macros
taking any type of floating-point and are declared in
<<math.h>>. Newlib has chosen to declare these as macros in
<<math.h>> and as functions in <<ieeefp.h>>.
The <<isnanf>>, <<isinff>> and <<finitef>> functions perform the same
operations as their <<isnan>>, <<isinf>> and <<finite>>
counterparts, but on single-precision floating-point numbers.
 
QUICKREF
isnan - pure
QUICKREF
isinf - pure
QUICKREF
finite - pure
QUICKREF
isnan - pure
QUICKREF
isinf - pure
QUICKREF
finite - pure
*/
 
/*
* __isnand(x) returns 1 is x is nan, else 0;
* no branching!
17,6 → 105,8
 
#include "fdlibm.h"
 
#ifndef _DOUBLE_IS_32BITS
 
int
_DEFUN (__isnand, (x),
double x)
29,3 → 119,4
return (int)(((__uint32_t)(hx))>>31);
}
 
#endif /* _DOUBLE_IS_32BITS */
/programs/develop/libraries/newlib/math/s_ldexp.c
0,0 → 1,81
 
/* @(#)s_ldexp.c 5.1 93/09/24 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
/*
FUNCTION
<<ldexp>>, <<ldexpf>>---load exponent
 
INDEX
ldexp
INDEX
ldexpf
 
ANSI_SYNOPSIS
#include <math.h>
double ldexp(double <[val]>, int <[exp]>);
float ldexpf(float <[val]>, int <[exp]>);
 
TRAD_SYNOPSIS
#include <math.h>
 
double ldexp(<[val]>, <[exp]>)
double <[val]>;
int <[exp]>;
 
float ldexpf(<[val]>, <[exp]>)
float <[val]>;
int <[exp]>;
 
 
DESCRIPTION
<<ldexp>> calculates the value
@ifnottex
<[val]> times 2 to the power <[exp]>.
@end ifnottex
@tex
$val\times 2^{exp}$.
@end tex
<<ldexpf>> is identical, save that it takes and returns <<float>>
rather than <<double>> values.
 
RETURNS
<<ldexp>> returns the calculated value.
 
Underflow and overflow both set <<errno>> to <<ERANGE>>.
On underflow, <<ldexp>> and <<ldexpf>> return 0.0.
On overflow, <<ldexp>> returns plus or minus <<HUGE_VAL>>.
 
PORTABILITY
<<ldexp>> is ANSI. <<ldexpf>> is an extension.
*/
 
#include "fdlibm.h"
#include <errno.h>
 
#ifndef _DOUBLE_IS_32BITS
 
#ifdef __STDC__
double ldexp(double value, int exp)
#else
double ldexp(value, exp)
double value; int exp;
#endif
{
if(!finite(value)||value==0.0) return value;
value = scalbn(value,exp);
if(!finite(value)||value==0.0) errno = ERANGE;
return value;
}
 
#endif /* _DOUBLE_IS_32BITS */
/programs/develop/libraries/newlib/math/s_lib_ver.c
0,0 → 1,35
 
/* @(#)s_lib_ver.c 5.1 93/09/24 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
/*
* MACRO for standards
*/
 
#include "fdlibm.h"
 
/*
* define and initialize _LIB_VERSION
*/
#ifdef _POSIX_MODE
_LIB_VERSION_TYPE _LIB_VERSION = _POSIX_;
#else
#ifdef _XOPEN_MODE
_LIB_VERSION_TYPE _LIB_VERSION = _XOPEN_;
#else
#ifdef _SVID3_MODE
_LIB_VERSION_TYPE _LIB_VERSION = _SVID_;
#else /* default _IEEE_MODE */
_LIB_VERSION_TYPE _LIB_VERSION = _IEEE_;
#endif
#endif
#endif
/programs/develop/libraries/newlib/math/s_llrint.c
0,0 → 1,124
/* lrint adapted to be llrint for Newlib, 2009 by Craig Howland. */
/* @(#)s_lrint.c 5.1 93/09/24 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
/*
* llrint(x)
* Return x rounded to integral value according to the prevailing
* rounding mode.
* Method:
* Using floating addition.
* Exception:
* Inexact flag raised if x not equal to llrint(x).
*/
 
#include "fdlibm.h"
 
#ifndef _DOUBLE_IS_32BITS
 
#ifdef __STDC__
static const double
#else
static double
#endif
 
/* Adding a double, x, to 2^52 will cause the result to be rounded based on
the fractional part of x, according to the implementation's current rounding
mode. 2^52 is the smallest double that can be represented using all 52 significant
digits. */
TWO52[2]={
4.50359962737049600000e+15, /* 0x43300000, 0x00000000 */
-4.50359962737049600000e+15, /* 0xC3300000, 0x00000000 */
};
 
long long int
#ifdef __STDC__
llrint(double x)
#else
llrint(x)
double x;
#endif
{
__int32_t i0,j0,sx;
__uint32_t i1;
double t;
volatile double w;
long long int result;
EXTRACT_WORDS(i0,i1,x);
 
/* Extract sign bit. */
sx = (i0>>31)&1;
 
/* Extract exponent field. */
j0 = ((i0 & 0x7ff00000) >> 20) - 1023;
/* j0 in [-1023,1024] */
if(j0 < 20)
{
/* j0 in [-1023,19] */
if(j0 < -1)
return 0;
else
{
/* j0 in [0,19] */
/* shift amt in [0,19] */
w = TWO52[sx] + x;
t = w - TWO52[sx];
GET_HIGH_WORD(i0, t);
/* Detect the all-zeros representation of plus and
minus zero, which fails the calculation below. */
if ((i0 & ~((__int32_t)1 << 31)) == 0)
return 0;
/* After round: j0 in [0,20] */
j0 = ((i0 & 0x7ff00000) >> 20) - 1023;
i0 &= 0x000fffff;
i0 |= 0x00100000;
/* shift amt in [20,0] */
result = i0 >> (20 - j0);
}
}
else if (j0 < (int)(8 * sizeof (long long int)) - 1)
{
/* 64bit return: j0 in [20,62] */
if (j0 >= 52)
/* 64bit return: j0 in [52,62] */
/* 64bit return: left shift amt in [32,42] */
result = ((long long int) ((i0 & 0x000fffff) | 0x0010000) << (j0 - 20)) |
/* 64bit return: right shift amt in [0,10] */
(i1 << (j0 - 52));
else
{
/* 64bit return: j0 in [20,51] */
w = TWO52[sx] + x;
t = w - TWO52[sx];
EXTRACT_WORDS (i0, i1, t);
j0 = ((i0 & 0x7ff00000) >> 20) - 1023;
i0 &= 0x000fffff;
i0 |= 0x00100000;
/* After round:
* 64bit return: j0 in [20,52] */
/* 64bit return: left shift amt in [0,32] */
/* ***64bit return: right shift amt in [32,0] */
result = ((long long int) i0 << (j0 - 20))
| SAFE_RIGHT_SHIFT (i1, (52 - j0));
}
}
else
{
return (long long int) x;
}
return sx ? -result : result;
}
 
#endif /* _DOUBLE_IS_32BITS */
/programs/develop/libraries/newlib/math/s_llround.c
0,0 → 1,84
/* lround adapted to be llround for Newlib, 2009 by Craig Howland. */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#include "fdlibm.h"
 
#ifndef _DOUBLE_IS_32BITS
 
long long int
llround(double x)
{
__int32_t sign, exponent_less_1023;
/* Most significant word, least significant word. */
__uint32_t msw, lsw;
long long int result;
EXTRACT_WORDS(msw, lsw, x);
 
/* Extract sign. */
sign = ((msw & 0x80000000) ? -1 : 1);
/* Extract exponent field. */
exponent_less_1023 = ((msw & 0x7ff00000) >> 20) - 1023;
msw &= 0x000fffff;
msw |= 0x00100000;
 
/* exponent_less_1023 in [-1023,1024] */
if (exponent_less_1023 < 20)
{
/* exponent_less_1023 in [-1023,19] */
if (exponent_less_1023 < 0)
{
if (exponent_less_1023 < -1)
return 0;
else
return sign;
}
else
{
/* exponent_less_1023 in [0,19] */
/* shift amt in [0,19] */
msw += 0x80000 >> exponent_less_1023;
/* shift amt in [20,1] */
result = msw >> (20 - exponent_less_1023);
}
}
else if (exponent_less_1023 < (8 * sizeof (long long int)) - 1)
{
/* 64bit longlong: exponent_less_1023 in [20,62] */
if (exponent_less_1023 >= 52)
/* 64bit longlong: exponent_less_1023 in [52,62] */
/* 64bit longlong: shift amt in [32,42] */
result = ((long long int) msw << (exponent_less_1023 - 20))
/* 64bit longlong: shift amt in [0,10] */
| (lsw << (exponent_less_1023 - 52));
else
{
/* 64bit longlong: exponent_less_1023 in [20,51] */
unsigned int tmp = lsw
/* 64bit longlong: shift amt in [0,31] */
+ (0x80000000 >> (exponent_less_1023 - 20));
if (tmp < lsw)
++msw;
/* 64bit longlong: shift amt in [0,31] */
result = ((long long int) msw << (exponent_less_1023 - 20))
/* ***64bit longlong: shift amt in [32,1] */
| SAFE_RIGHT_SHIFT (tmp, (52 - exponent_less_1023));
}
}
else
/* Result is too large to be represented by a long long int. */
return (long long int)x;
 
return sign * result;
}
 
#endif /* _DOUBLE_IS_32BITS */
/programs/develop/libraries/newlib/math/s_log1p.c
0,0 → 1,217
 
/* @(#)s_log1p.c 5.1 93/09/24 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
/*
FUNCTION
<<log1p>>, <<log1pf>>---log of <<1 + <[x]>>>
 
INDEX
log1p
INDEX
log1pf
 
ANSI_SYNOPSIS
#include <math.h>
double log1p(double <[x]>);
float log1pf(float <[x]>);
 
TRAD_SYNOPSIS
#include <math.h>
double log1p(<[x]>)
double <[x]>;
 
float log1pf(<[x]>)
float <[x]>;
 
DESCRIPTION
<<log1p>> calculates
@tex
$ln(1+x)$,
@end tex
the natural logarithm of <<1+<[x]>>>. You can use <<log1p>> rather
than `<<log(1+<[x]>)>>' for greater precision when <[x]> is very
small.
 
<<log1pf>> calculates the same thing, but accepts and returns
<<float>> values rather than <<double>>.
 
RETURNS
<<log1p>> returns a <<double>>, the natural log of <<1+<[x]>>>.
<<log1pf>> returns a <<float>>, the natural log of <<1+<[x]>>>.
 
PORTABILITY
Neither <<log1p>> nor <<log1pf>> is required by ANSI C or by the System V
Interface Definition (Issue 2).
 
*/
 
/* double log1p(double x)
*
* Method :
* 1. Argument Reduction: find k and f such that
* 1+x = 2^k * (1+f),
* where sqrt(2)/2 < 1+f < sqrt(2) .
*
* Note. If k=0, then f=x is exact. However, if k!=0, then f
* may not be representable exactly. In that case, a correction
* term is need. Let u=1+x rounded. Let c = (1+x)-u, then
* log(1+x) - log(u) ~ c/u. Thus, we proceed to compute log(u),
* and add back the correction term c/u.
* (Note: when x > 2**53, one can simply return log(x))
*
* 2. Approximation of log1p(f).
* Let s = f/(2+f) ; based on log(1+f) = log(1+s) - log(1-s)
* = 2s + 2/3 s**3 + 2/5 s**5 + .....,
* = 2s + s*R
* We use a special Reme algorithm on [0,0.1716] to generate
* a polynomial of degree 14 to approximate R The maximum error
* of this polynomial approximation is bounded by 2**-58.45. In
* other words,
* 2 4 6 8 10 12 14
* R(z) ~ Lp1*s +Lp2*s +Lp3*s +Lp4*s +Lp5*s +Lp6*s +Lp7*s
* (the values of Lp1 to Lp7 are listed in the program)
* and
* | 2 14 | -58.45
* | Lp1*s +...+Lp7*s - R(z) | <= 2
* | |
* Note that 2s = f - s*f = f - hfsq + s*hfsq, where hfsq = f*f/2.
* In order to guarantee error in log below 1ulp, we compute log
* by
* log1p(f) = f - (hfsq - s*(hfsq+R)).
*
* 3. Finally, log1p(x) = k*ln2 + log1p(f).
* = k*ln2_hi+(f-(hfsq-(s*(hfsq+R)+k*ln2_lo)))
* Here ln2 is split into two floating point number:
* ln2_hi + ln2_lo,
* where n*ln2_hi is always exact for |n| < 2000.
*
* Special cases:
* log1p(x) is NaN with signal if x < -1 (including -INF) ;
* log1p(+INF) is +INF; log1p(-1) is -INF with signal;
* log1p(NaN) is that NaN with no signal.
*
* Accuracy:
* according to an error analysis, the error is always less than
* 1 ulp (unit in the last place).
*
* Constants:
* The hexadecimal values are the intended ones for the following
* constants. The decimal values may be used, provided that the
* compiler will convert from decimal to binary accurately enough
* to produce the hexadecimal values shown.
*
* Note: Assuming log() return accurate answer, the following
* algorithm can be used to compute log1p(x) to within a few ULP:
*
* u = 1+x;
* if(u==1.0) return x ; else
* return log(u)*(x/(u-1.0));
*
* See HP-15C Advanced Functions Handbook, p.193.
*/
 
#include "fdlibm.h"
 
#ifndef _DOUBLE_IS_32BITS
 
#ifdef __STDC__
static const double
#else
static double
#endif
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 */
 
#ifdef __STDC__
static const double zero = 0.0;
#else
static double zero = 0.0;
#endif
 
#ifdef __STDC__
double log1p(double x)
#else
double log1p(x)
double x;
#endif
{
double hfsq,f,c,s,z,R,u;
__int32_t k,hx,hu,ax;
 
GET_HIGH_WORD(hx,x);
ax = hx&0x7fffffff;
 
k = 1;
if (hx < 0x3FDA827A) { /* x < 0.41422 */
if(ax>=0x3ff00000) { /* x <= -1.0 */
if(x==-1.0) return -two54/zero; /* log1p(-1)=+inf */
else return (x-x)/(x-x); /* log1p(x<-1)=NaN */
}
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<=((__int32_t)0xbfd2bec3)) {
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);
}
 
#endif /* _DOUBLE_IS_32BITS */
/programs/develop/libraries/newlib/math/s_log2.c
0,0 → 1,85
/* @(#)s_log2.c 5.1 93/09/24 */
/* Modification from s_exp10.c Yaakov Selkowitz 2009. */
 
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
/*
FUNCTION
<<log2>>, <<log2f>>--base 2 logarithm
INDEX
log2
INDEX
log2f
 
ANSI_SYNOPSIS
#include <math.h>
double log2(double <[x]>);
float log2f(float <[x]>);
 
DESCRIPTION
The <<log2>> functions compute the base-2 logarithm of <[x]>. A domain error
occurs if the argument is less than zero. A range error occurs if the
argument is zero.
 
The Newlib implementations are not full, intrinisic calculations, but
rather are derivatives based on <<log>>. (Accuracy might be slightly off from
a direct calculation.) In addition to functions, they are also implemented as
macros defined in math.h:
. #define log2(x) (log (x) / _M_LN2)
. #define log2f(x) (logf (x) / (float) _M_LN2)
To use the functions instead, just undefine the macros first.
 
You can use the (non-ANSI) function <<matherr>> to specify error
handling for these functions, indirectly through the respective <<log>>
function.
 
RETURNS
The <<log2>> functions return
@ifnottex
<<log base-2(<[x]>)>>
@end ifnottex
@tex
$log_2(x)$
@end tex
on success.
When <[x]> is zero, the
returned value is <<-HUGE_VAL>> and <<errno>> is set to <<ERANGE>>.
When <[x]> is negative, the returned value is NaN (not a number) and
<<errno>> is set to <<EDOM>>. You can control the error behavior via
<<matherr>>.
 
PORTABILITY
C99, POSIX, System V Interface Definition (Issue 6).
*/
 
/*
* wrapper log2(x)
*/
 
#include "fdlibm.h"
#include <errno.h>
#include <math.h>
#undef log2
 
#ifndef _DOUBLE_IS_32BITS
 
#ifdef __STDC__
double log2(double x) /* wrapper log2 */
#else
double log2(x) /* wrapper log2 */
double x;
#endif
{
return (log(x) / M_LN2);
}
 
#endif /* defined(_DOUBLE_IS_32BITS) */
/programs/develop/libraries/newlib/math/s_logb.c
0,0 → 1,110
/* 2009 for Newlib: Sun's s_ilogb.c converted to be s_logb.c. */
/* @(#)s_ilogb.c 5.1 93/09/24 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
/*
FUNCTION
<<logb>>, <<logbf>>--get exponent of floating-point number
INDEX
logb
INDEX
logbf
 
ANSI_SYNOPSIS
#include <math.h>
double logb(double <[x]>);
float logbf(float <[x]>);
 
DESCRIPTION
The <<logb>> functions extract the exponent of <[x]>, as a signed integer value
in floating-point format. If <[x]> is subnormal it is treated as though it were
normalized; thus, for positive finite <[x]>,
@ifnottex
1 <= (<[x]> * FLT_RADIX to the power (-logb(<[x]>))) < FLT_RADIX.
@end ifnottex
@tex
$1 \leq ( x \cdot FLT\_RADIX ^ {-logb(x)} ) < FLT\_RADIX$.
@end tex
A domain error may occur if the argument is zero.
In this floating-point implementation, FLT_RADIX is 2. Which also means
that for finite <[x]>, <<logb>>(<[x]>) = <<floor>>(<<log2>>(<<fabs>>(<[x]>))).
 
All nonzero, normal numbers can be described as
@ifnottex
<[m]> * 2**<[p]>, where 1.0 <= <[m]> < 2.0.
@end ifnottex
@tex
$m \cdot 2^p$, where $1.0 \leq m < 2.0$.
@end tex
The <<logb>> functions examine the argument <[x]>, and return <[p]>.
The <<frexp>> functions are similar to the <<logb>> functions, but
returning <[m]> adjusted to the interval [.5, 1) or 0, and <[p]>+1.
 
RETURNS
@comment Formatting note: "$@" forces a new line
When <[x]> is:@*
+inf or -inf, +inf is returned;@*
NaN, NaN is returned;@*
0, -inf is returned, and the divide-by-zero exception is raised;@*
otherwise, the <<logb>> functions return the signed exponent of <[x]>.
 
PORTABILITY
ANSI C, POSIX
 
SEEALSO
frexp, ilogb
*/
 
/* double logb(double x)
* return the binary exponent of non-zero x
* logb(0) = -inf, raise divide-by-zero floating point exception
* logb(+inf|-inf) = +inf (no signal is raised)
* logb(NaN) = NaN (no signal is raised)
* Per C99 recommendation, a NaN argument is returned unchanged.
*/
 
#include "fdlibm.h"
 
#ifndef _DOUBLE_IS_32BITS
 
double
#ifdef __STDC__
logb(double x)
#else
logb(x)
double x;
#endif
{
__int32_t hx,lx,ix;
 
EXTRACT_WORDS(hx,lx,x);
hx &= 0x7fffffff; /* high |x| */
if(hx<0x00100000) { /* 0 or subnormal */
if((hx|lx)==0) {
double xx;
/* arg==0: return -inf and raise divide-by-zero exception */
INSERT_WORDS(xx,hx,lx); /* +0.0 */
return -1./xx; /* logb(0) = -inf */
}
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 (double) ix;
}
else if (hx<0x7ff00000) return (hx>>20)-1023; /* normal # */
else if (hx>0x7ff00000 || lx) return x; /* x==NaN */
else return HUGE_VAL; /* x==inf (+ or -) */
}
 
#endif /* _DOUBLE_IS_32BITS */
/programs/develop/libraries/newlib/math/s_lrint.c
0,0 → 1,166
 
/* @(#)s_lrint.c 5.1 93/09/24 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
/*
FUNCTION
<<lrint>>, <<lrintf>>, <<llrint>>, <<llrintf>>--round to integer
INDEX
lrint
INDEX
lrintf
INDEX
llrint
INDEX
llrintf
 
ANSI_SYNOPSIS
#include <math.h>
long int lrint(double <[x]>);
long int lrintf(float <[x]>);
long long int llrint(double <[x]>);
long long int llrintf(float <[x]>);
 
DESCRIPTION
The <<lrint>> and <<llrint>> functions round their argument to the nearest
integer value, using the current rounding direction. If the rounded value is
outside the range of the return type, the numeric result is unspecified. A
range error may occur if the magnitude of <[x]> is too large.
The "inexact" floating-point exception is raised in implementations that
support it when the result differs in value from the argument (i.e., when
a fraction actually has been truncated).
 
RETURNS
<[x]> rounded to an integral value, using the current rounding direction.
 
SEEALSO
<<lround>>
 
PORTABILITY
ANSI C, POSIX
 
*/
 
/*
* lrint(x)
* Return x rounded to integral value according to the prevailing
* rounding mode.
* Method:
* Using floating addition.
* Exception:
* Inexact flag raised if x not equal to lrint(x).
*/
 
#include "fdlibm.h"
 
#ifndef _DOUBLE_IS_32BITS
 
#ifdef __STDC__
static const double
#else
static double
#endif
 
/* Adding a double, x, to 2^52 will cause the result to be rounded based on
the fractional part of x, according to the implementation's current rounding
mode. 2^52 is the smallest double that can be represented using all 52 significant
digits. */
TWO52[2]={
4.50359962737049600000e+15, /* 0x43300000, 0x00000000 */
-4.50359962737049600000e+15, /* 0xC3300000, 0x00000000 */
};
 
#ifdef __STDC__
long int lrint(double x)
#else
long int lrint(x)
double x;
#endif
{
__int32_t i0,j0,sx;
__uint32_t i1;
double t;
volatile double w;
long int result;
EXTRACT_WORDS(i0,i1,x);
 
/* Extract sign bit. */
sx = (i0>>31)&1;
 
/* Extract exponent field. */
j0 = ((i0 & 0x7ff00000) >> 20) - 1023;
/* j0 in [-1023,1024] */
if(j0 < 20)
{
/* j0 in [-1023,19] */
if(j0 < -1)
return 0;
else
{
/* j0 in [0,19] */
/* shift amt in [0,19] */
w = TWO52[sx] + x;
t = w - TWO52[sx];
GET_HIGH_WORD(i0, t);
/* Detect the all-zeros representation of plus and
minus zero, which fails the calculation below. */
if ((i0 & ~(1L << 31)) == 0)
return 0;
/* After round: j0 in [0,20] */
j0 = ((i0 & 0x7ff00000) >> 20) - 1023;
i0 &= 0x000fffff;
i0 |= 0x00100000;
/* shift amt in [20,0] */
result = i0 >> (20 - j0);
}
}
else if (j0 < (int)(8 * sizeof (long int)) - 1)
{
/* 32bit return: j0 in [20,30] */
/* 64bit return: j0 in [20,62] */
if (j0 >= 52)
/* 64bit return: j0 in [52,62] */
/* 64bit return: left shift amt in [32,42] */
result = ((long int) ((i0 & 0x000fffff) | 0x0010000) << (j0 - 20)) |
/* 64bit return: right shift amt in [0,10] */
(i1 << (j0 - 52));
else
{
/* 32bit return: j0 in [20,30] */
/* 64bit return: j0 in [20,51] */
w = TWO52[sx] + x;
t = w - TWO52[sx];
EXTRACT_WORDS (i0, i1, t);
j0 = ((i0 & 0x7ff00000) >> 20) - 1023;
i0 &= 0x000fffff;
i0 |= 0x00100000;
/* After round:
* 32bit return: j0 in [20,31];
* 64bit return: j0 in [20,52] */
/* 32bit return: left shift amt in [0,11] */
/* 64bit return: left shift amt in [0,32] */
/* ***32bit return: right shift amt in [32,21] */
/* ***64bit return: right shift amt in [32,0] */
result = ((long int) i0 << (j0 - 20))
| SAFE_RIGHT_SHIFT (i1, (52 - j0));
}
}
else
{
return (long int) x;
}
return sx ? -result : result;
}
 
#endif /* _DOUBLE_IS_32BITS */
/programs/develop/libraries/newlib/math/s_lround.c
0,0 → 1,129
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
/*
FUNCTION
<<lround>>, <<lroundf>>, <<llround>>, <<llroundf>>--round to integer, to nearest
INDEX
lround
INDEX
lroundf
INDEX
llround
INDEX
llroundf
 
ANSI_SYNOPSIS
#include <math.h>
long int lround(double <[x]>);
long int lroundf(float <[x]>);
long long int llround(double <[x]>);
long long int llroundf(float <[x]>);
 
DESCRIPTION
The <<lround>> and <<llround>> functions round their argument to the
nearest integer value, rounding halfway cases away from zero, regardless
of the current rounding direction. If the rounded value is outside the
range of the return type, the numeric result is unspecified (depending
upon the floating-point implementation, not the library). A range
error may occur if the magnitude of x is too large.
 
RETURNS
<[x]> rounded to an integral value as an integer.
 
SEEALSO
See the <<round>> functions for the return being the same floating-point type
as the argument. <<lrint>>, <<llrint>>.
 
PORTABILITY
ANSI C, POSIX
 
*/
 
#include "fdlibm.h"
 
#ifndef _DOUBLE_IS_32BITS
 
#ifdef __STDC__
long int lround(double x)
#else
long int lround(x)
double x;
#endif
{
__int32_t sign, exponent_less_1023;
/* Most significant word, least significant word. */
__uint32_t msw, lsw;
long int result;
EXTRACT_WORDS(msw, lsw, x);
 
/* Extract sign. */
sign = ((msw & 0x80000000) ? -1 : 1);
/* Extract exponent field. */
exponent_less_1023 = ((msw & 0x7ff00000) >> 20) - 1023;
msw &= 0x000fffff;
msw |= 0x00100000;
/* exponent_less_1023 in [-1023,1024] */
if (exponent_less_1023 < 20)
{
/* exponent_less_1023 in [-1023,19] */
if (exponent_less_1023 < 0)
{
if (exponent_less_1023 < -1)
return 0;
else
return sign;
}
else
{
/* exponent_less_1023 in [0,19] */
/* shift amt in [0,19] */
msw += 0x80000 >> exponent_less_1023;
/* shift amt in [20,1] */
result = msw >> (20 - exponent_less_1023);
}
}
else if (exponent_less_1023 < (8 * sizeof (long int)) - 1)
{
/* 32bit long: exponent_less_1023 in [20,30] */
/* 64bit long: exponent_less_1023 in [20,62] */
if (exponent_less_1023 >= 52)
/* 64bit long: exponent_less_1023 in [52,62] */
/* 64bit long: shift amt in [32,42] */
result = ((long int) msw << (exponent_less_1023 - 20))
/* 64bit long: shift amt in [0,10] */
| (lsw << (exponent_less_1023 - 52));
else
{
/* 32bit long: exponent_less_1023 in [20,30] */
/* 64bit long: exponent_less_1023 in [20,51] */
unsigned int tmp = lsw
/* 32bit long: shift amt in [0,10] */
/* 64bit long: shift amt in [0,31] */
+ (0x80000000 >> (exponent_less_1023 - 20));
if (tmp < lsw)
++msw;
/* 32bit long: shift amt in [0,10] */
/* 64bit long: shift amt in [0,31] */
result = ((long int) msw << (exponent_less_1023 - 20))
/* ***32bit long: shift amt in [32,22] */
/* ***64bit long: shift amt in [32,1] */
| SAFE_RIGHT_SHIFT (tmp, (52 - exponent_less_1023));
}
}
else
/* Result is too large to be represented by a long int. */
return (long int)x;
 
return sign * result;
}
 
#endif /* _DOUBLE_IS_32BITS */
/programs/develop/libraries/newlib/math/s_matherr.c
0,0 → 1,123
 
/* @(#)s_matherr.c 5.1 93/09/24 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
/*
 
FUNCTION
<<matherr>>---modifiable math error handler
 
INDEX
matherr
 
ANSI_SYNOPSIS
#include <math.h>
int matherr(struct exception *<[e]>);
 
TRAD_SYNOPSIS
#include <math.h>
int matherr(*<[e]>)
struct exception *<[e]>;
 
DESCRIPTION
<<matherr>> is called whenever a math library function generates an error.
You can replace <<matherr>> by your own subroutine to customize
error treatment. The customized <<matherr>> must return 0 if
it fails to resolve the error, and non-zero if the error is resolved.
 
When <<matherr>> returns a nonzero value, no error message is printed
and the value of <<errno>> is not modified. You can accomplish either
or both of these things in your own <<matherr>> using the information
passed in the structure <<*<[e]>>>.
 
This is the <<exception>> structure (defined in `<<math.h>>'):
. struct exception {
. int type;
. char *name;
. double arg1, arg2, retval;
. int err;
. };
 
The members of the exception structure have the following meanings:
o+
o type
The type of mathematical error that occured; macros encoding error
types are also defined in `<<math.h>>'.
 
o name
a pointer to a null-terminated string holding the
name of the math library function where the error occurred.
 
o arg1, arg2
The arguments which caused the error.
 
o retval
The error return value (what the calling function will return).
 
o err
If set to be non-zero, this is the new value assigned to <<errno>>.
o-
 
The error types defined in `<<math.h>>' represent possible mathematical
errors as follows:
 
o+
o DOMAIN
An argument was not in the domain of the function; e.g. <<log(-1.0)>>.
 
o SING
The requested calculation would result in a singularity; e.g. <<pow(0.0,-2.0)>>
 
o OVERFLOW
A calculation would produce a result too large to represent; e.g.
<<exp(1000.0)>>.
 
o UNDERFLOW
A calculation would produce a result too small to represent; e.g.
<<exp(-1000.0)>>.
 
o TLOSS
Total loss of precision. The result would have no significant digits;
e.g. <<sin(10e70)>>.
 
o PLOSS
Partial loss of precision.
o-
 
 
RETURNS
The library definition for <<matherr>> returns <<0>> in all cases.
 
You can change the calling function's result from a customized <<matherr>>
by modifying <<e->retval>>, which propagates backs to the caller.
 
If <<matherr>> returns <<0>> (indicating that it was not able to resolve
the error) the caller sets <<errno>> to an appropriate value, and prints
an error message.
 
PORTABILITY
<<matherr>> is not ANSI C.
*/
 
#include "fdlibm.h"
 
#ifdef __STDC__
int matherr(struct exception *x)
#else
int matherr(x)
struct exception *x;
#endif
{
int n=0;
if(x->arg1!=x->arg1) return 0;
return n;
}
/programs/develop/libraries/newlib/math/s_nan.c
0,0 → 1,48
/*
* nan () returns a nan.
* Added by Cygnus Support.
*/
 
/*
FUNCTION
<<nan>>, <<nanf>>---representation of ``Not a Number''
 
INDEX
nan
INDEX
nanf
 
ANSI_SYNOPSIS
#include <math.h>
double nan(const char *);
float nanf(const char *);
 
TRAD_SYNOPSIS
#include <math.h>
double nan();
float nanf();
 
 
DESCRIPTION
<<nan>> and <<nanf>> return an IEEE NaN (Not a Number) in
double- and single-precision arithmetic respectively. The
argument is currently disregarded.
 
QUICKREF
nan - pure
 
*/
 
#include "fdlibm.h"
 
#ifndef _DOUBLE_IS_32BITS
 
double nan(const char *unused)
{
double x;
 
INSERT_WORDS(x,0x7ff80000,0);
return x;
}
 
#endif /* _DOUBLE_IS_32BITS */
/programs/develop/libraries/newlib/math/s_nearbyint.c
0,0 → 1,64
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
/*
FUNCTION
<<nearbyint>>, <<nearbyintf>>--round to integer
INDEX
nearbyint
INDEX
nearbyintf
 
ANSI_SYNOPSIS
#include <math.h>
double nearbyint(double <[x]>);
float nearbyintf(float <[x]>);
 
DESCRIPTION
The <<nearbyint>> functions round their argument to an integer value in
floating-point format, using the current rounding direction and
(supposedly) without raising the "inexact" floating-point exception.
See the <<rint>> functions for the same function with the "inexact"
floating-point exception being raised when appropriate.
 
BUGS
Newlib does not support the floating-point exception model, so that
the floating-point exception control is not present and thereby what may
be seen will be compiler and hardware dependent in this regard.
The Newlib <<nearbyint>> functions are identical to the <<rint>>
functions with respect to the floating-point exception behavior, and
will cause the "inexact" exception to be raised for most targets.
 
RETURNS
<[x]> rounded to an integral value, using the current rounding direction.
 
PORTABILITY
ANSI C, POSIX
 
SEEALSO
<<rint>>, <<round>>
*/
 
#include <math.h>
#include "fdlibm.h"
 
#ifndef _DOUBLE_IS_32BITS
 
#ifdef __STDC__
double nearbyint(double x)
#else
double nearbyint(x)
double x;
#endif
{
return rint(x);
}
 
#endif /* _DOUBLE_IS_32BITS */
/programs/develop/libraries/newlib/math/s_nextafter.c
0,0 → 1,121
 
/* @(#)s_nextafter.c 5.1 93/09/24 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
/*
FUNCTION
<<nextafter>>, <<nextafterf>>---get next number
 
INDEX
nextafter
INDEX
nextafterf
 
ANSI_SYNOPSIS
#include <math.h>
double nextafter(double <[val]>, double <[dir]>);
float nextafterf(float <[val]>, float <[dir]>);
 
TRAD_SYNOPSIS
#include <math.h>
 
double nextafter(<[val]>, <[dir]>)
double <[val]>;
double <[exp]>;
 
float nextafter(<[val]>, <[dir]>)
float <[val]>;
float <[dir]>;
 
 
DESCRIPTION
<<nextafter>> returns the double-precision floating-point number
closest to <[val]> in the direction toward <[dir]>. <<nextafterf>>
performs the same operation in single precision. For example,
<<nextafter(0.0,1.0)>> returns the smallest positive number which is
representable in double precision.
 
RETURNS
Returns the next closest number to <[val]> in the direction toward
<[dir]>.
 
PORTABILITY
Neither <<nextafter>> nor <<nextafterf>> is required by ANSI C
or by the System V Interface Definition (Issue 2).
*/
 
/* IEEE functions
* nextafter(x,y)
* return the next machine floating-point number of x in the
* direction toward y.
* Special cases:
*/
 
#include "fdlibm.h"
 
#ifndef _DOUBLE_IS_32BITS
 
#ifdef __STDC__
double nextafter(double x, double y)
#else
double nextafter(x,y)
double x,y;
#endif
{
__int32_t hx,hy,ix,iy;
__uint32_t lx,ly;
 
EXTRACT_WORDS(hx,lx,x);
EXTRACT_WORDS(hy,ly,y);
ix = hx&0x7fffffff; /* |x| */
iy = hy&0x7fffffff; /* |y| */
 
if(((ix>=0x7ff00000)&&((ix-0x7ff00000)|lx)!=0) || /* x is nan */
((iy>=0x7ff00000)&&((iy-0x7ff00000)|ly)!=0)) /* y is nan */
return x+y;
if(x==y) return x; /* x=y, return x */
if((ix|lx)==0) { /* x == 0 */
INSERT_WORDS(x,hy&0x80000000,1); /* return +-minsubnormal */
y = x*x;
if(y==x) return y; else return x; /* raise underflow flag */
}
if(hx>=0) { /* x > 0 */
if(hx>hy||((hx==hy)&&(lx>ly))) { /* x > y, x -= ulp */
if(lx==0) hx -= 1;
lx -= 1;
} else { /* x < y, x += ulp */
lx += 1;
if(lx==0) hx += 1;
}
} else { /* x < 0 */
if(hy>=0||hx>hy||((hx==hy)&&(lx>ly))){/* x < y, x -= ulp */
if(lx==0) hx -= 1;
lx -= 1;
} else { /* x > y, x += ulp */
lx += 1;
if(lx==0) hx += 1;
}
}
hy = hx&0x7ff00000;
if(hy>=0x7ff00000) return x+x; /* overflow */
if(hy<0x00100000) { /* underflow */
y = x*x;
if(y!=x) { /* raise underflow flag */
INSERT_WORDS(y,hx,lx);
return y;
}
}
INSERT_WORDS(x,hx,lx);
return x;
}
 
#endif /* _DOUBLE_IS_32BITS */
/programs/develop/libraries/newlib/math/s_pow10.c
0,0 → 1,79
/* @(#)s_pow10.c 5.1 93/09/24 */
/* Modification from s_exp10.c Yaakov Selkowitz 2007. */
 
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
/*
FUNCTION
<<pow10>>, <<pow10f>>---exponential
INDEX
pow10
INDEX
pow10f
 
ANSI_SYNOPSIS
#include <math.h>
double pow10(double <[x]>);
float pow10f(float <[x]>);
 
TRAD_SYNOPSIS
#include <math.h>
double pow10(<[x]>);
double <[x]>;
 
float pow10f(<[x]>);
float <[x]>;
 
DESCRIPTION
<<pow10>> and <<pow10f>> calculate 10 ^ <[x]>, that is,
@ifnottex
10 raised to the power <[x]>.
@end ifnottex
@tex
$10^x$
@end tex
 
You can use the (non-ANSI) function <<matherr>> to specify
error handling for these functions.
 
RETURNS
On success, <<pow10>> and <<pow10f>> return the calculated value.
If the result underflows, the returned value is <<0>>. If the
result overflows, the returned value is <<HUGE_VAL>>. In
either case, <<errno>> is set to <<ERANGE>>.
 
PORTABILITY
<<pow10>> and <<pow10f>> are GNU extensions.
*/
 
/*
* wrapper pow10(x)
*/
 
#undef pow10
#include "fdlibm.h"
#include <errno.h>
#include <math.h>
 
#ifndef _DOUBLE_IS_32BITS
 
#ifdef __STDC__
double pow10(double x) /* wrapper pow10 */
#else
double pow10(x) /* wrapper pow10 */
double x;
#endif
{
return pow(10.0, x);
}
 
#endif /* defined(_DOUBLE_IS_32BITS) */
/programs/develop/libraries/newlib/math/s_remquo.c
0,0 → 1,208
/* Adapted for Newlib, 2009. (Allow for int < 32 bits; return *quo=0 during
* errors to make test scripts easier.) */
/* @(#)e_fmod.c 1.3 95/01/18 */
/*-
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunSoft, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
/*
FUNCTION
<<remquo>>, <<remquof>>--remainder and part of quotient
INDEX
remquo
INDEX
remquof
 
ANSI_SYNOPSIS
#include <math.h>
double remquo(double <[x]>, double <[y]>, int *<[quo]>);
float remquof(float <[x]>, float <[y]>, int *<[quo]>);
 
DESCRIPTION
The <<remquo>> functions compute the same remainder as the <<remainder>>
functions; this value is in the range -<[y]>/2 ... +<[y]>/2. In the object
pointed to by <<quo>> they store a value whose sign is the sign of <<x>>/<<y>>
and whose magnitude is congruent modulo 2**n to the magnitude of the integral
quotient of <<x>>/<<y>>. (That is, <<quo>> is given the n lsbs of the
quotient, not counting the sign.) This implementation uses n=31 if int is 32
bits or more, otherwise, n is 1 less than the width of int.
 
For example:
. remquo(-29.0, 3.0, &<[quo]>)
returns -1.0 and sets <[quo]>=10, and
. remquo(-98307.0, 3.0, &<[quo]>)
returns -0.0 and sets <[quo]>=-32769, although for 16-bit int, <[quo]>=-1. In
the latter case, the actual quotient of -(32769=0x8001) is reduced to -1
because of the 15-bit limitation for the quotient.
 
RETURNS
When either argument is NaN, NaN is returned. If <[y]> is 0 or <[x]> is
infinite (and neither is NaN), a domain error occurs (i.e. the "invalid"
floating point exception is raised or errno is set to EDOM), and NaN is
returned.
Otherwise, the <<remquo>> functions return <[x]> REM <[y]>.
 
BUGS
IEEE754-2008 calls for <<remquo>>(subnormal, inf) to cause the "underflow"
floating-point exception. This implementation does not.
 
PORTABILITY
C99, POSIX.
 
*/
 
#include <limits.h>
#include <math.h>
#include "fdlibm.h"
 
/* For quotient, return either all 31 bits that can from calculation (using
* int32_t), or as many as can fit into an int that is smaller than 32 bits. */
#if INT_MAX > 0x7FFFFFFFL
#define QUO_MASK 0x7FFFFFFF
# else
#define QUO_MASK INT_MAX
#endif
 
static const double Zero[] = {0.0, -0.0,};
 
/*
* Return the IEEE remainder and set *quo to the last n bits of the
* quotient, rounded to the nearest integer. We choose n=31--if that many fit--
* because we wind up computing all the integer bits of the quotient anyway as
* a side-effect of computing the remainder by the shift and subtract
* method. In practice, this is far more bits than are needed to use
* remquo in reduction algorithms.
*/
double
remquo(double x, double y, int *quo)
{
__int32_t n,hx,hy,hz,ix,iy,sx,i;
__uint32_t lx,ly,lz,q,sxy;
 
EXTRACT_WORDS(hx,lx,x);
EXTRACT_WORDS(hy,ly,y);
sxy = (hx ^ hy) & 0x80000000;
sx = hx&0x80000000; /* sign of x */
hx ^=sx; /* |x| */
hy &= 0x7fffffff; /* |y| */
 
/* purge off exception values */
if((hy|ly)==0||(hx>=0x7ff00000)|| /* y=0,or x not finite */
((hy|((ly|-ly)>>31))>0x7ff00000)) { /* or y is NaN */
*quo = 0; /* Not necessary, but return consistent value */
return (x*y)/(x*y);
}
if(hx<=hy) {
if((hx<hy)||(lx<ly)) {
q = 0;
goto fixup; /* |x|<|y| return x or x-y */
}
if(lx==ly) {
*quo = (sxy ? -1 : 1);
return Zero[(__uint32_t)sx>>31]; /* |x|=|y| return x*0 */
}
}
 
/* determine ix = ilogb(x) */
if(hx<0x00100000) { /* subnormal x */
if(hx==0) {
for (ix = -1043, i=lx; i>0; i<<=1) ix -=1;
} else {
for (ix = -1022,i=(hx<<11); i>0; i<<=1) ix -=1;
}
} else ix = (hx>>20)-1023;
 
/* determine iy = ilogb(y) */
if(hy<0x00100000) { /* subnormal y */
if(hy==0) {
for (iy = -1043, i=ly; i>0; i<<=1) iy -=1;
} else {
for (iy = -1022,i=(hy<<11); i>0; i<<=1) iy -=1;
}
} else iy = (hy>>20)-1023;
 
/* set up {hx,lx}, {hy,ly} and align y to x */
if(ix >= -1022)
hx = 0x00100000|(0x000fffff&hx);
else { /* subnormal x, shift x to normal */
n = -1022-ix;
if(n<=31) {
hx = (hx<<n)|(lx>>(32-n));
lx <<= n;
} else {
hx = lx<<(n-32);
lx = 0;
}
}
if(iy >= -1022)
hy = 0x00100000|(0x000fffff&hy);
else { /* subnormal y, shift y to normal */
n = -1022-iy;
if(n<=31) {
hy = (hy<<n)|(ly>>(32-n));
ly <<= n;
} else {
hy = ly<<(n-32);
ly = 0;
}
}
 
/* fix point fmod */
n = ix - iy;
q = 0;
while(n--) {
hz=hx-hy;lz=lx-ly; if(lx<ly) hz -= 1;
if(hz<0){hx = hx+hx+(lx>>31); lx = lx+lx;}
else {hx = hz+hz+(lz>>31); lx = lz+lz; q++;}
q <<= 1;
}
hz=hx-hy;lz=lx-ly; if(lx<ly) hz -= 1;
if(hz>=0) {hx=hz;lx=lz;q++;}
 
/* convert back to floating value and restore the sign */
if((hx|lx)==0) { /* return sign(x)*0 */
q &= QUO_MASK;
*quo = (sxy ? -q : q);
return Zero[(__uint32_t)sx>>31];
}
while(hx<0x00100000) { /* normalize x */
hx = hx+hx+(lx>>31); lx = lx+lx;
iy -= 1;
}
if(iy>= -1022) { /* normalize output */
hx = ((hx-0x00100000)|((iy+1023)<<20));
} else { /* subnormal output */
n = -1022 - iy;
if(n<=20) {
lx = (lx>>n)|((__uint32_t)hx<<(32-n));
hx >>= n;
} else if (n<=31) {
lx = (hx<<(32-n))|(lx>>n); hx = sx;
} else {
lx = hx>>(n-32); hx = sx;
}
}
fixup:
INSERT_WORDS(x,hx,lx);
y = fabs(y);
if (y < 0x1p-1021) {
if (x+x>y || (x+x==y && (q & 1))) {
q++;
x-=y;
}
} else if (x>0.5*y || (x==0.5*y && (q & 1))) {
q++;
x-=y;
}
GET_HIGH_WORD(hx,x);
SET_HIGH_WORD(x,hx^sx);
q &= QUO_MASK;
*quo = (sxy ? -q : q);
return x;
}
/programs/develop/libraries/newlib/math/s_rint.c
0,0 → 1,132
 
/* @(#)s_rint.c 5.1 93/09/24 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
/*
FUNCTION
<<rint>>, <<rintf>>--round to integer
INDEX
rint
INDEX
rintf
 
ANSI_SYNOPSIS
#include <math.h>
double rint(double <[x]>);
float rintf(float <[x]>);
 
DESCRIPTION
The <<rint>> functions round their argument to an integer value in
floating-point format, using the current rounding direction. They
raise the "inexact" floating-point exception if the result differs
in value from the argument. See the <<nearbyint>> functions for the
same function with the "inexact" floating-point exception never being
raised. Newlib does not directly support floating-point exceptions.
The <<rint>> functions are written so that the "inexact" exception is
raised in hardware implementations that support it, even though Newlib
does not provide access.
 
RETURNS
<[x]> rounded to an integral value, using the current rounding direction.
 
PORTABILITY
ANSI C, POSIX
 
SEEALSO
<<nearbyint>>, <<round>>
 
*/
 
/*
* rint(x)
* Return x rounded to integral value according to the prevailing
* rounding mode.
* Method:
* Using floating addition.
* Whenever a fraction is present, if the second or any following bit after
* the radix point is set, limit to the second radix point to avoid
* possible double rounding in the TWO52 +- steps (in case guard bits are
* used). Specifically, if have any, chop off bits past the 2nd place and
* set the second place.
* (e.g. 2.0625=0b10.0001 => 0b10.01=2.25;
* 2.3125=0b10.011 => 0b10.01=2.25;
* 1.5625= 0b1.1001 => 0b1.11=1.75;
* 1.9375= 0b1.1111 => 0b1.11=1.75.
* Pseudo-code: if(x.frac & ~0b0.10) x.frac = (x.frac & 0b0.11) | 0b0.01;).
* Exception:
* Inexact flag raised if x not equal to rint(x).
*/
 
#include "fdlibm.h"
 
#ifndef _DOUBLE_IS_32BITS
 
#ifdef __STDC__
static const double
#else
static double
#endif
TWO52[2]={
4.50359962737049600000e+15, /* 0x43300000, 0x00000000 */
-4.50359962737049600000e+15, /* 0xC3300000, 0x00000000 */
};
 
#ifdef __STDC__
double rint(double x)
#else
double rint(x)
double x;
#endif
{
__int32_t i0,j0,sx;
__uint32_t i,i1;
double t;
volatile double w;
EXTRACT_WORDS(i0,i1,x);
sx = (i0>>31)&1; /* sign */
j0 = ((i0>>20)&0x7ff)-0x3ff; /* exponent */
if(j0<20) { /* no integral bits in LS part */
if(j0<0) { /* x is fractional or 0 */
if(((i0&0x7fffffff)|i1)==0) return x; /* x == 0 */
i1 |= (i0&0x0fffff);
i0 &= 0xfffe0000;
i0 |= ((i1|-i1)>>12)&0x80000;
SET_HIGH_WORD(x,i0);
w = TWO52[sx]+x;
t = w-TWO52[sx];
GET_HIGH_WORD(i0,t);
SET_HIGH_WORD(t,(i0&0x7fffffff)|(sx<<31));
return t;
} else { /* x has integer and maybe fraction */
i = (0x000fffff)>>j0;
if(((i0&i)|i1)==0) return x; /* x is integral */
i>>=1;
if(((i0&i)|i1)!=0) {
/* 2nd or any later bit after radix is set */
if(j0==19) i1 = 0x80000000; else i1 = 0;
i0 = (i0&(~i))|((0x40000)>>j0);
}
}
} else if (j0>51) {
if(j0==0x400) return x+x; /* inf or NaN */
else return x; /* x is integral */
} else {
i = ((__uint32_t)(0xffffffff))>>(j0-20);
if((i1&i)==0) return x; /* x is integral */
i>>=1;
if((i1&i)!=0) i1 = (i1&(~i))|((0x40000000)>>(j0-20));
}
INSERT_WORDS(x,i0,i1);
w = TWO52[sx]+x;
return w-TWO52[sx];
}
 
#endif /* _DOUBLE_IS_32BITS */
/programs/develop/libraries/newlib/math/s_round.c
0,0 → 1,115
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
/*
FUNCTION
<<round>>, <<roundf>>--round to integer, to nearest
INDEX
round
INDEX
roundf
 
ANSI_SYNOPSIS
#include <math.h>
double round(double <[x]>);
float roundf(float <[x]>);
 
DESCRIPTION
The <<round>> functions round their argument to the nearest integer
value in floating-point format, rounding halfway cases away from zero,
regardless of the current rounding direction. (While the "inexact"
floating-point exception behavior is unspecified by the C standard, the
<<round>> functions are written so that "inexact" is not raised if the
result does not equal the argument, which behavior is as recommended by
IEEE 754 for its related functions.)
 
RETURNS
<[x]> rounded to an integral value.
 
PORTABILITY
ANSI C, POSIX
 
SEEALSO
<<nearbyint>>, <<rint>>
 
*/
 
#include "fdlibm.h"
 
#ifndef _DOUBLE_IS_32BITS
 
#ifdef __STDC__
double round(double x)
#else
double round(x)
double x;
#endif
{
/* Most significant word, least significant word. */
__int32_t msw, exponent_less_1023;
__uint32_t lsw;
 
EXTRACT_WORDS(msw, lsw, x);
 
/* Extract exponent field. */
exponent_less_1023 = ((msw & 0x7ff00000) >> 20) - 1023;
 
if (exponent_less_1023 < 20)
{
if (exponent_less_1023 < 0)
{
msw &= 0x80000000;
if (exponent_less_1023 == -1)
/* Result is +1.0 or -1.0. */
msw |= (1023 << 20);
lsw = 0;
}
else
{
__uint32_t exponent_mask = 0x000fffff >> exponent_less_1023;
if ((msw & exponent_mask) == 0 && lsw == 0)
/* x in an integral value. */
return x;
 
msw += 0x00080000 >> exponent_less_1023;
msw &= ~exponent_mask;
lsw = 0;
}
}
else if (exponent_less_1023 > 51)
{
if (exponent_less_1023 == 1024)
/* x is NaN or infinite. */
return x + x;
else
return x;
}
else
{
__uint32_t exponent_mask = 0xffffffff >> (exponent_less_1023 - 20);
__uint32_t tmp;
 
if ((lsw & exponent_mask) == 0)
/* x is an integral value. */
return x;
 
tmp = lsw + (1 << (51 - exponent_less_1023));
if (tmp < lsw)
msw += 1;
lsw = tmp;
 
lsw &= ~exponent_mask;
}
INSERT_WORDS(x, msw, lsw);
 
return x;
}
 
#endif /* _DOUBLE_IS_32BITS */
/programs/develop/libraries/newlib/math/s_scalbln.c
0,0 → 1,64
/* @(#)s_scalbn.c 5.1 93/09/24 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
/*
* scalbn (double x, int n)
* scalbn(x,n) returns x* 2**n computed by exponent
* manipulation rather than by actually performing an
* exponentiation or a multiplication.
*/
 
#include "fdlibm.h"
 
#ifndef _DOUBLE_IS_32BITS
 
#ifdef __STDC__
static const double
#else
static double
#endif
two54 = 1.80143985094819840000e+16, /* 0x43500000, 0x00000000 */
twom54 = 5.55111512312578270212e-17, /* 0x3C900000, 0x00000000 */
huge = 1.0e+300,
tiny = 1.0e-300;
 
#ifdef __STDC__
double scalbln (double x, long int n)
#else
double scalbln (x,n)
double x; long int n;
#endif
{
__int32_t 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 (k==0x7ff) return x+x; /* NaN or Inf */
k = k+n;
if (n> 50000 || k > 0x7fe)
return huge*copysign(huge,x); /* overflow */
if (n< -50000) return tiny*copysign(tiny,x); /*underflow*/
if (k > 0) /* normal result */
{SET_HIGH_WORD(x,(hx&0x800fffff)|(k<<20)); return x;}
if (k <= -54)
return tiny*copysign(tiny,x); /*underflow*/
k += 54; /* subnormal result */
SET_HIGH_WORD(x,(hx&0x800fffff)|(k<<20));
return x*twom54;
}
 
#endif /* _DOUBLE_IS_32BITS */
/programs/develop/libraries/newlib/math/s_scalbn.c
0,0 → 1,110
 
/* @(#)s_scalbn.c 5.1 93/09/24 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
/*
FUNCTION
<<scalbn>>, <<scalbnf>>, <<scalbln>>, <<scalblnf>>--scale by power of FLT_RADIX (=2)
INDEX
scalbn
INDEX
scalbnf
INDEX
scalbln
INDEX
scalblnf
 
ANSI_SYNOPSIS
#include <math.h>
double scalbn(double <[x]>, int <[n]>);
float scalbnf(float <[x]>, int <[n]>);
double scalbln(double <[x]>, long int <[n]>);
float scalblnf(float <[x]>, long int <[n]>);
 
DESCRIPTION
The <<scalbn>> and <<scalbln>> functions compute
@ifnottex
<[x]> times FLT_RADIX to the power <[n]>.
@end ifnottex
@tex
$x \cdot FLT\_RADIX^n$.
@end tex
efficiently. The result is computed by manipulating the exponent, rather than
by actually performing an exponentiation or multiplication. In this
floating-point implementation FLT_RADIX=2, which makes the <<scalbn>>
functions equivalent to the <<ldexp>> functions.
 
RETURNS
<[x]> times 2 to the power <[n]>. A range error may occur.
 
PORTABILITY
ANSI C, POSIX
 
SEEALSO
<<ldexp>>
 
*/
 
/*
* scalbn (double x, int n)
* scalbn(x,n) returns x* 2**n computed by exponent
* manipulation rather than by actually performing an
* exponentiation or a multiplication.
*/
 
#include "fdlibm.h"
 
#ifndef _DOUBLE_IS_32BITS
 
#ifdef __STDC__
static const double
#else
static double
#endif
two54 = 1.80143985094819840000e+16, /* 0x43500000, 0x00000000 */
twom54 = 5.55111512312578270212e-17, /* 0x3C900000, 0x00000000 */
huge = 1.0e+300,
tiny = 1.0e-300;
 
#ifdef __STDC__
double scalbn (double x, int n)
#else
double scalbn (x,n)
double x; int n;
#endif
{
__int32_t 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 huge*copysign(huge,x); /* overflow */
if (k > 0) /* normal result */
{SET_HIGH_WORD(x,(hx&0x800fffff)|(k<<20)); return x;}
if (k <= -54) {
if (n > 50000) /* in case integer overflow in n+k */
return huge*copysign(huge,x); /*overflow*/
else return tiny*copysign(tiny,x); /*underflow*/
}
k += 54; /* subnormal result */
SET_HIGH_WORD(x,(hx&0x800fffff)|(k<<20));
return x*twom54;
}
 
#endif /* _DOUBLE_IS_32BITS */
/programs/develop/libraries/newlib/math/s_signbit.c
3,7 → 3,36
* Permission to use, copy, modify, and distribute this software
* is freely granted, provided that this notice is preserved.
*/
/*
FUNCTION
<<signbit>>--Does floating-point number have negative sign?
 
INDEX
signbit
 
ANSI_SYNOPSIS
#include <math.h>
int signbit(real-floating <[x]>);
 
DESCRIPTION
The <<signbit>> macro determines whether the sign of its argument value is
negative. The macro reports the sign of all values, including infinities,
zeros, and NaNs. If zero is unsigned, it is treated as positive. As shown in
the synopsis, the argument is "real-floating," meaning that any of the real
floating-point types (float, double, etc.) may be given to it.
 
Note that because of the possibilities of signed 0 and NaNs, the expression
"<[x]> < 0.0" does not give the same result as <<signbit>> in all cases.
 
RETURNS
The <<signbit>> macro returns a nonzero value if and only if the sign of its
argument value is negative.
 
PORTABILITY
C99, POSIX.
 
*/
 
#include "fdlibm.h"
 
int __signbitf (float x);
/programs/develop/libraries/newlib/math/s_signif.c
0,0 → 1,34
 
/* @(#)s_signif.c 5.1 93/09/24 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
/*
* significand(x) computes just
* scalb(x, (double) -ilogb(x)),
* for exercising the fraction-part(F) IEEE 754-1985 test vector.
*/
 
#include "fdlibm.h"
 
#ifndef _DOUBLE_IS_32BITS
 
#ifdef __STDC__
double significand(double x)
#else
double significand(x)
double x;
#endif
{
return __ieee754_scalb(x,(double) -ilogb(x));
}
 
#endif /* _DOUBLE_IS_32BITS */
/programs/develop/libraries/newlib/math/s_sin.c
0,0 → 1,132
 
/* @(#)s_sin.c 5.1 93/09/24 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
/*
FUNCTION
<<sin>>, <<sinf>>, <<cos>>, <<cosf>>---sine or cosine
INDEX
sin
INDEX
sinf
INDEX
cos
INDEX
cosf
ANSI_SYNOPSIS
#include <math.h>
double sin(double <[x]>);
float sinf(float <[x]>);
double cos(double <[x]>);
float cosf(float <[x]>);
 
TRAD_SYNOPSIS
#include <math.h>
double sin(<[x]>)
double <[x]>;
float sinf(<[x]>)
float <[x]>;
 
double cos(<[x]>)
double <[x]>;
float cosf(<[x]>)
float <[x]>;
 
DESCRIPTION
<<sin>> and <<cos>> compute (respectively) the sine and cosine
of the argument <[x]>. Angles are specified in radians.
 
<<sinf>> and <<cosf>> are identical, save that they take and
return <<float>> values.
 
 
RETURNS
The sine or cosine of <[x]> is returned.
 
PORTABILITY
<<sin>> and <<cos>> are ANSI C.
<<sinf>> and <<cosf>> are extensions.
 
QUICKREF
sin ansi pure
sinf - pure
*/
 
/* sin(x)
* Return sine function of x.
*
* kernel function:
* __kernel_sin ... sine function on [-pi/4,pi/4]
* __kernel_cos ... cose function on [-pi/4,pi/4]
* __ieee754_rem_pio2 ... argument reduction routine
*
* Method.
* Let S,C and T denote the sin, cos and tan respectively on
* [-PI/4, +PI/4]. Reduce the argument x to y1+y2 = x-k*pi/2
* in [-pi/4 , +pi/4], and let n = k mod 4.
* We have
*
* n sin(x) cos(x) tan(x)
* ----------------------------------------------------------
* 0 S C T
* 1 C -S -1/T
* 2 -S -C T
* 3 -C S -1/T
* ----------------------------------------------------------
*
* Special cases:
* Let trig be any of sin, cos, or tan.
* trig(+-INF) is NaN, with signals;
* trig(NaN) is that NaN;
*
* Accuracy:
* TRIG(x) returns trig(x) nearly rounded
*/
 
#include "fdlibm.h"
 
#ifndef _DOUBLE_IS_32BITS
 
#ifdef __STDC__
double sin(double x)
#else
double sin(x)
double x;
#endif
{
double y[2],z=0.0;
__int32_t n,ix;
 
/* High word of x. */
GET_HIGH_WORD(ix,x);
 
/* |x| ~< pi/4 */
ix &= 0x7fffffff;
if(ix <= 0x3fe921fb) return __kernel_sin(x,z,0);
 
/* sin(Inf or NaN) is NaN */
else if (ix>=0x7ff00000) return x-x;
 
/* argument reduction needed */
else {
n = __ieee754_rem_pio2(x,y);
switch(n&3) {
case 0: return __kernel_sin(y[0],y[1],1);
case 1: return __kernel_cos(y[0],y[1]);
case 2: return -__kernel_sin(y[0],y[1],1);
default:
return -__kernel_cos(y[0],y[1]);
}
}
}
 
#endif /* _DOUBLE_IS_32BITS */
/programs/develop/libraries/newlib/math/s_tan.c
0,0 → 1,114
 
/* @(#)s_tan.c 5.1 93/09/24 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
 
/*
 
FUNCTION
<<tan>>, <<tanf>>---tangent
 
INDEX
tan
INDEX
tanf
 
ANSI_SYNOPSIS
#include <math.h>
double tan(double <[x]>);
float tanf(float <[x]>);
 
TRAD_SYNOPSIS
#include <math.h>
double tan(<[x]>)
double <[x]>;
 
float tanf(<[x]>)
float <[x]>;
 
 
DESCRIPTION
<<tan>> computes the tangent of the argument <[x]>.
Angles are specified in radians.
 
<<tanf>> is identical, save that it takes and returns <<float>> values.
 
RETURNS
The tangent of <[x]> is returned.
 
PORTABILITY
<<tan>> is ANSI. <<tanf>> is an extension.
*/
 
/* tan(x)
* Return tangent function of x.
*
* kernel function:
* __kernel_tan ... tangent function on [-pi/4,pi/4]
* __ieee754_rem_pio2 ... argument reduction routine
*
* Method.
* Let S,C and T denote the sin, cos and tan respectively on
* [-PI/4, +PI/4]. Reduce the argument x to y1+y2 = x-k*pi/2
* in [-pi/4 , +pi/4], and let n = k mod 4.
* We have
*
* n sin(x) cos(x) tan(x)
* ----------------------------------------------------------
* 0 S C T
* 1 C -S -1/T
* 2 -S -C T
* 3 -C S -1/T
* ----------------------------------------------------------
*
* Special cases:
* Let trig be any of sin, cos, or tan.
* trig(+-INF) is NaN, with signals;
* trig(NaN) is that NaN;
*
* Accuracy:
* TRIG(x) returns trig(x) nearly rounded
*/
 
#include "fdlibm.h"
 
#ifndef _DOUBLE_IS_32BITS
 
#ifdef __STDC__
double tan(double x)
#else
double tan(x)
double x;
#endif
{
double y[2],z=0.0;
__int32_t n,ix;
 
/* High word of x. */
GET_HIGH_WORD(ix,x);
 
/* |x| ~< pi/4 */
ix &= 0x7fffffff;
if(ix <= 0x3fe921fb) return __kernel_tan(x,z,1);
 
/* tan(Inf or NaN) is NaN */
else if (ix>=0x7ff00000) return x-x; /* NaN */
 
/* argument reduction needed */
else {
n = __ieee754_rem_pio2(x,y);
return __kernel_tan(y[0],y[1],1-((n&1)<<1)); /* 1 -- n even
-1 -- n odd */
}
}
 
#endif /* _DOUBLE_IS_32BITS */
/programs/develop/libraries/newlib/math/s_tanh.c
1,3 → 1,4
 
/* @(#)s_tanh.c 5.1 93/09/24 */
/*
* ====================================================
10,7 → 11,48
* ====================================================
*/
 
/*
 
FUNCTION
<<tanh>>, <<tanhf>>---hyperbolic tangent
 
INDEX
tanh
INDEX
tanhf
 
ANSI_SYNOPSIS
#include <math.h>
double tanh(double <[x]>);
float tanhf(float <[x]>);
 
TRAD_SYNOPSIS
#include <math.h>
double tanh(<[x]>)
double <[x]>;
 
float tanhf(<[x]>)
float <[x]>;
 
 
DESCRIPTION
 
<<tanh>> computes the hyperbolic tangent of
the argument <[x]>. Angles are specified in radians.
 
<<tanh(<[x]>)>> is defined as
. sinh(<[x]>)/cosh(<[x]>)
<<tanhf>> is identical, save that it takes and returns <<float>> values.
 
RETURNS
The hyperbolic tangent of <[x]> is returned.
 
PORTABILITY
<<tanh>> is ANSI C. <<tanhf>> is an extension.
 
*/
 
/* Tanh(x)
* Return the Hyperbolic Tangent of x
*
35,9 → 77,10
* only tanh(0)=0 is exact for finite argument.
*/
 
#include <math.h>
#include "fdlibm.h"
 
#ifndef _DOUBLE_IS_32BITS
 
#ifdef __STDC__
static const double one=1.0, two=2.0, tiny = 1.0e-300;
#else
44,13 → 87,18
static double one=1.0, two=2.0, tiny = 1.0e-300;
#endif
 
#ifdef __STDC__
double tanh(double x)
#else
double tanh(x)
double x;
#endif
{
double t,z;
int jx,ix,lx;
__int32_t jx,ix;
 
/* High word of |x|. */
EXTRACT_WORDS(jx,lx,x);
GET_HIGH_WORD(jx,x);
ix = jx&0x7fffffff;
 
/* x is INF or NaN */
61,15 → 109,13
 
/* |x| < 22 */
if (ix < 0x40360000) { /* |x|<22 */
if ((ix | lx) == 0)
return x; /* x == +-0 */
if (ix<0x3c800000) /* |x|<2**-55 */
return x*(one+x); /* tanh(small) = small */
if (ix>=0x3ff00000) { /* |x|>=1 */
t = __expm1(two*fabs(x));
t = expm1(two*fabs(x));
z = one - two/(t+two);
} else {
t = __expm1(-two*fabs(x));
t = expm1(-two*fabs(x));
z= -t/(t+two);
}
/* |x| > 22, return +-1 */
78,3 → 124,5
}
return (jx>=0)? z: -z;
}
 
#endif /* _DOUBLE_IS_32BITS */
/programs/develop/libraries/newlib/math/s_trunc.c
0,0 → 1,98
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
/*
FUNCTION
<<trunc>>, <<truncf>>--round to integer, towards zero
INDEX
trunc
INDEX
truncf
 
ANSI_SYNOPSIS
#include <math.h>
double trunc(double <[x]>);
float truncf(float <[x]>);
 
DESCRIPTION
The <<trunc>> functions round their argument to the integer value, in
floating format, nearest to but no larger in magnitude than the
argument, regardless of the current rounding direction. (While the
"inexact" floating-point exception behavior is unspecified by the C
standard, the <<trunc>> functions are written so that "inexact" is not
raised if the result does not equal the argument, which behavior is as
recommended by IEEE 754 for its related functions.)
 
RETURNS
<[x]> truncated to an integral value.
 
PORTABILITY
ANSI C, POSIX
 
*/
 
#include "fdlibm.h"
 
#ifndef _DOUBLE_IS_32BITS
 
#ifdef __STDC__
double trunc(double x)
#else
double trunc(x)
double x;
#endif
{
int signbit;
/* Most significant word, least significant word. */
int msw;
unsigned int lsw;
int exponent_less_1023;
 
EXTRACT_WORDS(msw, lsw, x);
 
/* Extract sign bit. */
signbit = msw & 0x80000000;
 
/* Extract exponent field. */
exponent_less_1023 = ((msw & 0x7ff00000) >> 20) - 1023;
 
if (exponent_less_1023 < 20)
{
/* All significant digits are in msw. */
if (exponent_less_1023 < 0)
{
/* -1 < x < 1, so result is +0 or -0. */
INSERT_WORDS(x, signbit, 0);
}
else
{
/* All relevant fraction bits are in msw, so lsw of the result is 0. */
INSERT_WORDS(x, signbit | (msw & ~(0x000fffff >> exponent_less_1023)), 0);
}
}
else if (exponent_less_1023 > 51)
{
if (exponent_less_1023 == 1024)
{
/* x is infinite, or not a number, so trigger an exception. */
return x + x;
}
/* All bits in the fraction fields of the msw and lsw are needed in the result. */
}
else
{
/* All fraction bits in msw are relevant. Truncate irrelevant
bits from lsw. */
INSERT_WORDS(x, msw, lsw & ~(0xffffffffu >> (exponent_less_1023 - 20)));
}
return x;
}
 
#endif /* _DOUBLE_IS_32BITS */
/programs/develop/libraries/newlib/math/scalblnl.c
0,0 → 1,42
/*
(C) Copyright IBM Corp. 2009
 
All rights reserved.
 
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
 
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of IBM nor the names of its contributors may be
used to endorse or promote products derived from this software without
specific prior written permission.
 
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
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.
*/
 
#include <math.h>
#include "local.h"
 
/* On platforms where long double is as wide as double. */
#ifdef _LDBL_EQ_DBL
long double
scalblnl (long double x, long n)
{
return scalbln(x, n);
}
#endif
 
/programs/develop/libraries/newlib/math/scalbnl.c
0,0 → 1,42
/*
(C) Copyright IBM Corp. 2009
 
All rights reserved.
 
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
 
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of IBM nor the names of its contributors may be
used to endorse or promote products derived from this software without
specific prior written permission.
 
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
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.
*/
 
#include <math.h>
#include "local.h"
 
/* On platforms where long double is as wide as double. */
#ifdef _LDBL_EQ_DBL
long double
scalbnl (long double x, int n)
{
return scalbn(x, n);
}
#endif
 
/programs/develop/libraries/newlib/math/sf_asinh.c
0,0 → 1,66
/* sf_asinh.c -- float version of s_asinh.c.
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
*/
 
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#include "fdlibm.h"
 
#ifdef __STDC__
static const float
#else
static float
#endif
one = 1.0000000000e+00, /* 0x3F800000 */
ln2 = 6.9314718246e-01, /* 0x3f317218 */
huge= 1.0000000000e+30;
 
#ifdef __STDC__
float asinhf(float x)
#else
float asinhf(x)
float x;
#endif
{
float t,w;
__int32_t hx,ix;
GET_FLOAT_WORD(hx,x);
ix = hx&0x7fffffff;
if(!FLT_UWORD_IS_FINITE(ix)) return x+x; /* x is inf or NaN */
if(ix< 0x31800000) { /* |x|<2**-28 */
if(huge+x>one) return x; /* return x inexact except 0 */
}
if(ix>0x4d800000) { /* |x| > 2**28 */
w = __ieee754_logf(fabsf(x))+ln2;
} else if (ix>0x40000000) { /* 2**28 > |x| > 2.0 */
t = fabsf(x);
w = __ieee754_logf((float)2.0*t+one/(__ieee754_sqrtf(x*x+one)+t));
} else { /* 2.0 > |x| > 2**-28 */
t = x*x;
w =log1pf(fabsf(x)+t/(one+__ieee754_sqrtf(one+t)));
}
if(hx>0) return w; else return -w;
}
 
#ifdef _DOUBLE_IS_32BITS
 
#ifdef __STDC__
double asinh(double x)
#else
double asinh(x)
double x;
#endif
{
return (double) asinhf((float) x);
}
 
#endif /* defined(_DOUBLE_IS_32BITS) */
/programs/develop/libraries/newlib/math/sf_atan.c
0,0 → 1,129
/* sf_atan.c -- float version of s_atan.c.
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
*/
 
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*
*/
 
#include "fdlibm.h"
 
#ifdef __STDC__
static const float atanhi[] = {
#else
static float atanhi[] = {
#endif
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 */
};
 
#ifdef __STDC__
static const float atanlo[] = {
#else
static float atanlo[] = {
#endif
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 */
};
 
#ifdef __STDC__
static const float aT[] = {
#else
static float aT[] = {
#endif
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 */
};
 
#ifdef __STDC__
static const float
#else
static float
#endif
one = 1.0,
huge = 1.0e30;
 
#ifdef __STDC__
float atanf(float x)
#else
float atanf(x)
float x;
#endif
{
float w,s1,s2,z;
__int32_t ix,hx,id;
 
GET_FLOAT_WORD(hx,x);
ix = hx&0x7fffffff;
if(ix>=0x50800000) { /* if |x| >= 2^34 */
if(FLT_UWORD_IS_NAN(ix))
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;
}
}
 
#ifdef _DOUBLE_IS_32BITS
 
#ifdef __STDC__
double atan(double x)
#else
double atan(x)
double x;
#endif
{
return (double) atanf((float) x);
}
 
#endif /* defined(_DOUBLE_IS_32BITS) */
/programs/develop/libraries/newlib/math/sf_cbrt.c
0,0 → 1,94
/* sf_cbrt.c -- float version of s_cbrt.c.
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
*/
 
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*
*/
 
#include "fdlibm.h"
 
/* cbrtf(x)
* Return cube root of x
*/
#ifdef __STDC__
static const __uint32_t
#else
static __uint32_t
#endif
B1 = 709958130, /* B1 = (84+2/3-0.03306235651)*2**23 */
B2 = 642849266; /* B2 = (76+2/3-0.03306235651)*2**23 */
 
#ifdef __STDC__
static const float
#else
static float
#endif
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 */
 
#ifdef __STDC__
float cbrtf(float x)
#else
float cbrtf(x)
float x;
#endif
{
__int32_t hx;
float r,s,t;
__uint32_t sign;
__uint32_t high;
 
GET_FLOAT_WORD(hx,x);
sign=hx&0x80000000; /* sign= sign(x) */
hx ^=sign;
if(!FLT_UWORD_IS_FINITE(hx))
return(x+x); /* cbrt(NaN,INF) is itself */
if(FLT_UWORD_IS_ZERO(hx))
return(x); /* cbrt(0) is itself */
 
SET_FLOAT_WORD(x,hx); /* x <- |x| */
/* rough cbrt to 5 bits */
if(FLT_UWORD_IS_SUBNORMAL(hx)) /* 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);
}
 
#ifdef _DOUBLE_IS_32BITS
 
#ifdef __STDC__
double cbrt(double x)
#else
double cbrt(x)
double x;
#endif
{
return (double) cbrtf((float) x);
}
 
#endif /* defined(_DOUBLE_IS_32BITS) */
/programs/develop/libraries/newlib/math/sf_ceil.c
0,0 → 1,70
/* sf_ceil.c -- float version of s_ceil.c.
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
*/
 
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#include "fdlibm.h"
 
#ifdef __STDC__
static const float huge = 1.0e30;
#else
static float huge = 1.0e30;
#endif
 
#ifdef __STDC__
float ceilf(float x)
#else
float ceilf(x)
float x;
#endif
{
__int32_t i0,j0;
__uint32_t i,ix;
GET_FLOAT_WORD(i0,x);
ix = (i0&0x7fffffff);
j0 = (ix>>23)-0x7f;
if(j0<23) {
if(j0<0) { /* raise inexact if x != 0 */
if(huge+x>(float)0.0) {/* return 0*sign(x) if |x|<1 */
if(i0<0) {i0=0x80000000;}
else if(!FLT_UWORD_IS_ZERO(ix)) { i0=0x3f800000;}
}
} else {
i = (0x007fffff)>>j0;
if((i0&i)==0) return x; /* x is integral */
if(huge+x>(float)0.0) { /* raise inexact flag */
if(i0>0) i0 += (0x00800000)>>j0;
i0 &= (~i);
}
}
} else {
if(!FLT_UWORD_IS_FINITE(ix)) return x+x; /* inf or NaN */
else return x; /* x is integral */
}
SET_FLOAT_WORD(x,i0);
return x;
}
 
#ifdef _DOUBLE_IS_32BITS
 
#ifdef __STDC__
double ceil(double x)
#else
double ceil(x)
double x;
#endif
{
return (double) ceilf((float) x);
}
 
#endif /* defined(_DOUBLE_IS_32BITS) */
/programs/develop/libraries/newlib/math/sf_copysign.c
0,0 → 1,50
/* sf_copysign.c -- float version of s_copysign.c.
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
*/
 
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
/*
* copysignf(float x, float y)
* copysignf(x,y) returns a value with the magnitude of x and
* with the sign bit of y.
*/
 
#include "fdlibm.h"
 
#ifdef __STDC__
float copysignf(float x, float y)
#else
float copysignf(x,y)
float x,y;
#endif
{
__uint32_t ix,iy;
GET_FLOAT_WORD(ix,x);
GET_FLOAT_WORD(iy,y);
SET_FLOAT_WORD(x,(ix&0x7fffffff)|(iy&0x80000000));
return x;
}
 
#ifdef _DOUBLE_IS_32BITS
 
#ifdef __STDC__
double copysign(double x, double y)
#else
double copysign(x,y)
double x,y;
#endif
{
return (double) copysignf((float) x, (float) y);
}
 
#endif /* defined(_DOUBLE_IS_32BITS) */
/programs/develop/libraries/newlib/math/sf_cos.c
0,0 → 1,68
/* sf_cos.c -- float version of s_cos.c.
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
*/
 
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#include "fdlibm.h"
 
#ifdef __STDC__
static const float one=1.0;
#else
static float one=1.0;
#endif
 
#ifdef __STDC__
float cosf(float x)
#else
float cosf(x)
float x;
#endif
{
float y[2],z=0.0;
__int32_t n,ix;
 
GET_FLOAT_WORD(ix,x);
 
/* |x| ~< pi/4 */
ix &= 0x7fffffff;
if(ix <= 0x3f490fd8) return __kernel_cosf(x,z);
 
/* cos(Inf or NaN) is NaN */
else if (!FLT_UWORD_IS_FINITE(ix)) return x-x;
 
/* argument reduction needed */
else {
n = __ieee754_rem_pio2f(x,y);
switch(n&3) {
case 0: return __kernel_cosf(y[0],y[1]);
case 1: return -__kernel_sinf(y[0],y[1],1);
case 2: return -__kernel_cosf(y[0],y[1]);
default:
return __kernel_sinf(y[0],y[1],1);
}
}
}
 
#ifdef _DOUBLE_IS_32BITS
 
#ifdef __STDC__
double cos(double x)
#else
double cos(x)
double x;
#endif
{
return (double) cosf((float) x);
}
 
#endif /* defined(_DOUBLE_IS_32BITS) */
/programs/develop/libraries/newlib/math/sf_erf.c
13,49 → 13,8
* ====================================================
*/
 
/*
#include "fdlibm.h"
*/
#include <math.h>
#include <stdint.h>
#include <errno.h>
 
#define __ieee754_expf expf
 
 
 
typedef union
{
float value;
uint32_t word;
} ieee_float_shape_type;
 
/* Get a 32 bit int from a float. */
 
static inline int
__get_float_word(float d)
{
ieee_float_shape_type u;
u.value = d;
return u.word;
}
 
/* Set a float from a 32 bit int. */
 
#define SET_FLOAT_WORD(d,i) \
do { \
ieee_float_shape_type sf_u; \
sf_u.word = (i); \
(d) = sf_u.value; \
} while (0)
 
static inline void __trunc_float_word(float * x)
{
ieee_float_shape_type u;
u.value = * x;
u.word &= 0xfffff000;
}
 
#ifdef __v810__
#define const
#endif
146,12 → 105,12
float x;
#endif
{
int32_t hx,ix,i;
__int32_t hx,ix,i;
float R,S,P,Q,s,y,z,r;
hx = __get_float_word(x);
GET_FLOAT_WORD(hx,x);
ix = hx&0x7fffffff;
if(!(ix<0x7f800000L)) { /* erf(nan)=nan */
i = ((uint32_t)hx>>31)<<1;
if(!FLT_UWORD_IS_FINITE(ix)) { /* erf(nan)=nan */
i = ((__uint32_t)hx>>31)<<1;
return (float)(1-i)+one/x; /* erf(+-inf)=+-1 */
}
 
190,9 → 149,8
S=one+s*(sb1+s*(sb2+s*(sb3+s*(sb4+s*(
sb5+s*(sb6+s*sb7))))));
}
 
z = x;
__trunc_float_word (&z);
GET_FLOAT_WORD(ix,x);
SET_FLOAT_WORD(z,ix&0xfffff000);
r = __ieee754_expf(-z*z-(float)0.5625)*__ieee754_expf((z-x)*(z+x)+R/S);
if(hx>=0) return one-r/x; else return r/x-one;
}
204,13 → 162,13
float x;
#endif
{
int32_t hx,ix;
__int32_t hx,ix;
float R,S,P,Q,s,y,z,r;
hx = __get_float_word(x);
GET_FLOAT_WORD(hx,x);
ix = hx&0x7fffffff;
if(!(ix<0x7f800000L)) { /* erfc(nan)=nan */
if(!FLT_UWORD_IS_FINITE(ix)) { /* erfc(nan)=nan */
/* erfc(+-inf)=0,2 */
return (float)(((uint32_t)hx>>31)<<1)+one/x;
return (float)(((__uint32_t)hx>>31)<<1)+one/x;
}
 
if(ix < 0x3f580000) { /* |x|<0.84375 */
238,7 → 196,6
z = erx+P/Q; return one+z;
}
}
 
if (ix < 0x41e00000) { /* |x|<28 */
x = fabsf(x);
s = one/(x*x);
254,14 → 211,36
S=one+s*(sb1+s*(sb2+s*(sb3+s*(sb4+s*(
sb5+s*(sb6+s*sb7))))));
}
z = x;
__trunc_float_word (&z);
GET_FLOAT_WORD(ix,x);
SET_FLOAT_WORD(z,ix&0xfffff000);
r = __ieee754_expf(-z*z-(float)0.5625)*
__ieee754_expf((z-x)*(z+x)+R/S);
if(hx>0) return r/x; else return two-r/x;
} else {
/* set range error */
errno = ERANGE;
if(hx>0) return tiny*tiny; else return two-tiny;
}
}
 
#ifdef _DOUBLE_IS_32BITS
 
#ifdef __STDC__
double erf(double x)
#else
double erf(x)
double x;
#endif
{
return (double) erff((float) x);
}
 
#ifdef __STDC__
double erfc(double x)
#else
double erfc(x)
double x;
#endif
{
return (double) erfcf((float) x);
}
 
#endif /* defined(_DOUBLE_IS_32BITS) */
/programs/develop/libraries/newlib/math/sf_exp10.c
0,0 → 1,47
/* sf_exp10.c -- float version of s_exp10.c.
* Modification of sf_exp2.c by Yaakov Selkowitz 2007.
*/
 
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
/*
* wrapper exp10f(x)
*/
 
#undef exp10f
#include "fdlibm.h"
#include <errno.h>
#include <math.h>
 
#ifdef __STDC__
float exp10f(float x) /* wrapper exp10f */
#else
float exp10f(x) /* wrapper exp10f */
float x;
#endif
{
return powf(10.0, x);
}
 
#ifdef _DOUBLE_IS_32BITS
 
#ifdef __STDC__
double exp10(double x)
#else
double exp10(x)
double x;
#endif
{
return (double) exp10f((float) x);
}
 
#endif /* defined(_DOUBLE_IS_32BITS) */
/programs/develop/libraries/newlib/math/sf_expm1.c
0,0 → 1,145
/* sf_expm1.c -- float version of s_expm1.c.
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
*/
 
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#include "fdlibm.h"
 
#ifdef __v810__
#define const
#endif
 
#ifdef __STDC__
static const float
#else
static float
#endif
one = 1.0,
huge = 1.0e+30,
tiny = 1.0e-30,
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 */
 
#ifdef __STDC__
float expm1f(float x)
#else
float expm1f(x)
float x;
#endif
{
float y,hi,lo,c,t,e,hxs,hfx,r1;
__int32_t k,xsb;
__uint32_t hx;
 
GET_FLOAT_WORD(hx,x);
xsb = hx&0x80000000; /* 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(FLT_UWORD_IS_NAN(hx))
return x+x;
if(FLT_UWORD_IS_INFINITE(hx))
return (xsb==0)? x:-1.0;/* exp(+-inf)={inf,-1} */
if(xsb == 0 && hx > FLT_UWORD_LOG_MAX) /* 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 */
__int32_t 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) {
__int32_t 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 {
__int32_t 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;
}
 
#ifdef _DOUBLE_IS_32BITS
 
#ifdef __STDC__
double expm1(double x)
#else
double expm1(x)
double x;
#endif
{
return (double) expm1f((float) x);
}
 
#endif /* defined(_DOUBLE_IS_32BITS) */
/programs/develop/libraries/newlib/math/sf_fabs.c
0,0 → 1,47
/* sf_fabs.c -- float version of s_fabs.c.
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
*/
 
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
/*
* fabsf(x) returns the absolute value of x.
*/
 
#include "fdlibm.h"
 
#ifdef __STDC__
float fabsf(float x)
#else
float fabsf(x)
float x;
#endif
{
__uint32_t ix;
GET_FLOAT_WORD(ix,x);
SET_FLOAT_WORD(x,ix&0x7fffffff);
return x;
}
 
#ifdef _DOUBLE_IS_32BITS
 
#ifdef __STDC__
double fabs(double x)
#else
double fabs(x)
double x;
#endif
{
return (double) fabsf((float) x);
}
 
#endif /* defined(_DOUBLE_IS_32BITS) */
/programs/develop/libraries/newlib/math/sf_fdim.c
0,0 → 1,39
/* Copyright (C) 2002 by Red Hat, Incorporated. All rights reserved.
*
* Permission to use, copy, modify, and distribute this software
* is freely granted, provided that this notice is preserved.
*/
 
#include "fdlibm.h"
 
#ifdef __STDC__
float fdimf(float x, float y)
#else
float fdimf(x,y)
float x;
float y;
#endif
{
int c = __fpclassifyf(x);
if (c == FP_NAN) return(x);
if (__fpclassifyf(y) == FP_NAN) return(y);
if (c == FP_INFINITE)
return HUGE_VALF;
 
return x > y ? x - y : 0.0;
}
 
#ifdef _DOUBLE_IS_32BITS
 
#ifdef __STDC__
double fdim(double x, double y)
#else
double fdim(x,y)
double x;
double y;
#endif
{
return (double) fdimf((float) x, (float) y);
}
 
#endif /* defined(_DOUBLE_IS_32BITS) */
/programs/develop/libraries/newlib/math/sf_finite.c
0,0 → 1,48
/* sf_finite.c -- float version of s_finite.c.
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
*/
 
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
/*
* finitef(x) returns 1 is x is finite, else 0;
* no branching!
*/
 
#include "fdlibm.h"
 
#ifdef __STDC__
int finitef(float x)
#else
int finitef(x)
float x;
#endif
{
__int32_t ix;
GET_FLOAT_WORD(ix,x);
ix &= 0x7fffffff;
return (FLT_UWORD_IS_FINITE(ix));
}
 
#ifdef _DOUBLE_IS_32BITS
 
#ifdef __STDC__
int finite(double x)
#else
int finite(x)
double x;
#endif
{
return finitef((float) x);
}
 
#endif /* defined(_DOUBLE_IS_32BITS) */
/programs/develop/libraries/newlib/math/sf_floor.c
0,0 → 1,80
/* sf_floor.c -- float version of s_floor.c.
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
*/
 
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
/*
* floorf(x)
* Return x rounded toward -inf to integral value
* Method:
* Bit twiddling.
* Exception:
* Inexact flag raised if x not equal to floorf(x).
*/
 
#include "fdlibm.h"
 
#ifdef __STDC__
static const float huge = 1.0e30;
#else
static float huge = 1.0e30;
#endif
 
#ifdef __STDC__
float floorf(float x)
#else
float floorf(x)
float x;
#endif
{
__int32_t i0,j0;
__uint32_t i,ix;
GET_FLOAT_WORD(i0,x);
ix = (i0&0x7fffffff);
j0 = (ix>>23)-0x7f;
if(j0<23) {
if(j0<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(!FLT_UWORD_IS_ZERO(ix))
{ i0=0xbf800000;}
}
} else {
i = (0x007fffff)>>j0;
if((i0&i)==0) return x; /* x is integral */
if(huge+x>(float)0.0) { /* raise inexact flag */
if(i0<0) i0 += (0x00800000)>>j0;
i0 &= (~i);
}
}
} else {
if(!FLT_UWORD_IS_FINITE(ix)) return x+x; /* inf or NaN */
else return x; /* x is integral */
}
SET_FLOAT_WORD(x,i0);
return x;
}
 
#ifdef _DOUBLE_IS_32BITS
 
#ifdef __STDC__
double floor(double x)
#else
double floor(x)
double x;
#endif
{
return (double) floorf((float) x);
}
 
#endif /* defined(_DOUBLE_IS_32BITS) */
/programs/develop/libraries/newlib/math/sf_fma.c
0,0 → 1,42
/* Copyright (C) 2002 by Red Hat, Incorporated. All rights reserved.
*
* Permission to use, copy, modify, and distribute this software
* is freely granted, provided that this notice is preserved.
*/
 
#include "fdlibm.h"
 
#ifdef __STDC__
float fmaf(float x, float y, float z)
#else
float fmaf(x,y,z)
float x;
float y;
float z;
#endif
{
/* NOTE: The floating-point exception behavior of this is not as
* required. But since the basic function is not really done properly,
* it is not worth bothering to get the exceptions right, either. */
/* Let the implementation handle this. */ /* <= NONSENSE! */
/* In floating-point implementations in which double is larger than float,
* computing as double should provide the desired function. Otherwise,
* the behavior will not be as specified in the standards. */
return (float) (((double) x * (double) y) + (double) z);
}
 
#ifdef _DOUBLE_IS_32BITS
 
#ifdef __STDC__
double fma(double x, double y, double z)
#else
double fma(x,y,z)
double x;
double y;
double z;
#endif
{
return (double) fmaf((float) x, (float) y, (float) z);
}
 
#endif /* defined(_DOUBLE_IS_32BITS) */
/programs/develop/libraries/newlib/math/sf_fmax.c
0,0 → 1,38
/* Copyright (C) 2002 by Red Hat, Incorporated. All rights reserved.
*
* Permission to use, copy, modify, and distribute this software
* is freely granted, provided that this notice is preserved.
*/
 
#include "fdlibm.h"
 
#ifdef __STDC__
float fmaxf(float x, float y)
#else
float fmaxf(x,y)
float x;
float y;
#endif
{
if (__fpclassifyf(x) == FP_NAN)
return y;
if (__fpclassifyf(y) == FP_NAN)
return x;
return x > y ? x : y;
}
 
#ifdef _DOUBLE_IS_32BITS
 
#ifdef __STDC__
double fmax(double x, double y)
#else
double fmax(x,y)
double x;
double y;
#endif
{
return (double) fmaxf((float) x, (float) y);
}
 
#endif /* defined(_DOUBLE_IS_32BITS) */
/programs/develop/libraries/newlib/math/sf_fmin.c
0,0 → 1,38
/* Copyright (C) 2002 by Red Hat, Incorporated. All rights reserved.
*
* Permission to use, copy, modify, and distribute this software
* is freely granted, provided that this notice is preserved.
*/
 
#include "fdlibm.h"
 
#ifdef __STDC__
float fminf(float x, float y)
#else
float fminf(x,y)
float x;
float y;
#endif
{
if (__fpclassifyf(x) == FP_NAN)
return y;
if (__fpclassifyf(y) == FP_NAN)
return x;
return x < y ? x : y;
}
 
#ifdef _DOUBLE_IS_32BITS
 
#ifdef __STDC__
double fmin(double x, double y)
#else
double fmin(x,y)
double x;
double y;
#endif
{
return (double) fminf((float) x, (float) y);
}
 
#endif /* defined(_DOUBLE_IS_32BITS) */
/programs/develop/libraries/newlib/math/sf_fpclassify.c
0,0 → 1,29
/* Copyright (C) 2002,2007 by Red Hat, Incorporated. All rights reserved.
*
* Permission to use, copy, modify, and distribute this software
* is freely granted, provided that this notice is preserved.
*/
 
#include "fdlibm.h"
 
int
__fpclassifyf (float x)
{
__uint32_t w;
 
GET_FLOAT_WORD(w,x);
if (w == 0x00000000 || w == 0x80000000)
return FP_ZERO;
else if ((w >= 0x00800000 && w <= 0x7f7fffff) ||
(w >= 0x80800000 && w <= 0xff7fffff))
return FP_NORMAL;
else if ((w >= 0x00000001 && w <= 0x007fffff) ||
(w >= 0x80000001 && w <= 0x807fffff))
return FP_SUBNORMAL;
else if (w == 0x7f800000 || w == 0xff800000)
return FP_INFINITE;
else
return FP_NAN;
}
 
/programs/develop/libraries/newlib/math/sf_frexp.c
0,0 → 1,61
/* sf_frexp.c -- float version of s_frexp.c.
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
*/
 
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#include "fdlibm.h"
 
#ifdef __STDC__
static const float
#else
static float
#endif
two25 = 3.3554432000e+07; /* 0x4c000000 */
 
#ifdef __STDC__
float frexpf(float x, int *eptr)
#else
float frexpf(x, eptr)
float x; int *eptr;
#endif
{
__int32_t hx, ix;
GET_FLOAT_WORD(hx,x);
ix = 0x7fffffff&hx;
*eptr = 0;
if(!FLT_UWORD_IS_FINITE(ix)||FLT_UWORD_IS_ZERO(ix)) return x; /* 0,inf,nan */
if (FLT_UWORD_IS_SUBNORMAL(ix)) { /* subnormal */
x *= two25;
GET_FLOAT_WORD(hx,x);
ix = hx&0x7fffffff;
*eptr = -25;
}
*eptr += (ix>>23)-126;
hx = (hx&0x807fffff)|0x3f000000;
SET_FLOAT_WORD(x,hx);
return x;
}
 
#ifdef _DOUBLE_IS_32BITS
 
#ifdef __STDC__
double frexp(double x, int *eptr)
#else
double frexp(x, eptr)
double x; int *eptr;
#endif
{
return (double) frexpf((float) x, eptr);
}
 
#endif /* defined(_DOUBLE_IS_32BITS) */
/programs/develop/libraries/newlib/math/sf_ilogb.c
0,0 → 1,55
/* sf_ilogb.c -- float version of s_ilogb.c.
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
*/
 
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#include <limits.h>
#include "fdlibm.h"
 
#ifdef __STDC__
int ilogbf(float x)
#else
int ilogbf(x)
float x;
#endif
{
__int32_t hx,ix;
 
GET_FLOAT_WORD(hx,x);
hx &= 0x7fffffff;
if(FLT_UWORD_IS_ZERO(hx))
return FP_ILOGB0; /* ilogb(0) = special case error */
if(FLT_UWORD_IS_SUBNORMAL(hx)) {
for (ix = -126,hx<<=8; hx>0; hx<<=1) ix -=1;
return ix;
}
#if FP_ILOGBNAN != INT_MAX
else if (FLT_UWORD_IS_NAN(hx)) return FP_ILOGBNAN; /* NAN */
#endif
else if (!FLT_UWORD_IS_FINITE(hx)) return INT_MAX;
else return (hx>>23)-127;
}
 
#ifdef _DOUBLE_IS_32BITS
 
#ifdef __STDC__
int ilogb(double x)
#else
int ilogb(x)
double x;
#endif
{
return ilogbf((float) x);
}
 
#endif /* defined(_DOUBLE_IS_32BITS) */
/programs/develop/libraries/newlib/math/sf_infinity.c
0,0 → 1,23
/*
* infinityf () returns the representation of infinity.
* Added by Cygnus Support.
*/
 
#include "fdlibm.h"
 
float infinityf()
{
float x;
 
SET_FLOAT_WORD(x,0x7f800000);
return x;
}
 
#ifdef _DOUBLE_IS_32BITS
 
double infinity()
{
return (double) infinityf();
}
 
#endif /* defined(_DOUBLE_IS_32BITS) */
/programs/develop/libraries/newlib/math/sf_isinf.c
0,0 → 1,37
/*
* isinff(x) returns 1 if x is +-infinity, else 0;
*
* isinf is a <math.h> macro in the C99 standard. It was previously
* implemented as isinf and isinff functions by newlib and are still declared
* as such in <ieeefp.h>. Newlib supplies it here as a function if the user
* chooses to use <ieeefp.h> or needs to link older code compiled with the
* previous <math.h> declaration.
*/
 
#include "fdlibm.h"
#include <ieeefp.h>
 
#undef isinff
 
int
_DEFUN (isinff, (x),
float x)
{
__int32_t ix;
GET_FLOAT_WORD(ix,x);
ix &= 0x7fffffff;
return FLT_UWORD_IS_INFINITE(ix);
}
 
#ifdef _DOUBLE_IS_32BITS
 
#undef isinf
 
int
_DEFUN (isinf, (x),
double x)
{
return isinff((float) x);
}
 
#endif /* defined(_DOUBLE_IS_32BITS) */
/programs/develop/libraries/newlib/math/sf_isinff.c
0,0 → 1,27
/*
* __isinff(x) returns 1 if x is +-infinity, else 0;
* Added by Cygnus Support.
*/
 
#include "fdlibm.h"
 
int
_DEFUN (__isinff, (x),
float x)
{
__int32_t ix;
GET_FLOAT_WORD(ix,x);
ix &= 0x7fffffff;
return FLT_UWORD_IS_INFINITE(ix);
}
 
#ifdef _DOUBLE_IS_32BITS
 
int
_DEFUN (__isinfd, (x),
double x)
{
return __isinff((float) x);
}
 
#endif /* defined(_DOUBLE_IS_32BITS) */
/programs/develop/libraries/newlib/math/sf_isnan.c
0,0 → 1,47
/* sf_c_isnan.c -- float version of s_c_isnan.c.
*/
 
/*
* ====================================================
* 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.
* ====================================================
*/
 
/*
* isnanf(x) returns 1 is x is nan, else 0;
*
* isnanf is an extension declared in <ieeefp.h>.
*/
 
#include "fdlibm.h"
#include <ieeefp.h>
#undef isnanf
 
int
_DEFUN (isnanf, (x),
float x)
{
__int32_t ix;
GET_FLOAT_WORD(ix,x);
ix &= 0x7fffffff;
return FLT_UWORD_IS_NAN(ix);
}
 
#ifdef _DOUBLE_IS_32BITS
 
#undef isnan
 
int
_DEFUN (isnan, (x),
double x)
{
return isnanf((float) x);
}
 
#endif /* defined(_DOUBLE_IS_32BITS) */
/programs/develop/libraries/newlib/math/sf_isnanf.c
0,0 → 1,37
/*
* ====================================================
* 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.
* ====================================================
*/
 
/*
* __isnanf(x) returns 1 is x is nan, else 0;
*/
 
#include "fdlibm.h"
 
int
_DEFUN (__isnanf, (x),
float x)
{
__int32_t ix;
GET_FLOAT_WORD(ix,x);
ix &= 0x7fffffff;
return FLT_UWORD_IS_NAN(ix);
}
 
#ifdef _DOUBLE_IS_32BITS
 
int
_DEFUN (__isnand, (x),
double x)
{
return __isnanf((float) x);
}
 
#endif /* defined(_DOUBLE_IS_32BITS) */
/programs/develop/libraries/newlib/math/sf_ldexp.c
0,0 → 1,44
/* sf_ldexp.c -- float version of s_ldexp.c.
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
*/
 
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#include "fdlibm.h"
#include <errno.h>
 
#ifdef __STDC__
float ldexpf(float value, int exp)
#else
float ldexpf(value, exp)
float value; int exp;
#endif
{
if(!finitef(value)||value==(float)0.0) return value;
value = scalbnf(value,exp);
if(!finitef(value)||value==(float)0.0) errno = ERANGE;
return value;
}
 
#ifdef _DOUBLE_IS_32BITS
 
#ifdef __STDC__
double ldexp(double value, int exp)
#else
double ldexp(value, exp)
double value; int exp;
#endif
{
return (double) ldexpf((float) value, exp);
}
 
#endif /* defined(_DOUBLE_IS_32BITS) */
/programs/develop/libraries/newlib/math/sf_llrint.c
0,0 → 1,101
/* lrintf adapted to be llrintf for Newlib, 2009 by Craig Howland. */
/* @(#)sf_lrint.c 5.1 93/09/24 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
/*
* llrintf(x)
* Return x rounded to integral value according to the prevailing
* rounding mode.
* Method:
* Using floating addition.
* Exception:
* Inexact flag raised if x not equal to llrintf(x).
*/
 
#include "fdlibm.h"
 
#ifdef __STDC__
static const float
#else
static float
#endif
/* Adding a float, x, to 2^23 will cause the result to be rounded based on
the fractional part of x, according to the implementation's current rounding
mode. 2^23 is the smallest float that can be represented using all 23 significant
digits. */
TWO23[2]={
8.3886080000e+06, /* 0x4b000000 */
-8.3886080000e+06, /* 0xcb000000 */
};
 
#ifdef __STDC__
long long int llrintf(float x)
#else
long long int llrintf(x)
float x;
#endif
{
__int32_t j0,sx;
__uint32_t i0;
float t;
volatile float w;
long long int result;
 
GET_FLOAT_WORD(i0,x);
 
/* Extract sign bit. */
sx = (i0 >> 31);
 
/* Extract exponent field. */
j0 = ((i0 & 0x7f800000) >> 23) - 127;
if (j0 < (int)(sizeof (long long int) * 8) - 1)
{
if (j0 < -1)
return 0;
else if (j0 >= 23)
result = (long long int) ((i0 & 0x7fffff) | 0x800000) << (j0 - 23);
else
{
w = TWO23[sx] + x;
t = w - TWO23[sx];
GET_FLOAT_WORD (i0, t);
/* Detect the all-zeros representation of plus and
minus zero, which fails the calculation below. */
if ((i0 & ~((__uint32_t)1 << 31)) == 0)
return 0;
j0 = ((i0 >> 23) & 0xff) - 0x7f;
i0 &= 0x7fffff;
i0 |= 0x800000;
result = i0 >> (23 - j0);
}
}
else
{
return (long long int) x;
}
return sx ? -result : result;
}
 
#ifdef _DOUBLE_IS_32BITS
 
#ifdef __STDC__
long long int llrint(double x)
#else
long long int llrint(x)
double x;
#endif
{
return llrintf((float) x);
}
 
#endif /* defined(_DOUBLE_IS_32BITS) */
/programs/develop/libraries/newlib/math/sf_llround.c
0,0 → 1,55
/* lroundf adapted to be llroundf for Newlib, 2009 by Craig Howland. */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#include "fdlibm.h"
 
long long int
llroundf(float x)
{
__int32_t exponent_less_127;
__uint32_t w;
long long int result;
__int32_t sign;
 
GET_FLOAT_WORD (w, x);
exponent_less_127 = ((w & 0x7f800000) >> 23) - 127;
sign = (w & 0x80000000) != 0 ? -1 : 1;
w &= 0x7fffff;
w |= 0x800000;
 
if (exponent_less_127 < (int)((8 * sizeof (long long int)) - 1))
{
if (exponent_less_127 < 0)
return exponent_less_127 < -1 ? 0 : sign;
else if (exponent_less_127 >= 23)
result = (long long int) w << (exponent_less_127 - 23);
else
{
w += 0x400000 >> exponent_less_127;
result = w >> (23 - exponent_less_127);
}
}
else
return (long long int) x;
 
return sign * result;
}
 
#ifdef _DOUBLE_IS_32BITS
 
long long int
llround(double x)
{
return llroundf((float) x);
}
 
#endif /* defined(_DOUBLE_IS_32BITS) */
/programs/develop/libraries/newlib/math/sf_log1p.c
0,0 → 1,121
/* sf_log1p.c -- float version of s_log1p.c.
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
*/
 
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#include "fdlibm.h"
 
#ifdef __STDC__
static const float
#else
static float
#endif
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 */
 
#ifdef __STDC__
static const float zero = 0.0;
#else
static float zero = 0.0;
#endif
 
#ifdef __STDC__
float log1pf(float x)
#else
float log1pf(x)
float x;
#endif
{
float hfsq,f,c,s,z,R,u;
__int32_t k,hx,hu,ax;
 
GET_FLOAT_WORD(hx,x);
ax = hx&0x7fffffff;
 
k = 1;
if (!FLT_UWORD_IS_FINITE(hx)) return x+x;
if (hx < 0x3ed413d7) { /* x < 0.41422 */
if(ax>=0x3f800000) { /* x <= -1.0 */
if(x==(float)-1.0) return -two25/zero; /* log1p(-1)=+inf */
else return (x-x)/(x-x); /* log1p(x<-1)=NaN */
}
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<=((__int32_t)0xbe95f61f)) {
k=0;f=x;hu=1;} /* -0.2929<x<0.41422 */
}
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);
}
 
#ifdef _DOUBLE_IS_32BITS
 
#ifdef __STDC__
double log1p(double x)
#else
double log1p(x)
double x;
#endif
{
return (double) log1pf((float) x);
}
 
#endif /* defined(_DOUBLE_IS_32BITS) */
/programs/develop/libraries/newlib/math/sf_log2.c
0,0 → 1,48
/* sf_log2.c -- float version of s_log2.c.
* Modification of sf_exp10.c by Yaakov Selkowitz 2009.
*/
 
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
/*
* wrapper log2f(x)
*/
 
#include "fdlibm.h"
#include <errno.h>
#include <math.h>
#undef log2
#undef log2f
 
#ifdef __STDC__
float log2f(float x) /* wrapper log2f */
#else
float log2f(x) /* wrapper log2f */
float x;
#endif
{
return (logf(x) / (float_t) M_LN2);
}
 
#ifdef _DOUBLE_IS_32BITS
 
#ifdef __STDC__
double log2(double x)
#else
double log2(x)
double x;
#endif
{
return (double) log2f((float) x);
}
 
#endif /* defined(_DOUBLE_IS_32BITS) */
/programs/develop/libraries/newlib/math/sf_logb.c
0,0 → 1,62
/* 2009 for Newlib: Sun's sf_ilogb.c converted to be sf_logb.c. */
/*
* ====================================================
* 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.
* ====================================================
*/
 
/* float logb(float x)
* return the binary exponent of non-zero x
* logbf(0) = -inf, raise divide-by-zero floating point exception
* logbf(+inf|-inf) = +inf (no signal is raised)
* logbf(NaN) = NaN (no signal is raised)
* Per C99 recommendation, a NaN argument is returned unchanged.
*/
 
#include "fdlibm.h"
 
float
#ifdef __STDC__
logbf(float x)
#else
logbf(x)
float x;
#endif
{
__int32_t hx,ix;
 
GET_FLOAT_WORD(hx,x);
hx &= 0x7fffffff;
if(FLT_UWORD_IS_ZERO(hx)) {
float xx;
/* arg==0: return -inf and raise divide-by-zero exception */
SET_FLOAT_WORD(xx,hx); /* +0.0 */
return -1./xx; /* logbf(0) = -inf */
}
if(FLT_UWORD_IS_SUBNORMAL(hx)) {
for (ix = -126,hx<<=8; hx>0; hx<<=1) ix -=1;
return (float) ix;
}
else if (FLT_UWORD_IS_INFINITE(hx)) return HUGE_VALF; /* x==+|-inf */
else if (FLT_UWORD_IS_NAN(hx)) return x;
else return (float) ((hx>>23)-127);
}
 
#ifdef _DOUBLE_IS_32BITS
 
#ifdef __STDC__
double logb(double x)
#else
double logb(x)
double x;
#endif
{
return (double) logbf((float) x);
}
 
#endif /* defined(_DOUBLE_IS_32BITS) */
/programs/develop/libraries/newlib/math/sf_lrint.c
0,0 → 1,101
 
/* @(#)sf_lrint.c 5.1 93/09/24 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
/*
* lrintf(x)
* Return x rounded to integral value according to the prevailing
* rounding mode.
* Method:
* Using floating addition.
* Exception:
* Inexact flag raised if x not equal to lrintf(x).
*/
 
#include "fdlibm.h"
 
#ifdef __STDC__
static const float
#else
static float
#endif
/* Adding a float, x, to 2^23 will cause the result to be rounded based on
the fractional part of x, according to the implementation's current rounding
mode. 2^23 is the smallest float that can be represented using all 23 significant
digits. */
TWO23[2]={
8.3886080000e+06, /* 0x4b000000 */
-8.3886080000e+06, /* 0xcb000000 */
};
 
#ifdef __STDC__
long int lrintf(float x)
#else
long int lrintf(x)
float x;
#endif
{
__int32_t j0,sx;
__uint32_t i0;
float t;
volatile float w;
long int result;
 
GET_FLOAT_WORD(i0,x);
 
/* Extract sign bit. */
sx = (i0 >> 31);
 
/* Extract exponent field. */
j0 = ((i0 & 0x7f800000) >> 23) - 127;
if (j0 < (int)(sizeof (long int) * 8) - 1)
{
if (j0 < -1)
return 0;
else if (j0 >= 23)
result = (long int) ((i0 & 0x7fffff) | 0x800000) << (j0 - 23);
else
{
w = TWO23[sx] + x;
t = w - TWO23[sx];
GET_FLOAT_WORD (i0, t);
/* Detect the all-zeros representation of plus and
minus zero, which fails the calculation below. */
if ((i0 & ~(1L << 31)) == 0)
return 0;
j0 = ((i0 >> 23) & 0xff) - 0x7f;
i0 &= 0x7fffff;
i0 |= 0x800000;
result = i0 >> (23 - j0);
}
}
else
{
return (long int) x;
}
return sx ? -result : result;
}
 
#ifdef _DOUBLE_IS_32BITS
 
#ifdef __STDC__
long int lrint(double x)
#else
long int lrint(x)
double x;
#endif
{
return lrintf((float) x);
}
 
#endif /* defined(_DOUBLE_IS_32BITS) */
/programs/develop/libraries/newlib/math/sf_lround.c
0,0 → 1,62
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#include "fdlibm.h"
 
#ifdef __STDC__
long int lroundf(float x)
#else
long int lroundf(x)
float x;
#endif
{
__int32_t exponent_less_127;
__uint32_t w;
long int result;
__int32_t sign;
 
GET_FLOAT_WORD (w, x);
exponent_less_127 = ((w & 0x7f800000) >> 23) - 127;
sign = (w & 0x80000000) != 0 ? -1 : 1;
w &= 0x7fffff;
w |= 0x800000;
 
if (exponent_less_127 < (int)((8 * sizeof (long int)) - 1))
{
if (exponent_less_127 < 0)
return exponent_less_127 < -1 ? 0 : sign;
else if (exponent_less_127 >= 23)
result = (long int) w << (exponent_less_127 - 23);
else
{
w += 0x400000 >> exponent_less_127;
result = w >> (23 - exponent_less_127);
}
}
else
return (long int) x;
 
return sign * result;
}
 
#ifdef _DOUBLE_IS_32BITS
 
#ifdef __STDC__
long int lround(double x)
#else
long int lround(x)
double x;
#endif
{
return lroundf((float) x);
}
 
#endif /* defined(_DOUBLE_IS_32BITS) */
/programs/develop/libraries/newlib/math/sf_modf.c
0,0 → 1,73
/* sf_modf.c -- float version of s_modf.c.
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
*/
 
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#include "fdlibm.h"
 
#ifdef __STDC__
static const float one = 1.0;
#else
static float one = 1.0;
#endif
 
#ifdef __STDC__
float modff(float x, float *iptr)
#else
float modff(x, iptr)
float x,*iptr;
#endif
{
__int32_t i0,j0;
__uint32_t i;
GET_FLOAT_WORD(i0,x);
j0 = ((i0>>23)&0xff)-0x7f; /* exponent of x */
if(j0<23) { /* integer part in x */
if(j0<0) { /* |x|<1 */
SET_FLOAT_WORD(*iptr,i0&0x80000000); /* *iptr = +-0 */
return x;
} else {
i = (0x007fffff)>>j0;
if((i0&i)==0) { /* x is integral */
__uint32_t ix;
*iptr = x;
GET_FLOAT_WORD(ix,x);
SET_FLOAT_WORD(x,ix&0x80000000); /* return +-0 */
return x;
} else {
SET_FLOAT_WORD(*iptr,i0&(~i));
return x - *iptr;
}
}
} else { /* no fraction part */
__uint32_t ix;
*iptr = x*one;
GET_FLOAT_WORD(ix,x);
SET_FLOAT_WORD(x,ix&0x80000000); /* return +-0 */
return x;
}
}
 
#ifdef _DOUBLE_IS_32BITS
 
#ifdef __STDC__
double modf(double x, double *iptr)
#else
double modf(x, iptr)
double x,*iptr;
#endif
{
return (double) modff((float) x, (float *) iptr);
}
 
#endif /* defined(_DOUBLE_IS_32BITS) */
/programs/develop/libraries/newlib/math/sf_nan.c
0,0 → 1,24
/*
* nanf () returns a nan.
* Added by Cygnus Support.
*/
 
#include "fdlibm.h"
 
float nanf(const char *unused)
{
float x;
 
SET_FLOAT_WORD(x,0x7fc00000);
return x;
}
 
#ifdef _DOUBLE_IS_32BITS
 
double nan(const char *arg)
{
return (double) nanf(arg);
}
 
#endif /* defined(_DOUBLE_IS_32BITS) */
 
/programs/develop/libraries/newlib/math/sf_nearbyint.c
0,0 → 1,38
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
 
#include <math.h>
#include "fdlibm.h"
 
#ifdef __STDC__
float nearbyintf(float x)
#else
float nearbyintf(x)
float x;
#endif
{
return rintf(x);
}
 
#ifdef _DOUBLE_IS_32BITS
 
#ifdef __STDC__
double nearbyint(double x)
#else
double nearbyint(x)
double x;
#endif
{
return (double) nearbyintf((float) x);
}
 
#endif /* defined(_DOUBLE_IS_32BITS) */
/programs/develop/libraries/newlib/math/sf_nextafter.c
0,0 → 1,79
/* sf_nextafter.c -- float version of s_nextafter.c.
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
*/
 
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#include "fdlibm.h"
 
#ifdef __STDC__
float nextafterf(float x, float y)
#else
float nextafterf(x,y)
float x,y;
#endif
{
__int32_t hx,hy,ix,iy;
 
GET_FLOAT_WORD(hx,x);
GET_FLOAT_WORD(hy,y);
ix = hx&0x7fffffff; /* |x| */
iy = hy&0x7fffffff; /* |y| */
 
if(FLT_UWORD_IS_NAN(ix) ||
FLT_UWORD_IS_NAN(iy))
return x+y;
if(x==y) return x; /* x=y, return x */
if(FLT_UWORD_IS_ZERO(ix)) { /* x == 0 */
SET_FLOAT_WORD(x,(hy&0x80000000)|FLT_UWORD_MIN);
y = x*x;
if(y==x) return y; else return x; /* raise underflow flag */
}
if(hx>=0) { /* x > 0 */
if(hx>hy) { /* x > y, x -= ulp */
hx -= 1;
} else { /* x < y, x += ulp */
hx += 1;
}
} else { /* x < 0 */
if(hy>=0||hx>hy){ /* x < y, x -= ulp */
hx -= 1;
} else { /* x > y, x += ulp */
hx += 1;
}
}
hy = hx&0x7f800000;
if(hy>FLT_UWORD_MAX) return x+x; /* overflow */
if(hy<0x00800000) { /* underflow */
y = x*x;
if(y!=x) { /* raise underflow flag */
SET_FLOAT_WORD(y,hx);
return y;
}
}
SET_FLOAT_WORD(x,hx);
return x;
}
 
#ifdef _DOUBLE_IS_32BITS
 
#ifdef __STDC__
double nextafter(double x, double y)
#else
double nextafter(x,y)
double x,y;
#endif
{
return (double) nextafterf((float) x, (float) x);
}
 
#endif /* defined(_DOUBLE_IS_32BITS) */
/programs/develop/libraries/newlib/math/sf_pow10.c
0,0 → 1,47
/* sf_pow10.c -- float version of s_pow10.c.
* Modification of sf_pow10.c by Yaakov Selkowitz 2007.
*/
 
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
/*
* wrapper pow10f(x)
*/
 
#undef pow10f
#include "fdlibm.h"
#include <errno.h>
#include <math.h>
 
#ifdef __STDC__
float pow10f(float x) /* wrapper pow10f */
#else
float pow10f(x) /* wrapper pow10f */
float x;
#endif
{
return powf(10.0, x);
}
 
#ifdef _DOUBLE_IS_32BITS
 
#ifdef __STDC__
double pow10(double x)
#else
double pow10(x)
double x;
#endif
{
return (double) pow10f((float) x);
}
 
#endif /* defined(_DOUBLE_IS_32BITS) */
/programs/develop/libraries/newlib/math/sf_remquo.c
0,0 → 1,130
/* Adapted for Newlib, 2009. (Allow for int < 32 bits; return *quo=0 during
* errors to make test scripts easier.) */
/* @(#)e_fmod.c 1.3 95/01/18 */
/*-
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunSoft, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#include <math.h>
#include "fdlibm.h"
 
/* For quotient, return either all 31 bits that can from calculation (using
* int32_t), or as many as can fit into an int that is smaller than 32 bits. */
#if INT_MAX > 0x7FFFFFFFL
#define QUO_MASK 0x7FFFFFFF
# else
#define QUO_MASK INT_MAX
#endif
 
static const float Zero[] = {0.0, -0.0,};
 
/*
* Return the IEEE remainder and set *quo to the last n bits of the
* quotient, rounded to the nearest integer. We choose n=31--if that many fit--
* we wind up computing all the integer bits of the quotient anyway as
* a side-effect of computing the remainder by the shift and subtract
* method. In practice, this is far more bits than are needed to use
* remquo in reduction algorithms.
*/
float
remquof(float x, float y, int *quo)
{
__int32_t n,hx,hy,hz,ix,iy,sx,i;
__uint32_t q,sxy;
 
GET_FLOAT_WORD(hx,x);
GET_FLOAT_WORD(hy,y);
sxy = (hx ^ hy) & 0x80000000;
sx = hx&0x80000000; /* sign of x */
hx ^=sx; /* |x| */
hy &= 0x7fffffff; /* |y| */
 
/* purge off exception values */
if(hy==0||hx>=0x7f800000||hy>0x7f800000) { /* y=0,NaN;or x not finite */
*quo = 0; /* Not necessary, but return consistent value */
return (x*y)/(x*y);
}
if(hx<hy) {
q = 0;
goto fixup; /* |x|<|y| return x or x-y */
} else if(hx==hy) {
*quo = 1;
return Zero[(__uint32_t)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 <<= n;
}
if(iy >= -126)
hy = 0x00800000|(0x007fffff&hy);
else { /* subnormal y, shift y to normal */
n = -126-iy;
hy <<= n;
}
 
/* fix point fmod */
n = ix - iy;
q = 0;
while(n--) {
hz=hx-hy;
if(hz<0) hx = hx << 1;
else {hx = hz << 1; q++;}
q <<= 1;
}
hz=hx-hy;
if(hz>=0) {hx=hz;q++;}
 
/* convert back to floating value and restore the sign */
if(hx==0) { /* return sign(x)*0 */
*quo = (sxy ? -q : q);
return Zero[(__uint32_t)sx>>31];
}
while(hx<0x00800000) { /* normalize x */
hx <<= 1;
iy -= 1;
}
if(iy>= -126) { /* normalize output */
hx = ((hx-0x00800000)|((iy+127)<<23));
} else { /* subnormal output */
n = -126 - iy;
hx >>= n;
}
fixup:
SET_FLOAT_WORD(x,hx);
y = fabsf(y);
if (y < 0x1p-125f) {
if (x+x>y || (x+x==y && (q & 1))) {
q++;
x-=y;
}
} else if (x>0.5f*y || (x==0.5f*y && (q & 1))) {
q++;
x-=y;
}
GET_FLOAT_WORD(hx,x);
SET_FLOAT_WORD(x,hx^sx);
q &= 0x7fffffff;
*quo = (sxy ? -q : q);
return x;
}
/programs/develop/libraries/newlib/math/sf_rint.c
0,0 → 1,84
/* sf_rint.c -- float version of s_rint.c.
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
*/
 
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#include "fdlibm.h"
 
#ifdef __STDC__
static const float
#else
static float
#endif
TWO23[2]={
8.3886080000e+06, /* 0x4b000000 */
-8.3886080000e+06, /* 0xcb000000 */
};
 
#ifdef __STDC__
float rintf(float x)
#else
float rintf(x)
float x;
#endif
{
__int32_t i0,j0,sx;
__uint32_t i,i1,ix;
float t;
volatile float w;
GET_FLOAT_WORD(i0,x);
sx = (i0>>31)&1;
ix = (i0&0x7fffffff);
j0 = (ix>>23)-0x7f;
if(j0<23) {
if(FLT_UWORD_IS_ZERO(ix))
return x;
if(j0<0) {
i1 = (i0&0x07fffff);
i0 &= 0xfff00000;
i0 |= ((i1|-i1)>>9)&0x400000;
SET_FLOAT_WORD(x,i0);
w = TWO23[sx]+x;
t = w-TWO23[sx];
GET_FLOAT_WORD(i0,t);
SET_FLOAT_WORD(t,(i0&0x7fffffff)|(sx<<31));
return t;
} else {
i = (0x007fffff)>>j0;
if((i0&i)==0) return x; /* x is integral */
i>>=1;
if((i0&i)!=0) i0 = (i0&(~i))|((0x200000)>>j0);
}
} else {
if(!FLT_UWORD_IS_FINITE(ix)) return x+x; /* inf or NaN */
else
return x; /* x is integral */
}
SET_FLOAT_WORD(x,i0);
w = TWO23[sx]+x;
return w-TWO23[sx];
}
 
#ifdef _DOUBLE_IS_32BITS
 
#ifdef __STDC__
double rint(double x)
#else
double rint(x)
double x;
#endif
{
return (double) rintf((float) x);
}
 
#endif /* defined(_DOUBLE_IS_32BITS) */
/programs/develop/libraries/newlib/math/sf_round.c
0,0 → 1,74
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#include "fdlibm.h"
 
#ifdef __STDC__
float roundf(float x)
#else
float roundf(x)
float x;
#endif
{
__uint32_t w;
/* Most significant word, least significant word. */
int exponent_less_127;
 
GET_FLOAT_WORD(w, x);
 
/* Extract exponent field. */
exponent_less_127 = (int)((w & 0x7f800000) >> 23) - 127;
 
if (exponent_less_127 < 23)
{
if (exponent_less_127 < 0)
{
w &= 0x80000000;
if (exponent_less_127 == -1)
/* Result is +1.0 or -1.0. */
w |= ((__uint32_t)127 << 23);
}
else
{
unsigned int exponent_mask = 0x007fffff >> exponent_less_127;
if ((w & exponent_mask) == 0)
/* x has an integral value. */
return x;
 
w += 0x00400000 >> exponent_less_127;
w &= ~exponent_mask;
}
}
else
{
if (exponent_less_127 == 128)
/* x is NaN or infinite. */
return x + x;
else
return x;
}
SET_FLOAT_WORD(x, w);
return x;
}
 
#ifdef _DOUBLE_IS_32BITS
 
#ifdef __STDC__
double round(double x)
#else
double round(x)
double x;
#endif
{
return (double) roundf((float) x);
}
 
#endif /* defined(_DOUBLE_IS_32BITS) */
/programs/develop/libraries/newlib/math/sf_scalbln.c
0,0 → 1,71
/* s_scalbnf.c -- float version of s_scalbn.c.
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
*/
 
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#include "fdlibm.h"
 
#ifdef __STDC__
static const float
#else
static float
#endif
two25 = 3.355443200e+07, /* 0x4c000000 */
twom25 = 2.9802322388e-08, /* 0x33000000 */
huge = 1.0e+30,
tiny = 1.0e-30;
 
#ifdef __STDC__
float scalblnf (float x, long int n)
#else
float scalblnf (x,n)
float x; long int n;
#endif
{
__int32_t 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 (k==0xff) return x+x; /* NaN or Inf */
k = k+n;
if (n> 50000 || k > 0xfe)
return huge*copysignf(huge,x); /* overflow */
if (n< -50000)
return tiny*copysignf(tiny,x); /*underflow*/
if (k > 0) /* normal result */
{SET_FLOAT_WORD(x,(ix&0x807fffff)|(k<<23)); return x;}
if (k <= -25)
return tiny*copysignf(tiny,x); /*underflow*/
k += 25; /* subnormal result */
SET_FLOAT_WORD(x,(ix&0x807fffff)|(k<<23));
return x*twom25;
}
 
#ifdef _DOUBLE_IS_32BITS
 
#ifdef __STDC__
double scalbln (double x, long int n)
#else
double scalbln (x,n)
double x; long int n;
#endif
{
return (double) scalblnf((float) x, n);
}
 
#endif /* defined(_DOUBLE_IS_32BITS) */
/programs/develop/libraries/newlib/math/sf_scalbn.c
0,0 → 1,86
/* sf_scalbn.c -- float version of s_scalbn.c.
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
*/
 
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#include "fdlibm.h"
#include <limits.h>
#include <float.h>
 
#if INT_MAX > 50000
#define OVERFLOW_INT 50000
#else
#define OVERFLOW_INT 30000
#endif
 
#ifdef __STDC__
static const float
#else
static float
#endif
two25 = 3.355443200e+07, /* 0x4c000000 */
twom25 = 2.9802322388e-08, /* 0x33000000 */
huge = 1.0e+30,
tiny = 1.0e-30;
 
#ifdef __STDC__
float scalbnf (float x, int n)
#else
float scalbnf (x,n)
float x; int n;
#endif
{
__int32_t k,ix;
__uint32_t hx;
 
GET_FLOAT_WORD(ix,x);
hx = ix&0x7fffffff;
k = hx>>23; /* extract exponent */
if (FLT_UWORD_IS_ZERO(hx))
return x;
if (!FLT_UWORD_IS_FINITE(hx))
return x+x; /* NaN or Inf */
if (FLT_UWORD_IS_SUBNORMAL(hx)) {
x *= two25;
GET_FLOAT_WORD(ix,x);
k = ((ix&0x7f800000)>>23) - 25;
if (n< -50000) return tiny*x; /*underflow*/
}
k = k+n;
if (k > FLT_LARGEST_EXP) return huge*copysignf(huge,x); /* overflow */
if (k > 0) /* normal result */
{SET_FLOAT_WORD(x,(ix&0x807fffff)|(k<<23)); return x;}
if (k < FLT_SMALLEST_EXP) {
if (n > OVERFLOW_INT) /* in case integer overflow in n+k */
return huge*copysignf(huge,x); /*overflow*/
else return tiny*copysignf(tiny,x); /*underflow*/
}
k += 25; /* subnormal result */
SET_FLOAT_WORD(x,(ix&0x807fffff)|(k<<23));
return x*twom25;
}
 
#ifdef _DOUBLE_IS_32BITS
 
#ifdef __STDC__
double scalbn(double x, int n)
#else
double scalbn(x,n)
double x;
int n;
#endif
{
return (double) scalbnf((float) x, n);
}
 
#endif /* defined(_DOUBLE_IS_32BITS) */
/programs/develop/libraries/newlib/math/sf_signif.c
0,0 → 1,40
/* sf_signif.c -- float version of s_signif.c.
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
*/
 
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#include "fdlibm.h"
 
#ifdef __STDC__
float significandf(float x)
#else
float significandf(x)
float x;
#endif
{
return __ieee754_scalbf(x,(float) -ilogbf(x));
}
 
#ifdef _DOUBLE_IS_32BITS
 
#ifdef __STDC__
double significand(double x)
#else
double significand(x)
double x;
#endif
{
return (double) significandf((float) x);
}
 
#endif /* defined(_DOUBLE_IS_32BITS) */
/programs/develop/libraries/newlib/math/sf_sin.c
0,0 → 1,62
/* sf_sin.c -- float version of s_sin.c.
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
*/
 
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#include "fdlibm.h"
 
#ifdef __STDC__
float sinf(float x)
#else
float sinf(x)
float x;
#endif
{
float y[2],z=0.0;
__int32_t n,ix;
 
GET_FLOAT_WORD(ix,x);
 
/* |x| ~< pi/4 */
ix &= 0x7fffffff;
if(ix <= 0x3f490fd8) return __kernel_sinf(x,z,0);
 
/* sin(Inf or NaN) is NaN */
else if (!FLT_UWORD_IS_FINITE(ix)) return x-x;
 
/* argument reduction needed */
else {
n = __ieee754_rem_pio2f(x,y);
switch(n&3) {
case 0: return __kernel_sinf(y[0],y[1],1);
case 1: return __kernel_cosf(y[0],y[1]);
case 2: return -__kernel_sinf(y[0],y[1],1);
default:
return -__kernel_cosf(y[0],y[1]);
}
}
}
 
#ifdef _DOUBLE_IS_32BITS
 
#ifdef __STDC__
double sin(double x)
#else
double sin(x)
double x;
#endif
{
return (double) sinf((float) x);
}
 
#endif /* defined(_DOUBLE_IS_32BITS) */
/programs/develop/libraries/newlib/math/sf_tan.c
0,0 → 1,57
/* sf_tan.c -- float version of s_tan.c.
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
*/
 
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#include "fdlibm.h"
 
#ifdef __STDC__
float tanf(float x)
#else
float tanf(x)
float x;
#endif
{
float y[2],z=0.0;
__int32_t n,ix;
 
GET_FLOAT_WORD(ix,x);
 
/* |x| ~< pi/4 */
ix &= 0x7fffffff;
if(ix <= 0x3f490fda) return __kernel_tanf(x,z,1);
 
/* tan(Inf or NaN) is NaN */
else if (!FLT_UWORD_IS_FINITE(ix)) return x-x; /* NaN */
 
/* argument reduction needed */
else {
n = __ieee754_rem_pio2f(x,y);
return __kernel_tanf(y[0],y[1],1-((n&1)<<1)); /* 1 -- n even
-1 -- n odd */
}
}
 
#ifdef _DOUBLE_IS_32BITS
 
#ifdef __STDC__
double tan(double x)
#else
double tan(x)
double x;
#endif
{
return (double) tanf((float) x);
}
 
#endif /* defined(_DOUBLE_IS_32BITS) */
/programs/develop/libraries/newlib/math/sf_tanh.c
0,0 → 1,73
/* sf_tanh.c -- float version of s_tanh.c.
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
*/
 
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#include "fdlibm.h"
 
#ifdef __STDC__
static const float one=1.0, two=2.0, tiny = 1.0e-30;
#else
static float one=1.0, two=2.0, tiny = 1.0e-30;
#endif
 
#ifdef __STDC__
float tanhf(float x)
#else
float tanhf(x)
float x;
#endif
{
float t,z;
__int32_t jx,ix;
 
GET_FLOAT_WORD(jx,x);
ix = jx&0x7fffffff;
 
/* x is INF or NaN */
if(!FLT_UWORD_IS_FINITE(ix)) {
if (jx>=0) return one/x+one; /* tanh(+-inf)=+-1 */
else return one/x-one; /* tanh(NaN) = NaN */
}
 
/* |x| < 22 */
if (ix < 0x41b00000) { /* |x|<22 */
if (ix<0x24000000) /* |x|<2**-55 */
return x*(one+x); /* tanh(small) = small */
if (ix>=0x3f800000) { /* |x|>=1 */
t = expm1f(two*fabsf(x));
z = one - two/(t+two);
} else {
t = expm1f(-two*fabsf(x));
z= -t/(t+two);
}
/* |x| > 22, return +-1 */
} else {
z = one - tiny; /* raised inexact flag */
}
return (jx>=0)? z: -z;
}
 
#ifdef _DOUBLE_IS_32BITS
 
#ifdef __STDC__
double tanh(double x)
#else
double tanh(x)
double x;
#endif
{
return (double) tanhf((float) x);
}
 
#endif /* defined(_DOUBLE_IS_32BITS) */
/programs/develop/libraries/newlib/math/sf_trunc.c
0,0 → 1,66
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#include "fdlibm.h"
 
#ifdef __STDC__
float truncf(float x)
#else
float truncf(x)
float x;
#endif
{
__int32_t signbit, w, exponent_less_127;
 
GET_FLOAT_WORD(w,x);
 
/* Extract sign bit. */
signbit = w & 0x80000000;
 
/* Extract exponent field. */
exponent_less_127 = ((w & 0x7f800000) >> 23) - 127;
 
if (exponent_less_127 < 23)
{
if (exponent_less_127 < 0)
{
/* -1 < x < 1, so result is +0 or -0. */
SET_FLOAT_WORD(x, signbit);
}
else
{
SET_FLOAT_WORD(x, signbit | (w & ~(0x007fffff >> exponent_less_127)));
}
}
else
{
if (exponent_less_127 == 255)
/* x is NaN or infinite. */
return x + x;
 
/* All bits in the fraction field are relevant. */
}
return x;
}
 
#ifdef _DOUBLE_IS_32BITS
 
#ifdef __STDC__
double trunc(double x)
#else
double trunc(x)
double x;
#endif
{
return (double) truncf((float) x);
}
 
#endif /* defined(_DOUBLE_IS_32BITS) */
/programs/develop/libraries/newlib/math/w_acos.c
0,0 → 1,118
 
/* @(#)w_acos.c 5.1 93/09/24 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
/*
FUNCTION
<<acos>>, <<acosf>>---arc cosine
 
INDEX
acos
INDEX
acosf
 
ANSI_SYNOPSIS
#include <math.h>
double acos(double <[x]>);
float acosf(float <[x]>);
 
TRAD_SYNOPSIS
#include <math.h>
double acos(<[x]>)
double <[x]>;
 
float acosf(<[x]>)
float <[x]>;
 
 
 
DESCRIPTION
 
<<acos>> computes the inverse cosine (arc cosine) of the input value.
Arguments to <<acos>> must be in the range @minus{}1 to 1.
 
<<acosf>> is identical to <<acos>>, except that it performs
its calculations on <<floats>>.
 
RETURNS
@ifnottex
<<acos>> and <<acosf>> return values in radians, in the range of 0 to pi.
@end ifnottex
@tex
<<acos>> and <<acosf>> return values in radians, in the range of <<0>> to $\pi$.
@end tex
 
If <[x]> is not between @minus{}1 and 1, the returned value is NaN
(not a number) the global variable <<errno>> is set to <<EDOM>>, and a
<<DOMAIN error>> message is sent as standard error output.
 
You can modify error handling for these functions using <<matherr>>.
 
 
QUICKREF ANSI SVID POSIX RENTRANT
acos y,y,y,m
acosf n,n,n,m
 
MATHREF
acos, [-1,1], acos(arg),,,
acos, NAN, arg,DOMAIN,EDOM
 
MATHREF
acosf, [-1,1], acosf(arg),,,
acosf, NAN, argf,DOMAIN,EDOM
*/
 
/*
* wrap_acos(x)
*/
 
#include "fdlibm.h"
#include <errno.h>
 
#ifndef _DOUBLE_IS_32BITS
 
#ifdef __STDC__
double acos(double x) /* wrapper acos */
#else
double acos(x) /* wrapper acos */
double x;
#endif
{
#ifdef _IEEE_LIBM
return __ieee754_acos(x);
#else
double z;
struct exception exc;
z = __ieee754_acos(x);
if(_LIB_VERSION == _IEEE_ || isnan(x)) return z;
if(fabs(x)>1.0) {
/* acos(|x|>1) */
exc.type = DOMAIN;
exc.name = "acos";
exc.err = 0;
exc.arg1 = exc.arg2 = x;
exc.retval = nan("");
if (_LIB_VERSION == _POSIX_)
errno = EDOM;
else if (!matherr(&exc)) {
errno = EDOM;
}
if (exc.err != 0)
errno = exc.err;
return exc.retval;
} else
return z;
#endif
}
 
#endif /* defined(_DOUBLE_IS_32BITS) */
/programs/develop/libraries/newlib/math/w_acosh.c
0,0 → 1,122
 
/* @(#)w_acosh.c 5.1 93/09/24 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*
*/
 
/*
FUNCTION
<<acosh>>, <<acoshf>>---inverse hyperbolic cosine
 
INDEX
acosh
INDEX
acoshf
 
ANSI_SYNOPSIS
#include <math.h>
double acosh(double <[x]>);
float acoshf(float <[x]>);
 
TRAD_SYNOPSIS
#include <math.h>
double acosh(<[x]>)
double <[x]>;
 
float acoshf(<[x]>)
float <[x]>;
 
DESCRIPTION
<<acosh>> calculates the inverse hyperbolic cosine of <[x]>.
<<acosh>> is defined as
@ifnottex
. log(<[x]> + sqrt(<[x]>*<[x]>-1))
@end ifnottex
@tex
$$ln\Bigl(x + \sqrt{x^2-1}\Bigr)$$
@end tex
 
<[x]> must be a number greater than or equal to 1.
 
<<acoshf>> is identical, other than taking and returning floats.
 
RETURNS
<<acosh>> and <<acoshf>> return the calculated value. If <[x]>
less than 1, the return value is NaN and <<errno>> is set to <<EDOM>>.
 
You can change the error-handling behavior with the non-ANSI
<<matherr>> function.
 
PORTABILITY
Neither <<acosh>> nor <<acoshf>> are ANSI C. They are not recommended
for portable programs.
 
 
QUICKREF ANSI SVID POSIX RENTRANT
acos n,n,n,m
acosf n,n,n,m
 
MATHREF
acosh, NAN, arg,DOMAIN,EDOM
acosh, < 1.0, NAN,DOMAIN,EDOM
acosh, >=1.0, acosh(arg),,,
 
MATHREF
acoshf, NAN, arg,DOMAIN,EDOM
acoshf, < 1.0, NAN,DOMAIN,EDOM
acoshf, >=1.0, acosh(arg),,,
 
*/
 
/*
* wrapper acosh(x)
*/
 
#include "fdlibm.h"
#include <errno.h>
 
#ifndef _DOUBLE_IS_32BITS
 
#ifdef __STDC__
double acosh(double x) /* wrapper acosh */
#else
double acosh(x) /* wrapper acosh */
double x;
#endif
{
#ifdef _IEEE_LIBM
return __ieee754_acosh(x);
#else
double z;
struct exception exc;
z = __ieee754_acosh(x);
if(_LIB_VERSION == _IEEE_ || isnan(x)) return z;
if(x<1.0) {
/* acosh(x<1) */
exc.type = DOMAIN;
exc.name = "acosh";
exc.err = 0;
exc.arg1 = exc.arg2 = x;
exc.retval = 0.0/0.0;
if (_LIB_VERSION == _POSIX_)
errno = EDOM;
else if (!matherr(&exc)) {
errno = EDOM;
}
if (exc.err != 0)
errno = exc.err;
return exc.retval;
} else
return z;
#endif
}
 
#endif /* defined(_DOUBLE_IS_32BITS) */
/programs/develop/libraries/newlib/math/w_asin.c
0,0 → 1,121
 
/* @(#)w_asin.c 5.1 93/09/24 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*
*/
 
/*
FUNCTION
<<asin>>, <<asinf>>---arc sine
 
INDEX
asin
INDEX
asinf
 
ANSI_SYNOPSIS
#include <math.h>
double asin(double <[x]>);
float asinf(float <[x]>);
 
TRAD_SYNOPSIS
#include <math.h>
double asin(<[x]>)
double <[x]>;
 
float asinf(<[x]>)
float <[x]>;
 
 
DESCRIPTION
 
<<asin>> computes the inverse sine (arc sine) of the argument <[x]>.
Arguments to <<asin>> must be in the range @minus{}1 to 1.
 
<<asinf>> is identical to <<asin>>, other than taking and
returning floats.
 
You can modify error handling for these routines using <<matherr>>.
 
RETURNS
@ifnottex
<<asin>> returns values in radians, in the range of -pi/2 to pi/2.
@end ifnottex
@tex
<<asin>> returns values in radians, in the range of $-\pi/2$ to $\pi/2$.
@end tex
 
If <[x]> is not in the range @minus{}1 to 1, <<asin>> and <<asinf>>
return NaN (not a number), set the global variable <<errno>> to
<<EDOM>>, and issue a <<DOMAIN error>> message.
 
You can change this error treatment using <<matherr>>.
 
QUICKREF ANSI SVID POSIX RENTRANT
asin y,y,y,m
asinf n,n,n,m
 
MATHREF
asin, -1<=arg<=1, asin(arg),,,
asin, NAN, arg,EDOM, DOMAIN
 
MATHREF
asinf, -1<=arg<=1, asin(arg),,,
asinf, NAN, arg,EDOM, DOMAIN
 
 
*/
 
/*
* wrapper asin(x)
*/
 
 
#include "fdlibm.h"
#include <errno.h>
 
#ifndef _DOUBLE_IS_32BITS
 
#ifdef __STDC__
double asin(double x) /* wrapper asin */
#else
double asin(x) /* wrapper asin */
double x;
#endif
{
#ifdef _IEEE_LIBM
return __ieee754_asin(x);
#else
double z;
struct exception exc;
z = __ieee754_asin(x);
if(_LIB_VERSION == _IEEE_ || isnan(x)) return z;
if(fabs(x)>1.0) {
/* asin(|x|>1) */
exc.type = DOMAIN;
exc.name = "asin";
exc.err = 0;
exc.arg1 = exc.arg2 = x;
exc.retval = nan("");
if(_LIB_VERSION == _POSIX_)
errno = EDOM;
else if (!matherr(&exc)) {
errno = EDOM;
}
if (exc.err != 0)
errno = exc.err;
return exc.retval;
} else
return z;
#endif
}
 
#endif /* defined(_DOUBLE_IS_32BITS) */
/programs/develop/libraries/newlib/math/w_atanh.c
0,0 → 1,140
 
/* @(#)w_atanh.c 5.1 93/09/24 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
/*
FUNCTION
<<atanh>>, <<atanhf>>---inverse hyperbolic tangent
 
INDEX
atanh
INDEX
atanhf
 
ANSI_SYNOPSIS
#include <math.h>
double atanh(double <[x]>);
float atanhf(float <[x]>);
 
TRAD_SYNOPSIS
#include <math.h>
double atanh(<[x]>)
double <[x]>;
 
float atanhf(<[x]>)
float <[x]>;
 
DESCRIPTION
<<atanh>> calculates the inverse hyperbolic tangent of <[x]>.
 
<<atanhf>> is identical, other than taking and returning
<<float>> values.
 
RETURNS
<<atanh>> and <<atanhf>> return the calculated value.
 
If
@ifnottex
|<[x]>|
@end ifnottex
@tex
$|x|$
@end tex
is greater than 1, the global <<errno>> is set to <<EDOM>> and
the result is a NaN. A <<DOMAIN error>> is reported.
 
If
@ifnottex
|<[x]>|
@end ifnottex
@tex
$|x|$
@end tex
is 1, the global <<errno>> is set to <<EDOM>>; and the result is
infinity with the same sign as <<x>>. A <<SING error>> is reported.
 
You can modify the error handling for these routines using
<<matherr>>.
 
PORTABILITY
Neither <<atanh>> nor <<atanhf>> are ANSI C.
 
QUICKREF
atanh - pure
atanhf - pure
 
 
*/
 
/*
* wrapper atanh(x)
*/
 
#include "fdlibm.h"
#include <errno.h>
 
#ifndef _DOUBLE_IS_32BITS
 
#ifdef __STDC__
double atanh(double x) /* wrapper atanh */
#else
double atanh(x) /* wrapper atanh */
double x;
#endif
{
#ifdef _IEEE_LIBM
return __ieee754_atanh(x);
#else
double z,y;
struct exception exc;
z = __ieee754_atanh(x);
if(_LIB_VERSION == _IEEE_ || isnan(x)) return z;
y = fabs(x);
if(y>=1.0) {
if(y>1.0) {
/* atanh(|x|>1) */
exc.type = DOMAIN;
exc.name = "atanh";
exc.err = 0;
exc.arg1 = exc.arg2 = x;
exc.retval = 0.0/0.0;
if (_LIB_VERSION == _POSIX_)
errno = EDOM;
else if (!matherr(&exc)) {
errno = EDOM;
}
} else {
/* atanh(|x|=1) */
exc.type = SING;
exc.name = "atanh";
exc.err = 0;
exc.arg1 = exc.arg2 = x;
exc.retval = x/0.0; /* sign(x)*inf */
if (_LIB_VERSION == _POSIX_)
errno = EDOM;
else if (!matherr(&exc)) {
errno = EDOM;
}
}
if (exc.err != 0)
errno = exc.err;
return exc.retval;
} else
return z;
#endif
}
 
#endif /* defined(_DOUBLE_IS_32BITS) */
 
 
 
 
/programs/develop/libraries/newlib/math/w_cosh.c
0,0 → 1,116
 
/* @(#)w_cosh.c 5.1 93/09/24 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
/*
 
FUNCTION
<<cosh>>, <<coshf>>---hyperbolic cosine
 
ANSI_SYNOPSIS
#include <math.h>
double cosh(double <[x]>);
float coshf(float <[x]>)
 
TRAD_SYNOPSIS
#include <math.h>
double cosh(<[x]>)
double <[x]>;
 
float coshf(<[x]>)
float <[x]>;
 
DESCRIPTION
 
<<cosh>> computes the hyperbolic cosine of the argument <[x]>.
<<cosh(<[x]>)>> is defined as
@ifnottex
. (exp(x) + exp(-x))/2
@end ifnottex
@tex
$${(e^x + e^{-x})} \over 2$$
@end tex
 
Angles are specified in radians.
<<coshf>> is identical, save that it takes and returns <<float>>.
 
RETURNS
The computed value is returned. When the correct value would create
an overflow, <<cosh>> returns the value <<HUGE_VAL>> with the
appropriate sign, and the global value <<errno>> is set to <<ERANGE>>.
 
You can modify error handling for these functions using the
function <<matherr>>.
 
PORTABILITY
<<cosh>> is ANSI.
<<coshf>> is an extension.
 
QUICKREF
cosh ansi pure
coshf - pure
*/
 
/*
* wrapper cosh(x)
*/
 
#include "fdlibm.h"
#include <errno.h>
 
#ifndef _DOUBLE_IS_32BITS
#ifdef __STDC__
double cosh(double x) /* wrapper cosh */
#else
double cosh(x) /* wrapper cosh */
double x;
#endif
{
#ifdef _IEEE_LIBM
return __ieee754_cosh(x);
#else
double z;
struct exception exc;
z = __ieee754_cosh(x);
if(_LIB_VERSION == _IEEE_ || isnan(x)) return z;
if(fabs(x)>7.10475860073943863426e+02) {
/* cosh(finite) overflow */
#ifndef HUGE_VAL
#define HUGE_VAL inf
double inf = 0.0;
 
SET_HIGH_WORD(inf,0x7ff00000); /* set inf to infinite */
#endif
exc.type = OVERFLOW;
exc.name = "cosh";
exc.err = 0;
exc.arg1 = exc.arg2 = x;
if (_LIB_VERSION == _SVID_)
exc.retval = HUGE;
else
exc.retval = HUGE_VAL;
if (_LIB_VERSION == _POSIX_)
errno = ERANGE;
else if (!matherr(&exc)) {
errno = ERANGE;
}
if (exc.err != 0)
errno = exc.err;
return exc.retval;
} else
return z;
#endif
}
 
#endif /* defined(_DOUBLE_IS_32BITS) */
/programs/develop/libraries/newlib/math/w_drem.c
0,0 → 1,15
/*
* drem() wrapper for remainder().
*
* Written by J.T. Conklin, <jtc@wimsey.com>
* Placed into the Public Domain, 1994.
*/
 
#include "fdlibm.h"
 
double
drem(x, y)
double x, y;
{
return remainder(x, y);
}
/programs/develop/libraries/newlib/math/w_exp.c
0,0 → 1,136
 
/* @(#)w_exp.c 5.1 93/09/24 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
/*
FUNCTION
<<exp>>, <<expf>>---exponential
INDEX
exp
INDEX
expf
 
ANSI_SYNOPSIS
#include <math.h>
double exp(double <[x]>);
float expf(float <[x]>);
 
TRAD_SYNOPSIS
#include <math.h>
double exp(<[x]>);
double <[x]>;
 
float expf(<[x]>);
float <[x]>;
 
DESCRIPTION
<<exp>> and <<expf>> calculate the exponential of <[x]>, that is,
@ifnottex
e raised to the power <[x]> (where e
@end ifnottex
@tex
$e^x$ (where $e$
@end tex
is the base of the natural system of logarithms, approximately 2.71828).
 
You can use the (non-ANSI) function <<matherr>> to specify
error handling for these functions.
 
RETURNS
On success, <<exp>> and <<expf>> return the calculated value.
If the result underflows, the returned value is <<0>>. If the
result overflows, the returned value is <<HUGE_VAL>>. In
either case, <<errno>> is set to <<ERANGE>>.
 
PORTABILITY
<<exp>> is ANSI C. <<expf>> is an extension.
 
*/
 
/*
* wrapper exp(x)
*/
 
#include "fdlibm.h"
#include <errno.h>
 
#ifndef _DOUBLE_IS_32BITS
 
#ifdef __STDC__
static const double
#else
static double
#endif
o_threshold= 7.09782712893383973096e+02, /* 0x40862E42, 0xFEFA39EF */
u_threshold= -7.45133219101941108420e+02; /* 0xc0874910, 0xD52D3051 */
 
#ifdef __STDC__
double exp(double x) /* wrapper exp */
#else
double exp(x) /* wrapper exp */
double x;
#endif
{
#ifdef _IEEE_LIBM
return __ieee754_exp(x);
#else
double z;
struct exception exc;
z = __ieee754_exp(x);
if(_LIB_VERSION == _IEEE_) return z;
if(finite(x)) {
if(x>o_threshold) {
/* exp(finite) overflow */
#ifndef HUGE_VAL
#define HUGE_VAL inf
double inf = 0.0;
 
SET_HIGH_WORD(inf,0x7ff00000); /* set inf to infinite */
#endif
exc.type = OVERFLOW;
exc.name = "exp";
exc.err = 0;
exc.arg1 = exc.arg2 = x;
if (_LIB_VERSION == _SVID_)
exc.retval = HUGE;
else
exc.retval = HUGE_VAL;
if (_LIB_VERSION == _POSIX_)
errno = ERANGE;
else if (!matherr(&exc)) {
errno = ERANGE;
}
if (exc.err != 0)
errno = exc.err;
return exc.retval;
} else if(x<u_threshold) {
/* exp(finite) underflow */
exc.type = UNDERFLOW;
exc.name = "exp";
exc.err = 0;
exc.arg1 = exc.arg2 = x;
exc.retval = 0.0;
if (_LIB_VERSION == _POSIX_)
errno = ERANGE;
else if (!matherr(&exc)) {
errno = ERANGE;
}
if (exc.err != 0)
errno = exc.err;
return exc.retval;
}
}
return z;
#endif
}
 
#endif /* defined(_DOUBLE_IS_32BITS) */
/programs/develop/libraries/newlib/math/w_exp2.c
0,0 → 1,70
 
/* @(#)w_exp2.c 5.1 93/09/24 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
/*
FUNCTION
<<exp2>>, <<exp2f>>--exponential, base 2
INDEX
exp2
INDEX
exp2f
 
ANSI_SYNOPSIS
#include <math.h>
double exp2(double <[x]>);
float exp2f(float <[x]>);
 
DESCRIPTION
<<exp2>> and <<exp2f>> calculate 2 ^ <[x]>, that is,
@ifnottex
2 raised to the power <[x]>.
@end ifnottex
@tex
$2^x$
@end tex
 
You can use the (non-ANSI) function <<matherr>> to specify
error handling for these functions.
 
RETURNS
On success, <<exp2>> and <<exp2f>> return the calculated value.
If the result underflows, the returned value is <<0>>. If the
result overflows, the returned value is <<HUGE_VAL>>. In
either case, <<errno>> is set to <<ERANGE>>.
 
PORTABILITY
ANSI C, POSIX.
 
*/
 
/*
* wrapper exp2(x)
*/
 
#include "fdlibm.h"
#include <errno.h>
#include <math.h>
 
#ifndef _DOUBLE_IS_32BITS
 
#ifdef __STDC__
double exp2(double x) /* wrapper exp2 */
#else
double exp2(x) /* wrapper exp2 */
double x;
#endif
{
return pow(2.0, x);
}
 
#endif /* defined(_DOUBLE_IS_32BITS) */
/programs/develop/libraries/newlib/math/w_fmod.c
0,0 → 1,107
 
/* @(#)w_fmod.c 5.1 93/09/24 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
/*
FUNCTION
<<fmod>>, <<fmodf>>---floating-point remainder (modulo)
 
INDEX
fmod
INDEX
fmodf
 
ANSI_SYNOPSIS
#include <math.h>
double fmod(double <[x]>, double <[y]>)
float fmodf(float <[x]>, float <[y]>)
 
TRAD_SYNOPSIS
#include <math.h>
double fmod(<[x]>, <[y]>)
double (<[x]>, <[y]>);
 
float fmodf(<[x]>, <[y]>)
float (<[x]>, <[y]>);
 
DESCRIPTION
The <<fmod>> and <<fmodf>> functions compute the floating-point
remainder of <[x]>/<[y]> (<[x]> modulo <[y]>).
 
RETURNS
The <<fmod>> function returns the value
@ifnottex
<[x]>-<[i]>*<[y]>,
@end ifnottex
@tex
$x-i\times y$,
@end tex
for the largest integer <[i]> such that, if <[y]> is nonzero, the
result has the same sign as <[x]> and magnitude less than the
magnitude of <[y]>.
 
<<fmod(<[x]>,0)>> returns NaN, and sets <<errno>> to <<EDOM>>.
 
You can modify error treatment for these functions using <<matherr>>.
 
PORTABILITY
<<fmod>> is ANSI C. <<fmodf>> is an extension.
*/
 
/*
* wrapper fmod(x,y)
*/
 
#include "fdlibm.h"
#include <errno.h>
 
#ifndef _DOUBLE_IS_32BITS
 
#ifdef __STDC__
double fmod(double x, double y) /* wrapper fmod */
#else
double fmod(x,y) /* wrapper fmod */
double x,y;
#endif
{
#ifdef _IEEE_LIBM
return __ieee754_fmod(x,y);
#else
double z;
struct exception exc;
z = __ieee754_fmod(x,y);
if(_LIB_VERSION == _IEEE_ ||isnan(y)||isnan(x)) return z;
if(y==0.0) {
/* fmod(x,0) */
exc.type = DOMAIN;
exc.name = "fmod";
exc.arg1 = x;
exc.arg2 = y;
exc.err = 0;
if (_LIB_VERSION == _SVID_)
exc.retval = x;
else
exc.retval = 0.0/0.0;
if (_LIB_VERSION == _POSIX_)
errno = EDOM;
else if (!matherr(&exc)) {
errno = EDOM;
}
if (exc.err != 0)
errno = exc.err;
return exc.retval;
} else
return z;
#endif
}
 
#endif /* defined(_DOUBLE_IS_32BITS) */
/programs/develop/libraries/newlib/math/w_gamma.c
0,0 → 1,226
 
/* @(#)w_gamma.c 5.1 93/09/24 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*
*/
 
/* BUG: FIXME?
According to Linux man pages for tgamma, lgamma, and gamma, the gamma
function was originally defined in BSD as implemented here--the log of the gamma
function. BSD 4.3 changed the name to lgamma, apparently removing gamma. BSD
4.4 re-introduced the gamma name with the more intuitive, without logarithm,
plain gamma function. The C99 standard apparently wanted to avoid a problem
with the poorly-named earlier gamma and used tgamma when adding a plain
gamma function.
So the current gamma is matching an old, bad definition, and not
matching a newer, better definition. */
/*
FUNCTION
<<gamma>>, <<gammaf>>, <<lgamma>>, <<lgammaf>>, <<gamma_r>>, <<gammaf_r>>, <<lgamma_r>>, <<lgammaf_r>>, <<tgamma>>, and <<tgammaf>>--logarithmic and plain gamma functions
 
INDEX
gamma
INDEX
gammaf
INDEX
lgamma
INDEX
lgammaf
INDEX
gamma_r
INDEX
gammaf_r
INDEX
lgamma_r
INDEX
lgammaf_r
INDEX
tgamma
INDEX
tgammaf
 
ANSI_SYNOPSIS
#include <math.h>
double gamma(double <[x]>);
float gammaf(float <[x]>);
double lgamma(double <[x]>);
float lgammaf(float <[x]>);
double gamma_r(double <[x]>, int *<[signgamp]>);
float gammaf_r(float <[x]>, int *<[signgamp]>);
double lgamma_r(double <[x]>, int *<[signgamp]>);
float lgammaf_r(float <[x]>, int *<[signgamp]>);
double tgamma(double <[x]>);
float tgammaf(float <[x]>);
 
TRAD_SYNOPSIS
#include <math.h>
double gamma(<[x]>)
double <[x]>;
float gammaf(<[x]>)
float <[x]>;
double lgamma(<[x]>)
double <[x]>;
float lgammaf(<[x]>)
float <[x]>;
double gamma_r(<[x]>, <[signgamp]>)
double <[x]>;
int <[signgamp]>;
float gammaf_r(<[x]>, <[signgamp]>)
float <[x]>;
int <[signgamp]>;
double lgamma_r(<[x]>, <[signgamp]>)
double <[x]>;
int <[signgamp]>;
float lgammaf_r(<[x]>, <[signgamp]>)
float <[x]>;
int <[signgamp]>;
double tgamma(<[x]>)
double <[x]>;
float tgammaf(<[x]>)
float <[x]>;
 
DESCRIPTION
<<gamma>> calculates
@tex
$\mit ln\bigl(\Gamma(x)\bigr)$,
@end tex
the natural logarithm of the gamma function of <[x]>. The gamma function
(<<exp(gamma(<[x]>))>>) is a generalization of factorial, and retains
the property that
@ifnottex
<<exp(gamma(N))>> is equivalent to <<N*exp(gamma(N-1))>>.
@end ifnottex
@tex
$\mit \Gamma(N)\equiv N\times\Gamma(N-1)$.
@end tex
Accordingly, the results of the gamma function itself grow very
quickly. <<gamma>> is defined as
@tex
$\mit ln\bigl(\Gamma(x)\bigr)$ rather than simply $\mit \Gamma(x)$
@end tex
@ifnottex
the natural log of the gamma function, rather than the gamma function
itself,
@end ifnottex
to extend the useful range of results representable.
 
The sign of the result is returned in the global variable <<signgam>>,
which is declared in math.h.
 
<<gammaf>> performs the same calculation as <<gamma>>, but uses and
returns <<float>> values.
 
<<lgamma>> and <<lgammaf>> are alternate names for <<gamma>> and
<<gammaf>>. The use of <<lgamma>> instead of <<gamma>> is a reminder
that these functions compute the log of the gamma function, rather
than the gamma function itself.
 
The functions <<gamma_r>>, <<gammaf_r>>, <<lgamma_r>>, and
<<lgammaf_r>> are just like <<gamma>>, <<gammaf>>, <<lgamma>>, and
<<lgammaf>>, respectively, but take an additional argument. This
additional argument is a pointer to an integer. This additional
argument is used to return the sign of the result, and the global
variable <<signgam>> is not used. These functions may be used for
reentrant calls (but they will still set the global variable <<errno>>
if an error occurs).
 
<<tgamma>> and <<tgammaf>> are the "true gamma" functions, returning
@tex
$\mit \Gamma(x)$,
@end tex
the gamma function of <[x]>--without a logarithm.
(They are apparently so named because of the prior existence of the old,
poorly-named <<gamma>> functions which returned the log of gamma up
through BSD 4.2.)
 
RETURNS
Normally, the computed result is returned.
 
When <[x]> is a nonpositive integer, <<gamma>> returns <<HUGE_VAL>>
and <<errno>> is set to <<EDOM>>. If the result overflows, <<gamma>>
returns <<HUGE_VAL>> and <<errno>> is set to <<ERANGE>>.
 
You can modify this error treatment using <<matherr>>.
 
PORTABILITY
Neither <<gamma>> nor <<gammaf>> is ANSI C. It is better not to use either
of these; use <<lgamma>> or <<tgamma>> instead.@*
<<lgamma>>, <<lgammaf>>, <<tgamma>>, and <<tgammaf>> are nominally C standard
in terms of the base return values, although the <<matherr>> error-handling
is not standard, nor is the <[signgam]> global for <<lgamma>>.
*/
 
/* double gamma(double x)
* Return the logarithm of the Gamma function of x.
*
* Method: call gamma_r
*/
 
#include "fdlibm.h"
#include <reent.h>
#include <errno.h>
 
#ifndef _DOUBLE_IS_32BITS
 
#ifdef __STDC__
double gamma(double x)
#else
double gamma(x)
double x;
#endif
{
#ifdef _IEEE_LIBM
return __ieee754_gamma_r(x,&(_REENT_SIGNGAM(_REENT)));
#else
double y;
struct exception exc;
y = __ieee754_gamma_r(x,&(_REENT_SIGNGAM(_REENT)));
if(_LIB_VERSION == _IEEE_) return y;
if(!finite(y)&&finite(x)) {
#ifndef HUGE_VAL
#define HUGE_VAL inf
double inf = 0.0;
 
SET_HIGH_WORD(inf,0x7ff00000); /* set inf to infinite */
#endif
exc.name = "gamma";
exc.err = 0;
exc.arg1 = exc.arg2 = x;
if (_LIB_VERSION == _SVID_)
exc.retval = HUGE;
else
exc.retval = HUGE_VAL;
if(floor(x)==x&&x<=0.0) {
/* gamma(-integer) or gamma(0) */
exc.type = SING;
if (_LIB_VERSION == _POSIX_)
errno = EDOM;
else if (!matherr(&exc)) {
errno = EDOM;
}
} else {
/* gamma(finite) overflow */
exc.type = OVERFLOW;
if (_LIB_VERSION == _POSIX_)
errno = ERANGE;
else if (!matherr(&exc)) {
errno = ERANGE;
}
}
if (exc.err != 0)
errno = exc.err;
return exc.retval;
} else
return y;
#endif
}
 
#endif /* defined(_DOUBLE_IS_32BITS) */
/programs/develop/libraries/newlib/math/w_hypot.c
57,8 → 57,6
* wrapper hypot(x,y)
*/
 
#define _IEEE_LIBM
 
#include "fdlibm.h"
#include <errno.h>
 
/programs/develop/libraries/newlib/math/w_j0.c
0,0 → 1,229
 
/* @(#)w_j0.c 5.1 93/09/24 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
/*
FUNCTION
<<jN>>, <<jNf>>, <<yN>>, <<yNf>>---Bessel functions
 
INDEX
j0
INDEX
j0f
INDEX
j1
INDEX
j1f
INDEX
jn
INDEX
jnf
INDEX
y0
INDEX
y0f
INDEX
y1
INDEX
y1f
INDEX
yn
INDEX
ynf
 
ANSI_SYNOPSIS
#include <math.h>
double j0(double <[x]>);
float j0f(float <[x]>);
double j1(double <[x]>);
float j1f(float <[x]>);
double jn(int <[n]>, double <[x]>);
float jnf(int <[n]>, float <[x]>);
double y0(double <[x]>);
float y0f(float <[x]>);
double y1(double <[x]>);
float y1f(float <[x]>);
double yn(int <[n]>, double <[x]>);
float ynf(int <[n]>, float <[x]>);
 
TRAD_SYNOPSIS
#include <math.h>
 
double j0(<[x]>)
double <[x]>;
float j0f(<[x]>)
float <[x]>;
double j1(<[x]>)
double <[x]>;
float j1f(<[x]>)
float <[x]>;
double jn(<[n]>, <[x]>)
int <[n]>;
double <[x]>;
float jnf(<[n]>, <[x]>)
int <[n]>;
float <[x]>;
 
double y0(<[x]>)
double <[x]>;
float y0f(<[x]>)
float <[x]>;
double y1(<[x]>)
double <[x]>;
float y1f(<[x]>)
float <[x]>;
double yn(<[n]>, <[x]>)
int <[n]>;
double <[x]>;
float ynf(<[n]>, <[x]>)
int <[n]>;
float <[x]>;
 
DESCRIPTION
The Bessel functions are a family of functions that solve the
differential equation
@ifnottex
. 2 2 2
. x y'' + xy' + (x - p )y = 0
@end ifnottex
@tex
$$x^2{d^2y\over dx^2} + x{dy\over dx} + (x^2-p^2)y = 0$$
@end tex
These functions have many applications in engineering and physics.
 
<<jn>> calculates the Bessel function of the first kind of order
<[n]>. <<j0>> and <<j1>> are special cases for order 0 and order
1 respectively.
 
Similarly, <<yn>> calculates the Bessel function of the second kind of
order <[n]>, and <<y0>> and <<y1>> are special cases for order 0 and
1.
 
<<jnf>>, <<j0f>>, <<j1f>>, <<ynf>>, <<y0f>>, and <<y1f>> perform the
same calculations, but on <<float>> rather than <<double>> values.
 
RETURNS
The value of each Bessel function at <[x]> is returned.
 
PORTABILITY
None of the Bessel functions are in ANSI C.
*/
 
/*
* wrapper j0(double x), y0(double x)
*/
 
#include "fdlibm.h"
#include <errno.h>
 
#ifndef _DOUBLE_IS_32BITS
 
#ifdef __STDC__
double j0(double x) /* wrapper j0 */
#else
double j0(x) /* wrapper j0 */
double x;
#endif
{
#ifdef _IEEE_LIBM
return __ieee754_j0(x);
#else
struct exception exc;
double z = __ieee754_j0(x);
if(_LIB_VERSION == _IEEE_ || isnan(x)) return z;
if(fabs(x)>X_TLOSS) {
/* j0(|x|>X_TLOSS) */
exc.type = TLOSS;
exc.name = "j0";
exc.err = 0;
exc.arg1 = exc.arg2 = x;
exc.retval = 0.0;
if (_LIB_VERSION == _POSIX_)
errno = ERANGE;
else if (!matherr(&exc)) {
errno = ERANGE;
}
if (exc.err != 0)
errno = exc.err;
return exc.retval;
} else
return z;
#endif
}
 
#ifdef __STDC__
double y0(double x) /* wrapper y0 */
#else
double y0(x) /* wrapper y0 */
double x;
#endif
{
#ifdef _IEEE_LIBM
return __ieee754_y0(x);
#else
double z;
struct exception exc;
z = __ieee754_y0(x);
if(_LIB_VERSION == _IEEE_ || isnan(x) ) return z;
if(x <= 0.0){
#ifndef HUGE_VAL
#define HUGE_VAL inf
double inf = 0.0;
 
SET_HIGH_WORD(inf,0x7ff00000); /* set inf to infinite */
#endif
/* y0(0) = -inf or y0(x<0) = NaN */
exc.type = DOMAIN; /* should be SING for IEEE y0(0) */
exc.name = "y0";
exc.err = 0;
exc.arg1 = exc.arg2 = x;
if (_LIB_VERSION == _SVID_)
exc.retval = -HUGE;
else
exc.retval = -HUGE_VAL;
if (_LIB_VERSION == _POSIX_)
errno = EDOM;
else if (!matherr(&exc)) {
errno = EDOM;
}
if (exc.err != 0)
errno = exc.err;
return exc.retval;
}
if(x>X_TLOSS) {
/* y0(x>X_TLOSS) */
exc.type = TLOSS;
exc.name = "y0";
exc.err = 0;
exc.arg1 = exc.arg2 = x;
exc.retval = 0.0;
if (_LIB_VERSION == _POSIX_)
errno = ERANGE;
else if (!matherr(&exc)) {
errno = ERANGE;
}
if (exc.err != 0)
errno = exc.err;
return exc.retval;
} else
return z;
#endif
}
 
#endif /* defined(_DOUBLE_IS_32BITS) */
 
 
 
 
 
 
 
/programs/develop/libraries/newlib/math/w_j1.c
0,0 → 1,121
 
/* @(#)w_j1.c 5.1 93/09/24 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
/*
* wrapper of j1,y1
*/
 
#include "fdlibm.h"
#include <errno.h>
 
#ifndef _DOUBLE_IS_32BITS
 
#ifdef __STDC__
double j1(double x) /* wrapper j1 */
#else
double j1(x) /* wrapper j1 */
double x;
#endif
{
#ifdef _IEEE_LIBM
return __ieee754_j1(x);
#else
double z;
struct exception exc;
z = __ieee754_j1(x);
if(_LIB_VERSION == _IEEE_ || isnan(x) ) return z;
if(fabs(x)>X_TLOSS) {
/* j1(|x|>X_TLOSS) */
exc.type = TLOSS;
exc.name = "j1";
exc.err = 0;
exc.arg1 = exc.arg2 = x;
exc.retval = 0.0;
if (_LIB_VERSION == _POSIX_)
errno = ERANGE;
else if (!matherr(&exc)) {
errno = ERANGE;
}
if (exc.err != 0)
errno = exc.err;
return exc.retval;
} else
return z;
#endif
}
 
#ifdef __STDC__
double y1(double x) /* wrapper y1 */
#else
double y1(x) /* wrapper y1 */
double x;
#endif
{
#ifdef _IEEE_LIBM
return __ieee754_y1(x);
#else
double z;
struct exception exc;
z = __ieee754_y1(x);
if(_LIB_VERSION == _IEEE_ || isnan(x) ) return z;
if(x <= 0.0){
#ifndef HUGE_VAL
#define HUGE_VAL inf
double inf = 0.0;
 
SET_HIGH_WORD(inf,0x7ff00000); /* set inf to infinite */
#endif
/* y1(0) = -inf or y1(x<0) = NaN */
exc.type = DOMAIN; /* should be SING for IEEE */
exc.name = "y1";
exc.err = 0;
exc.arg1 = exc.arg2 = x;
if (_LIB_VERSION == _SVID_)
exc.retval = -HUGE;
else
exc.retval = -HUGE_VAL;
if (_LIB_VERSION == _POSIX_)
errno = EDOM;
else if (!matherr(&exc)) {
errno = EDOM;
}
if (exc.err != 0)
errno = exc.err;
return exc.retval;
}
if(x>X_TLOSS) {
/* y1(x>X_TLOSS) */
exc.type = TLOSS;
exc.name = "y1";
exc.err = 0;
exc.arg1 = exc.arg2 = x;
exc.retval = 0.0;
if (_LIB_VERSION == _POSIX_)
errno = ERANGE;
else if (!matherr(&exc)) {
errno = ERANGE;
}
if (exc.err != 0)
errno = exc.err;
return exc.retval;
} else
return z;
#endif
}
 
#endif /* defined(_DOUBLE_IS_32BITS) */
 
 
 
 
 
/programs/develop/libraries/newlib/math/w_jn.c
0,0 → 1,141
 
/* @(#)w_jn.c 5.1 93/09/24 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
/*
* wrapper jn(int n, double x), yn(int n, double x)
* floating point Bessel's function of the 1st and 2nd kind
* of order n
*
* Special cases:
* y0(0)=y1(0)=yn(n,0) = -inf with division by zero signal;
* y0(-ve)=y1(-ve)=yn(n,-ve) are NaN with invalid signal.
* Note 2. About jn(n,x), yn(n,x)
* For n=0, j0(x) is called,
* for n=1, j1(x) is called,
* for n<x, forward recursion us used starting
* from values of j0(x) and j1(x).
* for n>x, a continued fraction approximation to
* j(n,x)/j(n-1,x) is evaluated and then backward
* recursion is used starting from a supposed value
* for j(n,x). The resulting value of j(0,x) is
* compared with the actual value to correct the
* supposed value of j(n,x).
*
* yn(n,x) is similar in all respects, except
* that forward recursion is used for all
* values of n>1.
*
*/
 
#include "fdlibm.h"
#include <errno.h>
 
#ifndef _DOUBLE_IS_32BITS
 
#ifdef __STDC__
double jn(int n, double x) /* wrapper jn */
#else
double jn(n,x) /* wrapper jn */
double x; int n;
#endif
{
#ifdef _IEEE_LIBM
return __ieee754_jn(n,x);
#else
double z;
struct exception exc;
z = __ieee754_jn(n,x);
if(_LIB_VERSION == _IEEE_ || isnan(x) ) return z;
if(fabs(x)>X_TLOSS) {
/* jn(|x|>X_TLOSS) */
exc.type = TLOSS;
exc.name = "jn";
exc.err = 0;
exc.arg1 = n;
exc.arg2 = x;
exc.retval = 0.0;
if (_LIB_VERSION == _POSIX_)
errno = ERANGE;
else if (!matherr(&exc)) {
errno = ERANGE;
}
if (exc.err != 0)
errno = exc.err;
return exc.retval;
} else
return z;
#endif
}
 
#ifdef __STDC__
double yn(int n, double x) /* wrapper yn */
#else
double yn(n,x) /* wrapper yn */
double x; int n;
#endif
{
#ifdef _IEEE_LIBM
return __ieee754_yn(n,x);
#else
double z;
struct exception exc;
z = __ieee754_yn(n,x);
if(_LIB_VERSION == _IEEE_ || isnan(x) ) return z;
if(x <= 0.0){
/* yn(n,0) = -inf or yn(x<0) = NaN */
#ifndef HUGE_VAL
#define HUGE_VAL inf
double inf = 0.0;
 
SET_HIGH_WORD(inf,0x7ff00000); /* set inf to infinite */
#endif
exc.type = DOMAIN; /* should be SING for IEEE */
exc.name = "yn";
exc.err = 0;
exc.arg1 = n;
exc.arg2 = x;
if (_LIB_VERSION == _SVID_)
exc.retval = -HUGE;
else
exc.retval = -HUGE_VAL;
if (_LIB_VERSION == _POSIX_)
errno = EDOM;
else if (!matherr(&exc)) {
errno = EDOM;
}
if (exc.err != 0)
errno = exc.err;
return exc.retval;
}
if(x>X_TLOSS) {
/* yn(x>X_TLOSS) */
exc.type = TLOSS;
exc.name = "yn";
exc.err = 0;
exc.arg1 = n;
exc.arg2 = x;
exc.retval = 0.0;
if (_LIB_VERSION == _POSIX_)
errno = ERANGE;
else if (!matherr(&exc)) {
errno = ERANGE;
}
if (exc.err != 0)
errno = exc.err;
return exc.retval;
} else
return z;
#endif
}
 
#endif /* defined(_DOUBLE_IS_32BITS) */
/programs/develop/libraries/newlib/math/w_lgamma.c
0,0 → 1,89
 
/* @(#)w_lgamma.c 5.1 93/09/24 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*
*/
 
/* double lgamma(double x)
* Return the logarithm of the Gamma function of x.
*
* Method: call __ieee754_lgamma_r
*/
 
#include "fdlibm.h"
#include <reent.h>
#include <errno.h>
 
#ifndef _DOUBLE_IS_32BITS
 
#ifdef __STDC__
double lgamma(double x)
#else
double lgamma(x)
double x;
#endif
{
#ifdef _IEEE_LIBM
return __ieee754_lgamma_r(x,&(_REENT_SIGNGAM(_REENT)));
#else
double y;
struct exception exc;
y = __ieee754_lgamma_r(x,&(_REENT_SIGNGAM(_REENT)));
if(_LIB_VERSION == _IEEE_) return y;
if(!finite(y)&&finite(x)) {
#ifndef HUGE_VAL
#define HUGE_VAL inf
double inf = 0.0;
 
SET_HIGH_WORD(inf,0x7ff00000); /* set inf to infinite */
#endif
exc.name = "lgamma";
exc.err = 0;
exc.arg1 = x;
exc.arg2 = x;
if (_LIB_VERSION == _SVID_)
exc.retval = HUGE;
else
exc.retval = HUGE_VAL;
if(floor(x)==x&&x<=0.0) {
/* lgamma(-integer) */
exc.type = SING;
if (_LIB_VERSION == _POSIX_)
errno = EDOM;
else if (!matherr(&exc)) {
errno = EDOM;
}
 
} else {
/* lgamma(finite) overflow */
exc.type = OVERFLOW;
if (_LIB_VERSION == _POSIX_)
errno = ERANGE;
else if (!matherr(&exc)) {
errno = ERANGE;
}
}
if (exc.err != 0)
errno = exc.err;
return exc.retval;
} else
return y;
#endif
}
 
#endif /* defined(_DOUBLE_IS_32BITS) */
 
 
 
 
 
 
 
/programs/develop/libraries/newlib/math/w_log.c
0,0 → 1,116
 
/* @(#)w_log.c 5.1 93/09/24 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
/*
FUNCTION
<<log>>, <<logf>>---natural logarithms
 
INDEX
log
INDEX
logf
 
ANSI_SYNOPSIS
#include <math.h>
double log(double <[x]>);
float logf(float <[x]>);
 
TRAD_SYNOPSIS
#include <math.h>
double log(<[x]>);
double <[x]>;
 
float logf(<[x]>);
float <[x]>;
 
DESCRIPTION
Return the natural logarithm of <[x]>, that is, its logarithm base e
(where e is the base of the natural system of logarithms, 2.71828@dots{}).
<<log>> and <<logf>> are identical save for the return and argument types.
 
You can use the (non-ANSI) function <<matherr>> to specify error
handling for these functions.
 
RETURNS
Normally, returns the calculated value. When <[x]> is zero, the
returned value is <<-HUGE_VAL>> and <<errno>> is set to <<ERANGE>>.
When <[x]> is negative, the returned value is NaN (not a number) and
<<errno>> is set to <<EDOM>>. You can control the error behavior via
<<matherr>>.
 
PORTABILITY
<<log>> is ANSI. <<logf>> is an extension.
*/
 
/*
* wrapper log(x)
*/
 
#include "fdlibm.h"
#include <errno.h>
 
#ifndef _DOUBLE_IS_32BITS
 
#ifdef __STDC__
double log(double x) /* wrapper log */
#else
double log(x) /* wrapper log */
double x;
#endif
{
#ifdef _IEEE_LIBM
return __ieee754_log(x);
#else
double z;
struct exception exc;
z = __ieee754_log(x);
if(_LIB_VERSION == _IEEE_ || isnan(x) || x > 0.0) return z;
#ifndef HUGE_VAL
#define HUGE_VAL inf
double inf = 0.0;
 
SET_HIGH_WORD(inf,0x7ff00000); /* set inf to infinite */
#endif
exc.name = "log";
exc.err = 0;
exc.arg1 = x;
exc.arg2 = x;
if (_LIB_VERSION == _SVID_)
exc.retval = -HUGE;
else
exc.retval = -HUGE_VAL;
if(x==0.0) {
/* log(0) */
exc.type = SING;
if (_LIB_VERSION == _POSIX_)
errno = ERANGE;
else if (!matherr(&exc)) {
errno = ERANGE;
}
} else {
/* log(x<0) */
exc.type = DOMAIN;
if (_LIB_VERSION == _POSIX_)
errno = EDOM;
else if (!matherr(&exc)) {
errno = EDOM;
}
exc.retval = nan("");
}
if (exc.err != 0)
errno = exc.err;
return exc.retval;
#endif
}
 
#endif /* defined(_DOUBLE_IS_32BITS) */
/programs/develop/libraries/newlib/math/w_log10.c
0,0 → 1,116
 
/* @(#)w_log10.c 5.1 93/09/24 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
/*
FUNCTION
<<log10>>, <<log10f>>---base 10 logarithms
 
INDEX
log10
INDEX
log10f
 
ANSI_SYNOPSIS
#include <math.h>
double log10(double <[x]>);
float log10f(float <[x]>);
 
TRAD_SYNOPSIS
#include <math.h>
double log10(<[x]>)
double <[x]>;
 
float log10f(<[x]>)
float <[x]>;
 
DESCRIPTION
<<log10>> returns the base 10 logarithm of <[x]>.
It is implemented as <<log(<[x]>) / log(10)>>.
 
<<log10f>> is identical, save that it takes and returns <<float>> values.
 
RETURNS
<<log10>> and <<log10f>> return the calculated value.
 
See the description of <<log>> for information on errors.
 
PORTABILITY
<<log10>> is ANSI C. <<log10f>> is an extension.
 
*/
 
/*
* wrapper log10(X)
*/
 
#include "fdlibm.h"
#include <errno.h>
 
#ifndef _DOUBLE_IS_32BITS
 
#ifdef __STDC__
double log10(double x) /* wrapper log10 */
#else
double log10(x) /* wrapper log10 */
double x;
#endif
{
#ifdef _IEEE_LIBM
return __ieee754_log10(x);
#else
double z;
struct exception exc;
z = __ieee754_log10(x);
if(_LIB_VERSION == _IEEE_ || isnan(x)) return z;
if(x<=0.0) {
#ifndef HUGE_VAL
#define HUGE_VAL inf
double inf = 0.0;
 
SET_HIGH_WORD(inf,0x7ff00000); /* set inf to infinite */
#endif
exc.name = "log10";
exc.err = 0;
exc.arg1 = x;
exc.arg2 = x;
if (_LIB_VERSION == _SVID_)
exc.retval = -HUGE;
else
exc.retval = -HUGE_VAL;
if(x==0.0) {
/* log10(0) */
exc.type = SING;
if (_LIB_VERSION == _POSIX_)
errno = ERANGE;
else if (!matherr(&exc)) {
errno = ERANGE;
}
} else {
/* log10(x<0) */
exc.type = DOMAIN;
if (_LIB_VERSION == _POSIX_)
errno = EDOM;
else if (!matherr(&exc)) {
errno = EDOM;
}
exc.retval = nan("");
}
if (exc.err != 0)
errno = exc.err;
return exc.retval;
} else
return z;
#endif
}
 
#endif /* defined(_DOUBLE_IS_32BITS) */
/programs/develop/libraries/newlib/math/w_pow.c
0,0 → 1,231
 
 
/* @(#)w_pow.c 5.2 93/10/01 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
/*
FUNCTION
<<pow>>, <<powf>>---x to the power y
INDEX
pow
INDEX
powf
 
 
ANSI_SYNOPSIS
#include <math.h>
double pow(double <[x]>, double <[y]>);
float powf(float <[x]>, float <[y]>);
 
TRAD_SYNOPSIS
#include <math.h>
double pow(<[x]>, <[y]>);
double <[x]>, <[y]>;
 
float powf(<[x]>, <[y]>);
float <[x]>, <[y]>;
 
DESCRIPTION
<<pow>> and <<powf>> calculate <[x]> raised to the exponent <[y]>.
@tex
(That is, $x^y$.)
@end tex
 
RETURNS
On success, <<pow>> and <<powf>> return the value calculated.
 
When the argument values would produce overflow, <<pow>>
returns <<HUGE_VAL>> and set <<errno>> to <<ERANGE>>. If the
argument <[x]> passed to <<pow>> or <<powf>> is a negative
noninteger, and <[y]> is also not an integer, then <<errno>>
is set to <<EDOM>>. If <[x]> and <[y]> are both 0, then
<<pow>> and <<powf>> return <<1>>.
 
You can modify error handling for these functions using <<matherr>>.
 
PORTABILITY
<<pow>> is ANSI C. <<powf>> is an extension. */
 
/*
* wrapper pow(x,y) return x**y
*/
 
#include "fdlibm.h"
#include <errno.h>
 
#ifndef _DOUBLE_IS_32BITS
 
#ifdef __STDC__
double pow(double x, double y) /* wrapper pow */
#else
double pow(x,y) /* wrapper pow */
double x,y;
#endif
{
#ifdef _IEEE_LIBM
return __ieee754_pow(x,y);
#else
double z;
#ifndef HUGE_VAL
#define HUGE_VAL inf
double inf = 0.0;
 
SET_HIGH_WORD(inf,0x7ff00000); /* set inf to infinite */
#endif
struct exception exc;
z=__ieee754_pow(x,y);
if(_LIB_VERSION == _IEEE_|| isnan(y)) return z;
if(isnan(x)) {
if(y==0.0) {
/* pow(NaN,0.0) */
/* error only if _LIB_VERSION == _SVID_ & _XOPEN_ */
exc.type = DOMAIN;
exc.name = "pow";
exc.err = 0;
exc.arg1 = x;
exc.arg2 = y;
exc.retval = 1.0;
if (_LIB_VERSION == _IEEE_ ||
_LIB_VERSION == _POSIX_) exc.retval = 1.0;
else if (!matherr(&exc)) {
errno = EDOM;
}
if (exc.err != 0)
errno = exc.err;
return exc.retval;
} else
return z;
}
if(x==0.0){
if(y==0.0) {
/* pow(0.0,0.0) */
/* error only if _LIB_VERSION == _SVID_ */
exc.type = DOMAIN;
exc.name = "pow";
exc.err = 0;
exc.arg1 = x;
exc.arg2 = y;
exc.retval = 0.0;
if (_LIB_VERSION != _SVID_) exc.retval = 1.0;
else if (!matherr(&exc)) {
errno = EDOM;
}
if (exc.err != 0)
errno = exc.err;
return exc.retval;
}
if(finite(y)&&y<0.0) {
/* 0**neg */
exc.type = DOMAIN;
exc.name = "pow";
exc.err = 0;
exc.arg1 = x;
exc.arg2 = y;
if (_LIB_VERSION == _SVID_)
exc.retval = 0.0;
else
exc.retval = -HUGE_VAL;
if (_LIB_VERSION == _POSIX_)
errno = EDOM;
else if (!matherr(&exc)) {
errno = EDOM;
}
if (exc.err != 0)
errno = exc.err;
return exc.retval;
}
return z;
}
if(!finite(z)) {
if(finite(x)&&finite(y)) {
if(isnan(z)) {
/* neg**non-integral */
exc.type = DOMAIN;
exc.name = "pow";
exc.err = 0;
exc.arg1 = x;
exc.arg2 = y;
if (_LIB_VERSION == _SVID_)
exc.retval = 0.0;
else
exc.retval = 0.0/0.0; /* X/Open allow NaN */
if (_LIB_VERSION == _POSIX_)
errno = EDOM;
else if (!matherr(&exc)) {
errno = EDOM;
}
if (exc.err != 0)
errno = exc.err;
return exc.retval;
} else {
/* pow(x,y) overflow */
exc.type = OVERFLOW;
exc.name = "pow";
exc.err = 0;
exc.arg1 = x;
exc.arg2 = y;
if (_LIB_VERSION == _SVID_) {
exc.retval = HUGE;
y *= 0.5;
if(x<0.0&&rint(y)!=y) exc.retval = -HUGE;
} else {
exc.retval = HUGE_VAL;
y *= 0.5;
if(x<0.0&&rint(y)!=y) exc.retval = -HUGE_VAL;
}
if (_LIB_VERSION == _POSIX_)
errno = ERANGE;
else if (!matherr(&exc)) {
errno = ERANGE;
}
if (exc.err != 0)
errno = exc.err;
return exc.retval;
}
}
}
if(z==0.0&&finite(x)&&finite(y)) {
/* pow(x,y) underflow */
exc.type = UNDERFLOW;
exc.name = "pow";
exc.err = 0;
exc.arg1 = x;
exc.arg2 = y;
exc.retval = 0.0;
if (_LIB_VERSION == _POSIX_)
errno = ERANGE;
else if (!matherr(&exc)) {
errno = ERANGE;
}
if (exc.err != 0)
errno = exc.err;
return exc.retval;
}
return z;
#endif
}
 
#endif /* defined(_DOUBLE_IS_32BITS) */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
/programs/develop/libraries/newlib/math/w_remainder.c
0,0 → 1,108
 
/* @(#)w_remainder.c 5.1 93/09/24 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
/*
FUNCTION
<<remainder>>, <<remainderf>>---round and remainder
INDEX
remainder
INDEX
remainderf
 
ANSI_SYNOPSIS
#include <math.h>
double remainder(double <[x]>, double <[y]>);
float remainderf(float <[x]>, float <[y]>);
 
TRAD_SYNOPSIS
#include <math.h>
double remainder(<[x]>,<[y]>)
double <[x]>, <[y]>;
float remainderf(<[x]>,<[y]>)
float <[x]>, <[y]>;
 
DESCRIPTION
<<remainder>> and <<remainderf>> find the remainder of
<[x]>/<[y]>; this value is in the range -<[y]>/2 .. +<[y]>/2.
 
RETURNS
<<remainder>> returns the integer result as a double.
 
PORTABILITY
<<remainder>> is a System V release 4.
<<remainderf>> is an extension.
 
*/
 
/*
* wrapper remainder(x,p)
*/
 
#include "fdlibm.h"
#include <errno.h>
 
#ifndef _DOUBLE_IS_32BITS
 
#ifdef __STDC__
double remainder(double x, double y) /* wrapper remainder */
#else
double remainder(x,y) /* wrapper remainder */
double x,y;
#endif
{
#ifdef _IEEE_LIBM
return __ieee754_remainder(x,y);
#else
double z;
struct exception exc;
z = __ieee754_remainder(x,y);
if(_LIB_VERSION == _IEEE_ || isnan(y)) return z;
if(y==0.0) {
/* remainder(x,0) */
exc.type = DOMAIN;
exc.name = "remainder";
exc.err = 0;
exc.arg1 = x;
exc.arg2 = y;
exc.retval = 0.0/0.0;
if (_LIB_VERSION == _POSIX_)
errno = EDOM;
else if (!matherr(&exc)) {
errno = EDOM;
}
if (exc.err != 0)
errno = exc.err;
return exc.retval;
} else
return z;
#endif
}
 
#endif /* defined(_DOUBLE_IS_32BITS) */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
/programs/develop/libraries/newlib/math/w_scalb.c
0,0 → 1,94
 
/* @(#)w_scalb.c 5.1 93/09/24 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
/*
* wrapper scalb(double x, double fn) is provide for
* passing various standard test suite. One
* should use scalbn() instead.
*/
 
#include "fdlibm.h"
#include <errno.h>
 
#ifndef _DOUBLE_IS_32BITS
 
#ifdef __STDC__
#ifdef _SCALB_INT
double scalb(double x, int fn) /* wrapper scalb */
#else
double scalb(double x, double fn) /* wrapper scalb */
#endif
#else
double scalb(x,fn) /* wrapper scalb */
#ifdef _SCALB_INT
double x; int fn;
#else
double x,fn;
#endif
#endif
{
#ifdef _IEEE_LIBM
return __ieee754_scalb(x,fn);
#else
double z;
#ifndef HUGE_VAL
#define HUGE_VAL inf
double inf = 0.0;
 
SET_HIGH_WORD(inf,0x7ff00000); /* set inf to infinite */
#endif
struct exception exc;
z = __ieee754_scalb(x,fn);
if(_LIB_VERSION == _IEEE_) return z;
if(!(finite(z)||isnan(z))&&finite(x)) {
/* scalb overflow; SVID also returns +-HUGE_VAL */
exc.type = OVERFLOW;
exc.name = "scalb";
exc.err = 0;
exc.arg1 = x;
exc.arg2 = fn;
exc.retval = x > 0.0 ? HUGE_VAL : -HUGE_VAL;
if (_LIB_VERSION == _POSIX_)
errno = ERANGE;
else if (!matherr(&exc)) {
errno = ERANGE;
}
if (exc.err != 0)
errno = exc.err;
return exc.retval;
}
if(z==0.0&&z!=x) {
/* scalb underflow */
exc.type = UNDERFLOW;
exc.name = "scalb";
exc.err = 0;
exc.arg1 = x;
exc.arg2 = fn;
exc.retval = copysign(0.0,x);
if (_LIB_VERSION == _POSIX_)
errno = ERANGE;
else if (!matherr(&exc)) {
errno = ERANGE;
}
if (exc.err != 0)
errno = exc.err;
return exc.retval;
}
#ifndef _SCALB_INT
if(!finite(fn)) errno = ERANGE;
#endif
return z;
#endif
}
 
#endif /* defined(_DOUBLE_IS_32BITS) */
/programs/develop/libraries/newlib/math/w_sincos.c
0,0 → 1,22
/* sincos -- currently no more efficient than two separate calls to
sin and cos. */
 
#include "fdlibm.h"
#include <errno.h>
 
#ifndef _DOUBLE_IS_32BITS
 
#ifdef __STDC__
void sincos(double x, double *sinx, double *cosx)
#else
void sincos(x, sinx, cosx)
double x;
double *sinx;
double *cosx;
#endif
{
*sinx = sin (x);
*cosx = cos (x);
}
 
#endif /* defined(_DOUBLE_IS_32BITS) */
/programs/develop/libraries/newlib/math/w_sinh.c
0,0 → 1,120
 
/* @(#)w_sinh.c 5.1 93/09/24 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
 
/*
FUNCTION
<<sinh>>, <<sinhf>>---hyperbolic sine
 
INDEX
sinh
INDEX
sinhf
 
ANSI_SYNOPSIS
#include <math.h>
double sinh(double <[x]>);
float sinhf(float <[x]>);
 
TRAD_SYNOPSIS
#include <math.h>
double sinh(<[x]>)
double <[x]>;
 
float sinhf(<[x]>)
float <[x]>;
 
DESCRIPTION
<<sinh>> computes the hyperbolic sine of the argument <[x]>.
Angles are specified in radians. <<sinh>>(<[x]>) is defined as
@ifnottex
. (exp(<[x]>) - exp(-<[x]>))/2
@end ifnottex
@tex
$${e^x - e^{-x}}\over 2$$
@end tex
 
<<sinhf>> is identical, save that it takes and returns <<float>> values.
 
RETURNS
The hyperbolic sine of <[x]> is returned.
 
When the correct result is too large to be representable (an
overflow), <<sinh>> returns <<HUGE_VAL>> with the
appropriate sign, and sets the global value <<errno>> to
<<ERANGE>>.
 
You can modify error handling for these functions with <<matherr>>.
 
PORTABILITY
<<sinh>> is ANSI C.
<<sinhf>> is an extension.
 
QUICKREF
sinh ansi pure
sinhf - pure
*/
 
/*
* wrapper sinh(x)
*/
 
#include "fdlibm.h"
#include <errno.h>
 
#ifndef _DOUBLE_IS_32BITS
 
#ifdef __STDC__
double sinh(double x) /* wrapper sinh */
#else
double sinh(x) /* wrapper sinh */
double x;
#endif
{
#ifdef _IEEE_LIBM
return __ieee754_sinh(x);
#else
double z;
struct exception exc;
z = __ieee754_sinh(x);
if(_LIB_VERSION == _IEEE_) return z;
if(!finite(z)&&finite(x)) {
/* sinh(finite) overflow */
#ifndef HUGE_VAL
#define HUGE_VAL inf
double inf = 0.0;
SET_HIGH_WORD(inf,0x7ff00000); /* set inf to infinite */
#endif
exc.type = OVERFLOW;
exc.name = "sinh";
exc.err = 0;
exc.arg1 = exc.arg2 = x;
if (_LIB_VERSION == _SVID_)
exc.retval = ( (x>0.0) ? HUGE : -HUGE);
else
exc.retval = ( (x>0.0) ? HUGE_VAL : -HUGE_VAL);
if (_LIB_VERSION == _POSIX_)
errno = ERANGE;
else if (!matherr(&exc)) {
errno = ERANGE;
}
if (exc.err != 0)
errno = exc.err;
return exc.retval;
} else
return z;
#endif
}
 
#endif /* defined(_DOUBLE_IS_32BITS) */
/programs/develop/libraries/newlib/math/w_sqrt.c
0,0 → 1,93
 
/* @(#)w_sqrt.c 5.1 93/09/24 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
/*
FUNCTION
<<sqrt>>, <<sqrtf>>---positive square root
 
INDEX
sqrt
INDEX
sqrtf
 
ANSI_SYNOPSIS
#include <math.h>
double sqrt(double <[x]>);
float sqrtf(float <[x]>);
 
TRAD_SYNOPSIS
#include <math.h>
double sqrt(<[x]>);
float sqrtf(<[x]>);
 
DESCRIPTION
<<sqrt>> computes the positive square root of the argument.
You can modify error handling for this function with
<<matherr>>.
 
RETURNS
On success, the square root is returned. If <[x]> is real and
positive, then the result is positive. If <[x]> is real and
negative, the global value <<errno>> is set to <<EDOM>> (domain error).
 
 
PORTABILITY
<<sqrt>> is ANSI C. <<sqrtf>> is an extension.
*/
 
/*
* wrapper sqrt(x)
*/
 
#include "fdlibm.h"
#include <errno.h>
 
#ifndef _DOUBLE_IS_32BITS
 
#ifdef __STDC__
double sqrt(double x) /* wrapper sqrt */
#else
double sqrt(x) /* wrapper sqrt */
double x;
#endif
{
#ifdef _IEEE_LIBM
return __ieee754_sqrt(x);
#else
struct exception exc;
double z;
z = __ieee754_sqrt(x);
if(_LIB_VERSION == _IEEE_ || isnan(x)) return z;
if(x<0.0) {
exc.type = DOMAIN;
exc.name = "sqrt";
exc.err = 0;
exc.arg1 = exc.arg2 = x;
if (_LIB_VERSION == _SVID_)
exc.retval = 0.0;
else
exc.retval = 0.0/0.0;
if (_LIB_VERSION == _POSIX_)
errno = EDOM;
else if (!matherr(&exc)) {
errno = EDOM;
}
if (exc.err != 0)
errno = exc.err;
return exc.retval;
} else
return z;
#endif
}
 
#endif /* defined(_DOUBLE_IS_32BITS) */
/programs/develop/libraries/newlib/math/w_tgamma.c
0,0 → 1,48
/* @(#)w_gamma.c 5.1 93/09/24 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
/* double gamma(double x)
* Return the logarithm of the Gamma function of x or the Gamma function of x,
* depending on the library mode.
*/
 
#include "fdlibm.h"
 
#ifndef _DOUBLE_IS_32BITS
 
#ifdef __STDC__
double tgamma(double x)
#else
double tgamma(x)
double x;
#endif
{
double y;
int local_signgam;
y = __ieee754_gamma_r(x,&local_signgam);
if (local_signgam < 0) y = -y;
#ifdef _IEEE_LIBM
return y;
#else
if(_LIB_VERSION == _IEEE_) return y;
 
if(!finite(y)&&finite(x)) {
if(floor(x)==x&&x<=0.0)
return __kernel_standard(x,x,41); /* tgamma pole */
else
return __kernel_standard(x,x,40); /* tgamma overflow */
}
return y;
#endif
}
 
#endif /* defined(_DOUBLE_IS_32BITS) */
/programs/develop/libraries/newlib/math/wf_acos.c
0,0 → 1,69
/* wf_acos.c -- float version of w_acos.c.
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
*/
 
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
/*
* wrap_acosf(x)
*/
 
#include "fdlibm.h"
#include <errno.h>
 
#ifdef _HAVE_STDC
float acosf(float x) /* wrapper acosf */
#else
float acosf(x) /* wrapper acosf */
float x;
#endif
{
#ifdef _IEEE_LIBM
return __ieee754_acosf(x);
#else
float z;
struct exception exc;
z = __ieee754_acosf(x);
if(_LIB_VERSION == _IEEE_ || isnan(x)) return z;
if(fabsf(x)>(float)1.0) {
/* acosf(|x|>1) */
exc.type = DOMAIN;
exc.name = "acosf";
exc.err = 0;
exc.arg1 = exc.arg2 = (double)x;
exc.retval = nan("");
if (_LIB_VERSION == _POSIX_)
errno = EDOM;
else if (!matherr(&exc)) {
errno = EDOM;
}
if (exc.err != 0)
errno = exc.err;
return (float)exc.retval;
} else
return z;
#endif
}
 
#ifdef _DOUBLE_IS_32BITS
 
#ifdef __STDC__
double acos(double x)
#else
double acos(x)
double x;
#endif
{
return (double) acosf((float) x);
}
 
#endif /* defined(_DOUBLE_IS_32BITS) */
/programs/develop/libraries/newlib/math/wf_acosh.c
0,0 → 1,70
/* wf_acosh.c -- float version of w_acosh.c.
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
*/
 
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*
*/
 
/*
* wrapper acoshf(x)
*/
 
#include "fdlibm.h"
#include <errno.h>
 
#ifdef __STDC__
float acoshf(float x) /* wrapper acoshf */
#else
float acoshf(x) /* wrapper acoshf */
float x;
#endif
{
#ifdef _IEEE_LIBM
return __ieee754_acoshf(x);
#else
float z;
struct exception exc;
z = __ieee754_acoshf(x);
if(_LIB_VERSION == _IEEE_ || isnan(x)) return z;
if(x<(float)1.0) {
/* acoshf(x<1) */
exc.type = DOMAIN;
exc.name = "acoshf";
exc.err = 0;
exc.arg1 = exc.arg2 = (double)x;
exc.retval = 0.0/0.0;
if (_LIB_VERSION == _POSIX_)
errno = EDOM;
else if (!matherr(&exc)) {
errno = EDOM;
}
if (exc.err != 0)
errno = exc.err;
return (float)exc.retval;
} else
return z;
#endif
}
 
#ifdef _DOUBLE_IS_32BITS
 
#ifdef __STDC__
double acosh(double x)
#else
double acosh(x)
double x;
#endif
{
return (double) acoshf((float) x);
}
 
#endif /* defined(_DOUBLE_IS_32BITS) */
/programs/develop/libraries/newlib/math/wf_asin.c
0,0 → 1,71
/* wf_asin.c -- float version of w_asin.c.
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
*/
 
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*
*/
 
/*
* wrapper asinf(x)
*/
 
 
#include "fdlibm.h"
#include <errno.h>
 
#ifdef __STDC__
float asinf(float x) /* wrapper asinf */
#else
float asinf(x) /* wrapper asinf */
float x;
#endif
{
#ifdef _IEEE_LIBM
return __ieee754_asinf(x);
#else
float z;
struct exception exc;
z = __ieee754_asinf(x);
if(_LIB_VERSION == _IEEE_ || isnan(x)) return z;
if(fabsf(x)>(float)1.0) {
/* asinf(|x|>1) */
exc.type = DOMAIN;
exc.name = "asinf";
exc.err = 0;
exc.arg1 = exc.arg2 = (double)x;
exc.retval = nan("");
if(_LIB_VERSION == _POSIX_)
errno = EDOM;
else if (!matherr(&exc)) {
errno = EDOM;
}
if (exc.err != 0)
errno = exc.err;
return (float)exc.retval;
} else
return z;
#endif
}
 
#ifdef _DOUBLE_IS_32BITS
 
#ifdef __STDC__
double asin(double x)
#else
double asin(x)
double x;
#endif
{
return (double) asinf((float) x);
}
 
#endif /* defined(_DOUBLE_IS_32BITS) */
/programs/develop/libraries/newlib/math/wf_atan2.c
0,0 → 1,46
/* wf_atan2.c -- float version of w_atan2.c.
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
*/
 
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*
*/
 
/*
* wrapper atan2f(y,x)
*/
 
#include "fdlibm.h"
#include <errno.h>
 
#ifdef __STDC__
float atan2f(float y, float x) /* wrapper atan2f */
#else
float atan2f(y,x) /* wrapper atan2 */
float y,x;
#endif
{
return __ieee754_atan2f(y,x);
}
 
#ifdef _DOUBLE_IS_32BITS
 
#ifdef __STDC__
double atan2(double y, double x)
#else
double atan2(y,x)
double y,x;
#endif
{
return (double) atan2f((float) y, (float) x);
}
 
#endif /* defined(_DOUBLE_IS_32BITS) */
/programs/develop/libraries/newlib/math/wf_atanh.c
0,0 → 1,83
/* wf_atanh.c -- float version of w_atanh.c.
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
*/
 
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
/*
* wrapper atanhf(x)
*/
 
#include "fdlibm.h"
#include <errno.h>
 
#ifdef __STDC__
float atanhf(float x) /* wrapper atanhf */
#else
float atanhf(x) /* wrapper atanhf */
float x;
#endif
{
#ifdef _IEEE_LIBM
return __ieee754_atanhf(x);
#else
float z,y;
struct exception exc;
z = __ieee754_atanhf(x);
if(_LIB_VERSION == _IEEE_ || isnan(x)) return z;
y = fabsf(x);
if(y>=(float)1.0) {
if(y>(float)1.0) {
/* atanhf(|x|>1) */
exc.type = DOMAIN;
exc.name = "atanhf";
exc.err = 0;
exc.arg1 = exc.arg2 = (double)x;
exc.retval = 0.0/0.0;
if (_LIB_VERSION == _POSIX_)
errno = EDOM;
else if (!matherr(&exc)) {
errno = EDOM;
}
} else {
/* atanhf(|x|=1) */
exc.type = SING;
exc.name = "atanhf";
exc.err = 0;
exc.arg1 = exc.arg2 = (double)x;
exc.retval = x/0.0; /* sign(x)*inf */
if (_LIB_VERSION == _POSIX_)
errno = EDOM;
else if (!matherr(&exc)) {
errno = EDOM;
}
}
if (exc.err != 0)
errno = exc.err;
return (float)exc.retval;
} else
return z;
#endif
}
 
#ifdef _DOUBLE_IS_32BITS
 
#ifdef __STDC__
double atanh(double x)
#else
double atanh(x)
double x;
#endif
{
return (double) atanhf((float) x);
}
 
#endif /* defined(_DOUBLE_IS_32BITS) */
/programs/develop/libraries/newlib/math/wf_cosh.c
0,0 → 1,78
/* wf_cosh.c -- float version of w_cosh.c.
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
*/
 
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
/*
* wrapper coshf(x)
*/
 
#include "fdlibm.h"
#include <errno.h>
 
#ifdef __STDC__
float coshf(float x) /* wrapper coshf */
#else
float coshf(x) /* wrapper coshf */
float x;
#endif
{
#ifdef _IEEE_LIBM
return __ieee754_coshf(x);
#else
float z;
struct exception exc;
z = __ieee754_coshf(x);
if(_LIB_VERSION == _IEEE_ || isnan(x)) return z;
if(fabsf(x)>(float)8.9415985107e+01) {
/* coshf(finite) overflow */
#ifndef HUGE_VAL
#define HUGE_VAL inf
double inf = 0.0;
 
SET_HIGH_WORD(inf,0x7ff00000); /* set inf to infinite */
#endif
exc.type = OVERFLOW;
exc.name = "coshf";
exc.err = 0;
exc.arg1 = exc.arg2 = (double)x;
if (_LIB_VERSION == _SVID_)
exc.retval = HUGE;
else
exc.retval = HUGE_VAL;
if (_LIB_VERSION == _POSIX_)
errno = ERANGE;
else if (!matherr(&exc)) {
errno = ERANGE;
}
if (exc.err != 0)
errno = exc.err;
return (float)exc.retval;
} else
return z;
#endif
}
 
#ifdef _DOUBLE_IS_32BITS
 
#ifdef __STDC__
double cosh(double x)
#else
double cosh(x)
double x;
#endif
{
return (double) coshf((float) x);
}
 
#endif /* defined(_DOUBLE_IS_32BITS) */
/programs/develop/libraries/newlib/math/wf_drem.c
0,0 → 1,19
/*
* dremf() wrapper for remainderf().
*
* Written by J.T. Conklin, <jtc@wimsey.com>
* Placed into the Public Domain, 1994.
*/
 
#include "fdlibm.h"
 
float
#ifdef __STDC__
dremf(float x, float y)
#else
dremf(x, y)
float x, y;
#endif
{
return remainderf(x, y);
}
/programs/develop/libraries/newlib/math/wf_exp.c
0,0 → 1,103
/* wf_exp.c -- float version of w_exp.c.
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
*/
 
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
/*
* wrapper expf(x)
*/
 
#include "fdlibm.h"
#include <errno.h>
 
#ifdef __STDC__
static const float
#else
static float
#endif
o_threshold= 8.8721679688e+01, /* 0x42b17180 */
u_threshold= -1.0397208405e+02; /* 0xc2cff1b5 */
 
#ifdef __STDC__
float expf(float x) /* wrapper expf */
#else
float expf(x) /* wrapper expf */
float x;
#endif
{
#ifdef _IEEE_LIBM
return __ieee754_expf(x);
#else
float z;
struct exception exc;
z = __ieee754_expf(x);
if(_LIB_VERSION == _IEEE_) return z;
if(finitef(x)) {
if(x>o_threshold) {
/* expf(finite) overflow */
#ifndef HUGE_VAL
#define HUGE_VAL inf
double inf = 0.0;
 
SET_HIGH_WORD(inf,0x7ff00000); /* set inf to infinite */
#endif
exc.type = OVERFLOW;
exc.name = "expf";
exc.err = 0;
exc.arg1 = exc.arg2 = (double)x;
if (_LIB_VERSION == _SVID_)
exc.retval = HUGE;
else
exc.retval = HUGE_VAL;
if (_LIB_VERSION == _POSIX_)
errno = ERANGE;
else if (!matherr(&exc)) {
errno = ERANGE;
}
if (exc.err != 0)
errno = exc.err;
return exc.retval;
} else if(x<u_threshold) {
/* expf(finite) underflow */
exc.type = UNDERFLOW;
exc.name = "expf";
exc.err = 0;
exc.arg1 = exc.arg2 = (double)x;
exc.retval = 0.0;
if (_LIB_VERSION == _POSIX_)
errno = ERANGE;
else if (!matherr(&exc)) {
errno = ERANGE;
}
if (exc.err != 0)
errno = exc.err;
return exc.retval;
}
}
return z;
#endif
}
 
#ifdef _DOUBLE_IS_32BITS
 
#ifdef __STDC__
double exp(double x)
#else
double exp(x)
double x;
#endif
{
return (double) expf((float) x);
}
 
#endif /* defined(_DOUBLE_IS_32BITS) */
/programs/develop/libraries/newlib/math/wf_exp2.c
0,0 → 1,46
/* wf_exp2.c -- float version of w_exp2.c.
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
*/
 
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
/*
* wrapper exp2f(x)
*/
 
#include "fdlibm.h"
#include <errno.h>
#include <math.h>
 
#ifdef __STDC__
float exp2f(float x) /* wrapper exp2f */
#else
float exp2f(x) /* wrapper exp2f */
float x;
#endif
{
return powf(2.0, x);
}
 
#ifdef _DOUBLE_IS_32BITS
 
#ifdef __STDC__
double exp2(double x)
#else
double exp2(x)
double x;
#endif
{
return (double) exp2f((float) x);
}
 
#endif /* defined(_DOUBLE_IS_32BITS) */
/programs/develop/libraries/newlib/math/wf_fmod.c
0,0 → 1,73
/* wf_fmod.c -- float version of w_fmod.c.
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
*/
 
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
/*
* wrapper fmodf(x,y)
*/
 
#include "fdlibm.h"
#include <errno.h>
 
#ifdef __STDC__
float fmodf(float x, float y) /* wrapper fmodf */
#else
float fmodf(x,y) /* wrapper fmodf */
float x,y;
#endif
{
#ifdef _IEEE_LIBM
return __ieee754_fmodf(x,y);
#else
float z;
struct exception exc;
z = __ieee754_fmodf(x,y);
if(_LIB_VERSION == _IEEE_ ||isnan(y)||isnan(x)) return z;
if(y==(float)0.0) {
/* fmodf(x,0) */
exc.type = DOMAIN;
exc.name = "fmodf";
exc.err = 0;
exc.arg1 = (double)x;
exc.arg2 = (double)y;
if (_LIB_VERSION == _SVID_)
exc.retval = x;
else
exc.retval = 0.0/0.0;
if (_LIB_VERSION == _POSIX_)
errno = EDOM;
else if (!matherr(&exc)) {
errno = EDOM;
}
if (exc.err != 0)
errno = exc.err;
return (float)exc.retval;
} else
return z;
#endif
}
 
#ifdef _DOUBLE_IS_32BITS
 
#ifdef __STDC__
double fmod(double x, double y)
#else
double fmod(x,y)
double x,y;
#endif
{
return (double) fmodf((float) x, (float) y);
}
 
#endif /* defined(_DOUBLE_IS_32BITS) */
/programs/develop/libraries/newlib/math/wf_gamma.c
0,0 → 1,93
/* wf_gamma.c -- float version of w_gamma.c.
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
*/
 
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*
*/
 
#include "fdlibm.h"
#include <reent.h>
#include <errno.h>
 
#ifdef __STDC__
float gammaf(float x)
#else
float gammaf(x)
float x;
#endif
{
#ifdef _IEEE_LIBM
return __ieee754_gammaf_r(x,&(_REENT_SIGNGAM(_REENT)));
#else
float y;
struct exception exc;
y = __ieee754_gammaf_r(x,&(_REENT_SIGNGAM(_REENT)));
if(_LIB_VERSION == _IEEE_) return y;
if(!finitef(y)&&finitef(x)) {
#ifndef HUGE_VAL
#define HUGE_VAL inf
double inf = 0.0;
 
SET_HIGH_WORD(inf,0x7ff00000); /* set inf to infinite */
#endif
if(floorf(x)==x&&x<=(float)0.0) {
/* gammaf(-integer) or gammaf(0) */
exc.type = SING;
exc.name = "gammaf";
exc.err = 0;
exc.arg1 = exc.arg2 = (double)x;
if (_LIB_VERSION == _SVID_)
exc.retval = HUGE;
else
exc.retval = HUGE_VAL;
if (_LIB_VERSION == _POSIX_)
errno = EDOM;
else if (!matherr(&exc)) {
errno = EDOM;
}
} else {
/* gammaf(finite) overflow */
exc.type = OVERFLOW;
exc.name = "gammaf";
exc.err = 0;
exc.arg1 = exc.arg2 = (double)x;
if (_LIB_VERSION == _SVID_)
exc.retval = HUGE;
else
exc.retval = HUGE_VAL;
if (_LIB_VERSION == _POSIX_)
errno = ERANGE;
else if (!matherr(&exc)) {
errno = ERANGE;
}
}
if (exc.err != 0)
errno = exc.err;
return (float)exc.retval;
} else
return y;
#endif
}
 
#ifdef _DOUBLE_IS_32BITS
 
#ifdef __STDC__
double gamma(double x)
#else
double gamma(x)
double x;
#endif
{
return (double) gammaf((float) x);
}
 
#endif /* defined(_DOUBLE_IS_32BITS) */
/programs/develop/libraries/newlib/math/wf_hypot.c
0,0 → 1,79
/* wf_hypot.c -- float version of w_hypot.c.
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
*/
 
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
/*
* wrapper hypotf(x,y)
*/
 
#include "fdlibm.h"
#include <errno.h>
 
#ifdef __STDC__
float hypotf(float x, float y) /* wrapper hypotf */
#else
float hypotf(x,y) /* wrapper hypotf */
float x,y;
#endif
{
#ifdef _IEEE_LIBM
return __ieee754_hypotf(x,y);
#else
float z;
struct exception exc;
z = __ieee754_hypotf(x,y);
if(_LIB_VERSION == _IEEE_) return z;
if((!finitef(z))&&finitef(x)&&finitef(y)) {
/* hypotf(finite,finite) overflow */
#ifndef HUGE_VAL
#define HUGE_VAL inf
double inf = 0.0;
 
SET_HIGH_WORD(inf,0x7ff00000); /* set inf to infinite */
#endif
exc.type = OVERFLOW;
exc.name = "hypotf";
exc.err = 0;
exc.arg1 = (double)x;
exc.arg2 = (double)y;
if (_LIB_VERSION == _SVID_)
exc.retval = HUGE;
else
exc.retval = HUGE_VAL;
if (_LIB_VERSION == _POSIX_)
errno = ERANGE;
else if (!matherr(&exc)) {
errno = ERANGE;
}
if (exc.err != 0)
errno = exc.err;
return (float)exc.retval;
} else
return z;
#endif
}
 
#ifdef _DOUBLE_IS_32BITS
 
#ifdef __STDC__
double hypot(double x, double y)
#else
double hypot(x,y)
double x,y;
#endif
{
return (double) hypotf((float) x, (float) y);
}
 
#endif /* defined(_DOUBLE_IS_32BITS) */
/programs/develop/libraries/newlib/math/wf_j0.c
0,0 → 1,137
/* wf_j0.c -- float version of w_j0.c.
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
*/
 
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
/*
* wrapper j0f(float x), y0f(float x)
*/
 
#include "fdlibm.h"
#include <errno.h>
 
#ifdef __STDC__
float j0f(float x) /* wrapper j0f */
#else
float j0f(x) /* wrapper j0f */
float x;
#endif
{
#ifdef _IEEE_LIBM
return __ieee754_j0f(x);
#else
struct exception exc;
float z = __ieee754_j0f(x);
if(_LIB_VERSION == _IEEE_ || isnan(x)) return z;
if(fabsf(x)>(float)X_TLOSS) {
/* j0f(|x|>X_TLOSS) */
exc.type = TLOSS;
exc.name = "j0f";
exc.err = 0;
exc.arg1 = exc.arg2 = (double)x;
exc.retval = 0.0;
if (_LIB_VERSION == _POSIX_)
errno = ERANGE;
else if (!matherr(&exc)) {
errno = ERANGE;
}
if (exc.err != 0)
errno = exc.err;
return (float)exc.retval;
} else
return z;
#endif
}
 
#ifdef __STDC__
float y0f(float x) /* wrapper y0f */
#else
float y0f(x) /* wrapper y0f */
float x;
#endif
{
#ifdef _IEEE_LIBM
return __ieee754_y0f(x);
#else
float z;
struct exception exc;
z = __ieee754_y0f(x);
if(_LIB_VERSION == _IEEE_ || isnan(x) ) return z;
if(x <= (float)0.0){
#ifndef HUGE_VAL
#define HUGE_VAL inf
double inf = 0.0;
 
SET_HIGH_WORD(inf,0x7ff00000); /* set inf to infinite */
#endif
/* y0f(0) = -inf or y0f(x<0) = NaN */
exc.type = DOMAIN; /* should be SING for IEEE y0f(0) */
exc.name = "y0f";
exc.err = 0;
exc.arg1 = exc.arg2 = (double)x;
if (_LIB_VERSION == _SVID_)
exc.retval = -HUGE;
else
exc.retval = -HUGE_VAL;
if (_LIB_VERSION == _POSIX_)
errno = EDOM;
else if (!matherr(&exc)) {
errno = EDOM;
}
if (exc.err != 0)
errno = exc.err;
return (float)exc.retval;
}
if(x>(float)X_TLOSS) {
/* y0f(x>X_TLOSS) */
exc.type = TLOSS;
exc.name = "y0f";
exc.err = 0;
exc.arg1 = exc.arg2 = (double)x;
exc.retval = 0.0;
if (_LIB_VERSION == _POSIX_)
errno = ERANGE;
else if (!matherr(&exc)) {
errno = ERANGE;
}
if (exc.err != 0)
errno = exc.err;
return (float)exc.retval;
} else
return z;
#endif
}
 
#ifdef _DOUBLE_IS_32BITS
 
#ifdef __STDC__
double j0(double x)
#else
double j0(x)
double x;
#endif
{
return (double) j0f((float) x);
}
 
#ifdef __STDC__
double y0(double x)
#else
double y0(x)
double x;
#endif
{
return (double) y0f((float) x);
}
 
#endif /* defined(_DOUBLE_IS_32BITS) */
/programs/develop/libraries/newlib/math/wf_j1.c
0,0 → 1,139
/* wf_j1.c -- float version of w_j1.c.
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
*/
 
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
/*
* wrapper of j1f,y1f
*/
 
#include "fdlibm.h"
#include <errno.h>
 
 
#ifdef __STDC__
float j1f(float x) /* wrapper j1f */
#else
float j1f(x) /* wrapper j1f */
float x;
#endif
{
#ifdef _IEEE_LIBM
return __ieee754_j1f(x);
#else
float z;
struct exception exc;
z = __ieee754_j1f(x);
if(_LIB_VERSION == _IEEE_ || isnan(x) ) return z;
if(fabsf(x)>(float)X_TLOSS) {
/* j1f(|x|>X_TLOSS) */
exc.type = TLOSS;
exc.name = "j1f";
exc.err = 0;
exc.arg1 = exc.arg2 = (double)x;
exc.retval = 0.0;
if (_LIB_VERSION == _POSIX_)
errno = ERANGE;
else if (!matherr(&exc)) {
errno = ERANGE;
}
if (exc.err != 0)
errno = exc.err;
return exc.retval;
} else
return z;
#endif
}
 
#ifdef __STDC__
float y1f(float x) /* wrapper y1f */
#else
float y1f(x) /* wrapper y1f */
float x;
#endif
{
#ifdef _IEEE_LIBM
return __ieee754_y1f(x);
#else
float z;
struct exception exc;
z = __ieee754_y1f(x);
if(_LIB_VERSION == _IEEE_ || isnan(x) ) return z;
if(x <= (float)0.0){
/* y1f(0) = -inf or y1f(x<0) = NaN */
#ifndef HUGE_VAL
#define HUGE_VAL inf
double inf = 0.0;
 
SET_HIGH_WORD(inf,0x7ff00000); /* set inf to infinite */
#endif
exc.type = DOMAIN; /* should be SING for IEEE */
exc.name = "y1f";
exc.err = 0;
exc.arg1 = exc.arg2 = (double)x;
if (_LIB_VERSION == _SVID_)
exc.retval = -HUGE;
else
exc.retval = -HUGE_VAL;
if (_LIB_VERSION == _POSIX_)
errno = EDOM;
else if (!matherr(&exc)) {
errno = EDOM;
}
if (exc.err != 0)
errno = exc.err;
return (float)exc.retval;
}
if(x>(float)X_TLOSS) {
/* y1f(x>X_TLOSS) */
exc.type = TLOSS;
exc.name = "y1f";
exc.err = 0;
exc.arg1 = exc.arg2 = (double)x;
exc.retval = 0.0;
if (_LIB_VERSION == _POSIX_)
errno = ERANGE;
else if (!matherr(&exc)) {
errno = ERANGE;
}
if (exc.err != 0)
errno = exc.err;
return (float)exc.retval;
} else
return z;
#endif
}
 
#ifdef _DOUBLE_IS_32BITS
 
#ifdef __STDC__
double j1(double x)
#else
double j1(x)
double x;
#endif
{
return (double) j1f((float) x);
}
 
#ifdef __STDC__
double y1(double x)
#else
double y1(x)
double x;
#endif
{
return (double) y1f((float) x);
}
 
#endif /* defined(_DOUBLE_IS_32BITS) */
/programs/develop/libraries/newlib/math/wf_jn.c
0,0 → 1,138
/* wf_jn.c -- float version of w_jn.c.
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
*/
 
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#include "fdlibm.h"
#include <errno.h>
 
 
#ifdef __STDC__
float jnf(int n, float x) /* wrapper jnf */
#else
float jnf(n,x) /* wrapper jnf */
float x; int n;
#endif
{
#ifdef _IEEE_LIBM
return __ieee754_jnf(n,x);
#else
float z;
struct exception exc;
z = __ieee754_jnf(n,x);
if(_LIB_VERSION == _IEEE_ || isnan(x) ) return z;
if(fabsf(x)>(float)X_TLOSS) {
/* jnf(|x|>X_TLOSS) */
exc.type = TLOSS;
exc.name = "jnf";
exc.err = 0;
exc.arg1 = (double)n;
exc.arg2 = (double)x;
exc.retval = 0.0;
if (_LIB_VERSION == _POSIX_)
errno = ERANGE;
else if (!matherr(&exc)) {
errno = ERANGE;
}
if (exc.err != 0)
errno = exc.err;
return exc.retval;
} else
return z;
#endif
}
 
#ifdef __STDC__
float ynf(int n, float x) /* wrapper ynf */
#else
float ynf(n,x) /* wrapper ynf */
float x; int n;
#endif
{
#ifdef _IEEE_LIBM
return __ieee754_ynf(n,x);
#else
float z;
struct exception exc;
z = __ieee754_ynf(n,x);
if(_LIB_VERSION == _IEEE_ || isnan(x) ) return z;
if(x <= (float)0.0){
/* ynf(n,0) = -inf or ynf(x<0) = NaN */
#ifndef HUGE_VAL
#define HUGE_VAL inf
double inf = 0.0;
 
SET_HIGH_WORD(inf,0x7ff00000); /* set inf to infinite */
#endif
exc.type = DOMAIN; /* should be SING for IEEE */
exc.name = "ynf";
exc.err = 0;
exc.arg1 = (double)n;
exc.arg2 = (double)x;
if (_LIB_VERSION == _SVID_)
exc.retval = -HUGE;
else
exc.retval = -HUGE_VAL;
if (_LIB_VERSION == _POSIX_)
errno = EDOM;
else if (!matherr(&exc)) {
errno = EDOM;
}
if (exc.err != 0)
errno = exc.err;
return (float)exc.retval;
}
if(x>(float)X_TLOSS) {
/* ynf(x>X_TLOSS) */
exc.type = TLOSS;
exc.name = "ynf";
exc.err = 0;
exc.arg1 = (double)n;
exc.arg2 = (double)x;
exc.retval = 0.0;
if (_LIB_VERSION == _POSIX_)
errno = ERANGE;
else if (!matherr(&exc)) {
errno = ERANGE;
}
if (exc.err != 0)
errno = exc.err;
return (float)exc.retval;
} else
return z;
#endif
}
 
#ifdef _DOUBLE_IS_32BITS
 
#ifdef __STDC__
double jn(int n, double x)
#else
double jn(n,x)
double x; int n;
#endif
{
return (double) jnf(n, (float) x);
}
 
#ifdef __STDC__
double yn(int n, double x)
#else
double yn(n,x)
double x; int n;
#endif
{
return (double) ynf(n, (float) x);
}
 
#endif /* defined(_DOUBLE_IS_32BITS) */
/programs/develop/libraries/newlib/math/wf_lgamma.c
0,0 → 1,87
/* wf_lgamma.c -- float version of w_lgamma.c.
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
*/
 
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*
*/
 
#include "fdlibm.h"
#include <reent.h>
#include <errno.h>
 
#ifdef __STDC__
float lgammaf(float x)
#else
float lgammaf(x)
float x;
#endif
{
#ifdef _IEEE_LIBM
return __ieee754_lgammaf_r(x,&(_REENT_SIGNGAM(_REENT)));
#else
float y;
struct exception exc;
y = __ieee754_lgammaf_r(x,&(_REENT_SIGNGAM(_REENT)));
if(_LIB_VERSION == _IEEE_) return y;
if(!finitef(y)&&finitef(x)) {
#ifndef HUGE_VAL
#define HUGE_VAL inf
double inf = 0.0;
 
SET_HIGH_WORD(inf,0x7ff00000); /* set inf to infinite */
#endif
exc.name = "lgammaf";
exc.err = 0;
exc.arg1 = exc.arg2 = (double)x;
if (_LIB_VERSION == _SVID_)
exc.retval = HUGE;
else
exc.retval = HUGE_VAL;
if(floorf(x)==x&&x<=(float)0.0) {
/* lgammaf(-integer) */
exc.type = SING;
if (_LIB_VERSION == _POSIX_)
errno = EDOM;
else if (!matherr(&exc)) {
errno = EDOM;
}
 
} else {
/* lgammaf(finite) overflow */
exc.type = OVERFLOW;
if (_LIB_VERSION == _POSIX_)
errno = ERANGE;
else if (!matherr(&exc)) {
errno = ERANGE;
}
}
if (exc.err != 0)
errno = exc.err;
return (float)exc.retval;
} else
return y;
#endif
}
 
#ifdef _DOUBLE_IS_32BITS
 
#ifdef __STDC__
double lgamma(double x)
#else
double lgamma(x)
double x;
#endif
{
return (double) lgammaf((float) x);
}
 
#endif /* defined(_DOUBLE_IS_32BITS) */
/programs/develop/libraries/newlib/math/wf_log.c
0,0 → 1,86
/* wf_log.c -- float version of w_log.c.
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
*/
 
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
/*
* wrapper logf(x)
*/
 
#include "fdlibm.h"
#include <errno.h>
 
#ifdef __STDC__
float logf(float x) /* wrapper logf */
#else
float logf(x) /* wrapper logf */
float x;
#endif
{
#ifdef _IEEE_LIBM
return __ieee754_logf(x);
#else
float z;
struct exception exc;
z = __ieee754_logf(x);
if(_LIB_VERSION == _IEEE_ || isnan(x) || x > (float)0.0) return z;
#ifndef HUGE_VAL
#define HUGE_VAL inf
double inf = 0.0;
 
SET_HIGH_WORD(inf,0x7ff00000); /* set inf to infinite */
#endif
exc.name = "logf";
exc.err = 0;
exc.arg1 = exc.arg2 = (double)x;
if (_LIB_VERSION == _SVID_)
exc.retval = -HUGE;
else
exc.retval = -HUGE_VAL;
if(x==(float)0.0) {
/* logf(0) */
exc.type = SING;
if (_LIB_VERSION == _POSIX_)
errno = ERANGE;
else if (!matherr(&exc)) {
errno = ERANGE;
}
} else {
/* logf(x<0) */
exc.type = DOMAIN;
if (_LIB_VERSION == _POSIX_)
errno = EDOM;
else if (!matherr(&exc)) {
errno = EDOM;
}
exc.retval = nan("");
}
if (exc.err != 0)
errno = exc.err;
return (float)exc.retval;
#endif
}
 
#ifdef _DOUBLE_IS_32BITS
 
#ifdef __STDC__
double log(double x)
#else
double log(x)
double x;
#endif
{
return (double) logf((float) x);
}
 
#endif /* defined(_DOUBLE_IS_32BITS) */
/programs/develop/libraries/newlib/math/wf_log10.c
0,0 → 1,89
/* wf_log10.c -- float version of w_log10.c.
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
*/
 
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
/*
* wrapper log10f(X)
*/
 
#include "fdlibm.h"
#include <errno.h>
 
#ifdef __STDC__
float log10f(float x) /* wrapper log10f */
#else
float log10f(x) /* wrapper log10f */
float x;
#endif
{
#ifdef _IEEE_LIBM
return __ieee754_log10f(x);
#else
float z;
struct exception exc;
z = __ieee754_log10f(x);
if(_LIB_VERSION == _IEEE_ || isnan(x)) return z;
if(x<=(float)0.0) {
#ifndef HUGE_VAL
#define HUGE_VAL inf
double inf = 0.0;
 
SET_HIGH_WORD(inf,0x7ff00000); /* set inf to infinite */
#endif
exc.name = "log10f";
exc.err = 0;
exc.arg1 = exc.arg2 = (double)x;
if (_LIB_VERSION == _SVID_)
exc.retval = -HUGE;
else
exc.retval = -HUGE_VAL;
if(x==(float)0.0) {
/* log10f(0) */
exc.type = SING;
if (_LIB_VERSION == _POSIX_)
errno = ERANGE;
else if (!matherr(&exc)) {
errno = ERANGE;
}
} else {
/* log10f(x<0) */
exc.type = DOMAIN;
if (_LIB_VERSION == _POSIX_)
errno = EDOM;
else if (!matherr(&exc)) {
errno = EDOM;
}
exc.retval = nan("");
}
if (exc.err != 0)
errno = exc.err;
return (float)exc.retval;
} else
return z;
#endif
}
 
#ifdef _DOUBLE_IS_32BITS
 
#ifdef __STDC__
double log10(double x)
#else
double log10(x)
double x;
#endif
{
return (double) log10f((float) x);
}
 
#endif /* defined(_DOUBLE_IS_32BITS) */
/programs/develop/libraries/newlib/math/wf_pow.c
0,0 → 1,179
/* wf_pow.c -- float version of w_pow.c.
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
*/
 
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
/*
* wrapper powf(x,y) return x**y
*/
 
#include "fdlibm.h"
#include <errno.h>
 
#ifdef __STDC__
float powf(float x, float y) /* wrapper powf */
#else
float powf(x,y) /* wrapper powf */
float x,y;
#endif
{
#ifdef _IEEE_LIBM
return __ieee754_powf(x,y);
#else
float z;
struct exception exc;
z=__ieee754_powf(x,y);
if(_LIB_VERSION == _IEEE_|| isnan(y)) return z;
if(isnan(x)) {
if(y==(float)0.0) {
/* powf(NaN,0.0) */
/* error only if _LIB_VERSION == _SVID_ & _XOPEN_ */
exc.type = DOMAIN;
exc.name = "powf";
exc.err = 0;
exc.arg1 = (double)x;
exc.arg2 = (double)y;
exc.retval = 1.0;
if (_LIB_VERSION == _IEEE_ ||
_LIB_VERSION == _POSIX_) exc.retval = 1.0;
else if (!matherr(&exc)) {
errno = EDOM;
}
if (exc.err != 0)
errno = exc.err;
return (float)exc.retval;
} else
return z;
}
if(x==(float)0.0){
if(y==(float)0.0) {
/* powf(0.0,0.0) */
/* error only if _LIB_VERSION == _SVID_ */
exc.type = DOMAIN;
exc.name = "powf";
exc.err = 0;
exc.arg1 = (double)x;
exc.arg2 = (double)y;
exc.retval = 0.0;
if (_LIB_VERSION != _SVID_) exc.retval = 1.0;
else if (!matherr(&exc)) {
errno = EDOM;
}
if (exc.err != 0)
errno = exc.err;
return (float)exc.retval;
}
if(finitef(y)&&y<(float)0.0) {
/* 0**neg */
exc.type = DOMAIN;
exc.name = "powf";
exc.err = 0;
exc.arg1 = (double)x;
exc.arg2 = (double)y;
if (_LIB_VERSION == _SVID_)
exc.retval = 0.0;
else
exc.retval = -HUGE_VAL;
if (_LIB_VERSION == _POSIX_)
errno = EDOM;
else if (!matherr(&exc)) {
errno = EDOM;
}
if (exc.err != 0)
errno = exc.err;
return (float)exc.retval;
}
return z;
}
if(!finitef(z)) {
if(finitef(x)&&finitef(y)) {
if(isnan(z)) {
/* neg**non-integral */
exc.type = DOMAIN;
exc.name = "powf";
exc.err = 0;
exc.arg1 = (double)x;
exc.arg2 = (double)y;
if (_LIB_VERSION == _SVID_)
exc.retval = 0.0;
else
exc.retval = 0.0/0.0; /* X/Open allow NaN */
if (_LIB_VERSION == _POSIX_)
errno = EDOM;
else if (!matherr(&exc)) {
errno = EDOM;
}
if (exc.err != 0)
errno = exc.err;
return (float)exc.retval;
} else {
/* powf(x,y) overflow */
exc.type = OVERFLOW;
exc.name = "powf";
exc.err = 0;
exc.arg1 = (double)x;
exc.arg2 = (double)y;
if (_LIB_VERSION == _SVID_) {
exc.retval = HUGE;
y *= 0.5;
if(x<0.0&&rint(y)!=y) exc.retval = -HUGE;
} else {
exc.retval = HUGE_VAL;
y *= 0.5;
if(x<0.0&&rint(y)!=y) exc.retval = -HUGE_VAL;
}
if (_LIB_VERSION == _POSIX_)
errno = ERANGE;
else if (!matherr(&exc)) {
errno = ERANGE;
}
if (exc.err != 0)
errno = exc.err;
return (float)exc.retval;
}
}
}
if(z==(float)0.0&&finitef(x)&&finitef(y)) {
/* powf(x,y) underflow */
exc.type = UNDERFLOW;
exc.name = "powf";
exc.err = 0;
exc.arg1 = (double)x;
exc.arg2 = (double)y;
exc.retval = 0.0;
if (_LIB_VERSION == _POSIX_)
errno = ERANGE;
else if (!matherr(&exc)) {
errno = ERANGE;
}
if (exc.err != 0)
errno = exc.err;
return (float)exc.retval;
}
return z;
#endif
}
 
#ifdef _DOUBLE_IS_32BITS
 
#ifdef __STDC__
double pow(double x, double y)
#else
double pow(x,y)
double x,y;
#endif
{
return (double) powf((float) x, (float) y);
}
 
#endif /* defined(_DOUBLE_IS_32BITS) */
/programs/develop/libraries/newlib/math/wf_remainder.c
0,0 → 1,74
/* wf_remainder.c -- float version of w_remainder.c.
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
*/
 
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
/*
* wrapper remainderf(x,p)
*/
 
#include "fdlibm.h"
#include <errno.h>
 
#ifdef __STDC__
float remainderf(float x, float y) /* wrapper remainder */
#else
float remainderf(x,y) /* wrapper remainder */
float x,y;
#endif
{
#ifdef _IEEE_LIBM
return __ieee754_remainderf(x,y);
#else
float z;
struct exception exc;
z = __ieee754_remainderf(x,y);
if(_LIB_VERSION == _IEEE_ || isnan(y)) return z;
if(y==(float)0.0) {
/* remainderf(x,0) */
exc.type = DOMAIN;
exc.name = "remainderf";
exc.err = 0;
exc.arg1 = (double)x;
exc.arg2 = (double)y;
exc.retval = 0.0/0.0;
if (_LIB_VERSION == _POSIX_)
errno = EDOM;
else if (!matherr(&exc)) {
errno = EDOM;
}
if (exc.err != 0)
errno = exc.err;
return (float)exc.retval;
} else
return z;
#endif
}
 
#ifdef _DOUBLE_IS_32BITS
 
#ifdef __STDC__
double remainder(double x, double y)
#else
double remainder(x,y)
double x,y;
#endif
{
return (double) remainderf((float) x, (float) y);
}
 
#endif /* defined(_DOUBLE_IS_32BITS) */
 
 
 
 
/programs/develop/libraries/newlib/math/wf_scalb.c
0,0 → 1,118
/* wf_scalb.c -- float version of w_scalb.c.
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
*/
 
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
/*
* wrapper scalbf(float x, float fn) is provide for
* passing various standard test suite. One
* should use scalbn() instead.
*/
 
#include "fdlibm.h"
#include <errno.h>
 
#ifdef __STDC__
#ifdef _SCALB_INT
float scalbf(float x, int fn) /* wrapper scalbf */
#else
float scalbf(float x, float fn) /* wrapper scalbf */
#endif
#else
float scalbf(x,fn) /* wrapper scalbf */
#ifdef _SCALB_INT
float x; int fn;
#else
float x,fn;
#endif
#endif
{
#ifdef _IEEE_LIBM
return __ieee754_scalbf(x,fn);
#else
float z;
#ifndef HUGE_VAL
#define HUGE_VAL inf
double inf = 0.0;
 
SET_HIGH_WORD(inf,0x7ff00000); /* set inf to infinite */
#endif
struct exception exc;
z = __ieee754_scalbf(x,fn);
if(_LIB_VERSION == _IEEE_) return z;
if(!(finitef(z)||isnan(z))&&finitef(x)) {
/* scalbf overflow; SVID also returns +-HUGE_VAL */
exc.type = OVERFLOW;
exc.name = "scalbf";
exc.err = 0;
exc.arg1 = (double)x;
exc.arg2 = (double)fn;
exc.retval = x > 0.0 ? HUGE_VAL : -HUGE_VAL;
if (_LIB_VERSION == _POSIX_)
errno = ERANGE;
else if (!matherr(&exc)) {
errno = ERANGE;
}
if (exc.err != 0)
errno = exc.err;
return exc.retval;
}
if(z==(float)0.0&&z!=x) {
/* scalbf underflow */
exc.type = UNDERFLOW;
exc.name = "scalbf";
exc.err = 0;
exc.arg1 = (double)x;
exc.arg2 = (double)fn;
exc.retval = copysign(0.0,x);
if (_LIB_VERSION == _POSIX_)
errno = ERANGE;
else if (!matherr(&exc)) {
errno = ERANGE;
}
if (exc.err != 0)
errno = exc.err;
return exc.retval;
}
#ifndef _SCALB_INT
if(!finitef(fn)) errno = ERANGE;
#endif
return z;
#endif
}
 
#ifdef _DOUBLE_IS_32BITS
 
#ifdef __STDC__
#ifdef _SCALB_INT
double scalb(double x, int fn)
#else
double scalb(double x, double fn)
#endif
#else
double scalb(x, fn)
#ifdef _SCALB_INT
double x; int fn;
#else
double x,fn;
#endif
#endif
{
#ifdef _SCALB_INT
return (double) scalbf((float) x, fn);
#else
return (double) scalbf((float) x, (float) fn);
#endif
}
 
#endif /* defined(_DOUBLE_IS_32BITS) */
/programs/develop/libraries/newlib/math/wf_sincos.c
0,0 → 1,33
/* sincos -- currently no more efficient than two separate calls to
sin and cos. */
#include "fdlibm.h"
#include <errno.h>
 
#ifdef __STDC__
void sincosf(float x, float *sinx, float *cosx)
#else
void sincosf(x, sinx, cosx)
float x;
float *sinx;
float *cosx;
#endif
{
*sinx = sinf (x);
*cosx = cosf (x);
}
 
#ifdef _DOUBLE_IS_32BITS
 
#ifdef __STDC__
void sincos(double x, double *sinx, double *cosx)
#else
void sincos(x, sinx, cosx)
double x;
double sinx;
double cosx;
#endif
{
*sinx = sinf((float) x);
*cosx = cosf((float) x);
}
#endif /* defined(_DOUBLE_IS_32BITS) */
/programs/develop/libraries/newlib/math/wf_sinh.c
0,0 → 1,78
/* wf_sinh.c -- float version of w_sinh.c.
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
*/
 
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
/*
* wrapper sinhf(x)
*/
 
#include "fdlibm.h"
#include <errno.h>
 
#ifdef __STDC__
float sinhf(float x) /* wrapper sinhf */
#else
float sinhf(x) /* wrapper sinhf */
float x;
#endif
{
#ifdef _IEEE_LIBM
return __ieee754_sinhf(x);
#else
float z;
struct exception exc;
z = __ieee754_sinhf(x);
if(_LIB_VERSION == _IEEE_) return z;
if(!finitef(z)&&finitef(x)) {
/* sinhf(finite) overflow */
#ifndef HUGE_VAL
#define HUGE_VAL inf
double inf = 0.0;
SET_HIGH_WORD(inf,0x7ff00000); /* set inf to infinite */
#endif
exc.type = OVERFLOW;
exc.name = "sinhf";
exc.err = 0;
exc.arg1 = exc.arg2 = (double)x;
if (_LIB_VERSION == _SVID_)
exc.retval = ( (x>0.0) ? HUGE : -HUGE);
else
exc.retval = ( (x>0.0) ? HUGE_VAL : -HUGE_VAL);
if (_LIB_VERSION == _POSIX_)
errno = ERANGE;
else if (!matherr(&exc)) {
errno = ERANGE;
}
if (exc.err != 0)
errno = exc.err;
return (float)exc.retval;
} else
return z;
#endif
}
 
#ifdef _DOUBLE_IS_32BITS
 
#ifdef __STDC__
double sinh(double x)
#else
double sinh(x)
double x;
#endif
{
return (double) sinhf((float) x);
}
 
#endif /* defined(_DOUBLE_IS_32BITS) */
/programs/develop/libraries/newlib/math/wf_sqrt.c
0,0 → 1,72
/* wf_sqrt.c -- float version of w_sqrt.c.
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
*/
 
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
/*
* wrapper sqrtf(x)
*/
 
#include "fdlibm.h"
#include <errno.h>
 
#ifdef __STDC__
float sqrtf(float x) /* wrapper sqrtf */
#else
float sqrtf(x) /* wrapper sqrtf */
float x;
#endif
{
#ifdef _IEEE_LIBM
return __ieee754_sqrtf(x);
#else
float z;
struct exception exc;
z = __ieee754_sqrtf(x);
if(_LIB_VERSION == _IEEE_ || isnan(x)) return z;
if(x<(float)0.0) {
/* sqrtf(negative) */
exc.type = DOMAIN;
exc.name = "sqrtf";
exc.err = 0;
exc.arg1 = exc.arg2 = (double)x;
if (_LIB_VERSION == _SVID_)
exc.retval = 0.0;
else
exc.retval = 0.0/0.0;
if (_LIB_VERSION == _POSIX_)
errno = EDOM;
else if (!matherr(&exc)) {
errno = EDOM;
}
if (exc.err != 0)
errno = exc.err;
return (float)exc.retval;
} else
return z;
#endif
}
 
#ifdef _DOUBLE_IS_32BITS
 
#ifdef __STDC__
double sqrt(double x)
#else
double sqrt(x)
double x;
#endif
{
return (double) sqrtf((float) x);
}
 
#endif /* defined(_DOUBLE_IS_32BITS) */
/programs/develop/libraries/newlib/math/wf_tgamma.c
0,0 → 1,59
/* w_gammaf.c -- float version of w_gamma.c.
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
*/
 
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
#include "math.h"
#include "fdlibm.h"
 
#ifdef __STDC__
float tgammaf(float x)
#else
float tgammaf(x)
float x;
#endif
{
float y;
int local_signgam;
y = __ieee754_gammaf_r(x,&local_signgam);
if (local_signgam < 0) y = -y;
#ifdef _IEEE_LIBM
return y;
#else
if(_LIB_VERSION == _IEEE_) return y;
 
if(!finitef(y)&&finitef(x)) {
if(floorf(x)==x&&x<=(float)0.0)
/* tgammaf pole */
return (float)__kernel_standard((double)x,(double)x,141);
else
/* tgammaf overflow */
return (float)__kernel_standard((double)x,(double)x,140);
}
return y;
#endif
}
 
#ifdef _DOUBLE_IS_32BITS
 
#ifdef __STDC__
double tgamma(double x)
#else
double tgamma(x)
double x;
#endif
{
return (double) tgammaf((float) x);
}
 
#endif /* defined(_DOUBLE_IS_32BITS) */
/programs/develop/libraries/newlib/math/wr_gamma.c
0,0 → 1,76
 
/* @(#)wr_gamma.c 5.1 93/09/24 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
/*
* wrapper double gamma_r(double x, int *signgamp)
*/
 
#include "fdlibm.h"
#include <errno.h>
 
#ifndef _DOUBLE_IS_32BITS
 
#ifdef __STDC__
double gamma_r(double x, int *signgamp) /* wrapper lgamma_r */
#else
double gamma_r(x,signgamp) /* wrapper lgamma_r */
double x; int *signgamp;
#endif
{
#ifdef _IEEE_LIBM
return __ieee754_gamma_r(x,signgamp);
#else
double y;
struct exception exc;
y = __ieee754_gamma_r(x,signgamp);
if(_LIB_VERSION == _IEEE_) return y;
if(!finite(y)&&finite(x)) {
#ifndef HUGE_VAL
#define HUGE_VAL inf
double inf = 0.0;
 
SET_HIGH_WORD(inf,0x7ff00000); /* set inf to infinite */
#endif
exc.name = "gamma";
exc.err = 0;
exc.arg1 = exc.arg2 = (double)x;
if (_LIB_VERSION == _SVID_)
exc.retval = HUGE;
else
exc.retval = HUGE_VAL;
if(floor(x)==x&&x<=0.0) {
/* gamma(-integer) or gamma(0) */
exc.type = SING;
if (_LIB_VERSION == _POSIX_)
errno = EDOM;
else if (!matherr(&exc)) {
errno = EDOM;
}
} else {
/* gamma(finite) overflow */
exc.type = OVERFLOW;
if (_LIB_VERSION == _POSIX_)
errno = ERANGE;
else if (!matherr(&exc)) {
errno = ERANGE;
}
}
if (exc.err != 0)
errno = exc.err;
return exc.retval;
} else
return y;
#endif
}
 
#endif /* defined(_DOUBLE_IS_32BITS) */
/programs/develop/libraries/newlib/math/wr_lgamma.c
0,0 → 1,77
 
/* @(#)wr_lgamma.c 5.1 93/09/24 */
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
/*
* wrapper double lgamma_r(double x, int *signgamp)
*/
 
#include "fdlibm.h"
#include <errno.h>
 
#ifndef _DOUBLE_IS_32BITS
 
#ifdef __STDC__
double lgamma_r(double x, int *signgamp) /* wrapper lgamma_r */
#else
double lgamma_r(x,signgamp) /* wrapper lgamma_r */
double x; int *signgamp;
#endif
{
#ifdef _IEEE_LIBM
return __ieee754_lgamma_r(x,signgamp);
#else
double y;
struct exception exc;
y = __ieee754_lgamma_r(x,signgamp);
if(_LIB_VERSION == _IEEE_) return y;
if(!finite(y)&&finite(x)) {
#ifndef HUGE_VAL
#define HUGE_VAL inf
double inf = 0.0;
 
SET_HIGH_WORD(inf,0x7ff00000); /* set inf to infinite */
#endif
exc.name = "lgamma";
exc.err = 0;
exc.arg1 = exc.arg2 = (double)x;
if (_LIB_VERSION == _SVID_)
exc.retval = HUGE;
else
exc.retval = HUGE_VAL;
if(floor(x)==x&&x<=0.0) {
/* lgamma(-integer) */
exc.type = SING;
if (_LIB_VERSION == _POSIX_)
errno = EDOM;
else if (!matherr(&exc)) {
errno = EDOM;
}
 
} else {
/* lgamma(finite) overflow */
exc.type = OVERFLOW;
if (_LIB_VERSION == _POSIX_)
errno = ERANGE;
else if (!matherr(&exc)) {
errno = ERANGE;
}
}
if (exc.err != 0)
errno = exc.err;
return exc.retval;
} else
return y;
#endif
}
 
#endif /* defined(_DOUBLE_IS_32BITS) */
/programs/develop/libraries/newlib/math/wrf_gamma.c
0,0 → 1,74
/* wrf_gamma.c -- float version of wr_gamma.c.
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
*/
 
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
/*
* wrapper float gammaf_r(float x, int *signgamp)
*/
 
#include "fdlibm.h"
#include <errno.h>
 
#ifdef __STDC__
float gammaf_r(float x, int *signgamp) /* wrapper lgammaf_r */
#else
float gammaf_r(x,signgamp) /* wrapper lgammaf_r */
float x; int *signgamp;
#endif
{
#ifdef _IEEE_LIBM
return __ieee754_gammaf_r(x,signgamp);
#else
float y;
struct exception exc;
y = __ieee754_gammaf_r(x,signgamp);
if(_LIB_VERSION == _IEEE_) return y;
if(!finitef(y)&&finitef(x)) {
#ifndef HUGE_VAL
#define HUGE_VAL inf
double inf = 0.0;
 
SET_HIGH_WORD(inf,0x7ff00000); /* set inf to infinite */
#endif
exc.name = "gammaf";
exc.err = 0;
exc.arg1 = exc.arg2 = (double)x;
if (_LIB_VERSION == _SVID_)
exc.retval = HUGE;
else
exc.retval = HUGE_VAL;
if(floorf(x)==x&&x<=(float)0.0) {
/* gammaf(-integer) or gamma(0) */
exc.type = SING;
if (_LIB_VERSION == _POSIX_)
errno = EDOM;
else if (!matherr(&exc)) {
errno = EDOM;
}
} else {
/* gammaf(finite) overflow */
exc.type = OVERFLOW;
if (_LIB_VERSION == _POSIX_)
errno = ERANGE;
else if (!matherr(&exc)) {
errno = ERANGE;
}
}
if (exc.err != 0)
errno = exc.err;
return (float)exc.retval;
} else
return y;
#endif
}
/programs/develop/libraries/newlib/math/wrf_lgamma.c
0,0 → 1,75
/* wrf_lgamma.c -- float version of wr_lgamma.c.
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
*/
 
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
 
/*
* wrapper float lgammaf_r(float x, int *signgamp)
*/
 
#include "fdlibm.h"
#include <errno.h>
 
#ifdef __STDC__
float lgammaf_r(float x, int *signgamp) /* wrapper lgammaf_r */
#else
float lgammaf_r(x,signgamp) /* wrapper lgammaf_r */
float x; int *signgamp;
#endif
{
#ifdef _IEEE_LIBM
return __ieee754_lgammaf_r(x,signgamp);
#else
float y;
struct exception exc;
y = __ieee754_lgammaf_r(x,signgamp);
if(_LIB_VERSION == _IEEE_) return y;
if(!finitef(y)&&finitef(x)) {
#ifndef HUGE_VAL
#define HUGE_VAL inf
double inf = 0.0;
 
SET_HIGH_WORD(inf,0x7ff00000); /* set inf to infinite */
#endif
exc.name = "lgammaf";
exc.err = 0;
exc.arg1 = exc.arg2 = (double)x;
if (_LIB_VERSION == _SVID_)
exc.retval = HUGE;
else
exc.retval = HUGE_VAL;
if(floorf(x)==x&&x<=(float)0.0) {
/* lgammaf(-integer) or lgamma(0) */
exc.type = SING;
if (_LIB_VERSION == _POSIX_)
errno = EDOM;
else if (!matherr(&exc)) {
errno = EDOM;
}
 
} else {
/* lgammaf(finite) overflow */
exc.type = OVERFLOW;
if (_LIB_VERSION == _POSIX_)
errno = ERANGE;
else if (!matherr(&exc)) {
errno = ERANGE;
}
}
if (exc.err != 0)
errno = exc.err;
return (float)exc.retval;
} else
return y;
#endif
}
/programs/develop/libraries/newlib/static.lds
33,7 → 33,7
*(.gcc_except_table)
}
 
.rdata ALIGN(16) :
.rdata ALIGN(64) :
{
*(.rdata)
*(SORT(.rdata$*))
43,7 → 43,7
___RUNTIME_PSEUDO_RELOC_LIST_END__ = .;
__RUNTIME_PSEUDO_RELOC_LIST_END__ = .;
}
.CRT ALIGN(16) :
.CRT ALIGN(64) :
{
___crt_xc_start__ = . ;
*(SORT(.CRT$XC*)) /* C initialization */
62,7 → 62,7
___crt_xt_end__ = . ;
}
 
.data ALIGN(16) :
.data ALIGN(64) :
{
__data_start__ = . ;
*(.data)
77,7 → 77,7
}
 
 
bss ALIGN(16):
bss ALIGN(64):
{
*(.bss)
*(COMMON)