acadia-newlib/newlib/libm/math
Joseph S. Myers 5e24839658 Fix spurious underflow exceptions for Bessel functions for double(from glibc bug 14155)
This fix comes from glibc, from files which originated from
	the same place as the newlib files. Those files in glibc carry
	the same license as the newlib files.

Bug 14155 is spurious underflow exceptions from Bessel functions for
large arguments.  (The correct results for large x are roughly
constant * sin or cos (x + constant) / sqrt (x), so no underflow
exceptions should occur based on the final result.)

There are various places underflows may occur in the intermediate
calculations that cause the failures listed in that bug.  This patch
fixes problems for the double version where underflows occur in
calculating the intermediate functions P and Q (in particular, x**-12
gets computed while calculating Q).  Appropriate approximations are
used for P and Q for arguments at least 0x1p28 and above to avoid the
underflows.

For sufficiently large x - 0x1p129 and above - the code already has a
cut-off to avoid calculating P and Q at all, which means the
approximations -0.125 / x and 0.375 / x can't themselves cause
underflows calculating Q.  This cut-off is heuristically reasonable
for the point beyond which Q can be neglected (based on expecting
around 0x1p-64 to be the least absolute value of sin or cos for large
arguments representable in double).

The float versions use a cut-off 0x1p17, which is less heuristically
justifiable but should still only affect values near zeroes of the
Bessel functions where these implementations are intrinsically
inaccurate anyway (bugs 14469-14472), and should serve to avoid
underflows (the float underflow for jn in bug 14155 probably comes
from the recurrence to compute jn).  ldbl-96 uses 0x1p129, which may
not really be enough heuristically (0x1p143 or so might be safer - 143
= 64 + 79, number of mantissa bits plus total number of significant
bits in representation) but again should avoid underflows and only
affect values where the code is substantially inaccurate anyway.
ldbl-128 and ldbl-128ibm share a completely different implementation
with no such cut-off, which I propose to fix separately.

Signed-off-by: Keith Packard <keithp@keithp.com>
2020-03-26 12:21:33 +01:00
..
Makefile.am New expf, exp2f, logf, log2f and powf implementations 2017-10-13 10:58:00 +02:00
Makefile.in makedoc: make errors visible 2017-12-07 11:54:11 +00:00
e_acos.c
e_acosh.c
e_asin.c
e_atan2.c Throughout, run newlib with -Wall -Werror option and fix bugs and 2012-08-08 11:04:18 +00:00
e_atanh.c
e_cosh.c
e_exp.c Fix error in exp in magnitude [2e-32,2e-28] 2020-03-09 10:12:25 +01:00
e_fmod.c
e_hypot.c
e_j0.c Fix spurious underflow exceptions for Bessel functions for double(from glibc bug 14155) 2020-03-26 12:21:33 +01:00
e_j1.c Fix spurious underflow exceptions for Bessel functions for double(from glibc bug 14155) 2020-03-26 12:21:33 +01:00
e_jn.c
e_log.c New log implementation 2018-06-27 15:40:49 +02:00
e_log10.c
e_pow.c pow: fix pow(-1.0, NaN) 2020-02-14 10:12:25 +01:00
e_rem_pio2.c Throughout, run newlib with -Wall -Werror option and fix bugs and 2012-08-08 11:04:18 +00:00
e_remainder.c
e_scalb.c e_scalb.c: Call scalbln instead of scalbn on 16-bit targets to ensure constant fits in an int. 2018-09-03 09:41:23 +02:00
e_sinh.c
e_sqrt.c Avoid unneeded truncation to "int" 2015-05-27 13:30:20 +02:00
ef_acos.c
ef_acosh.c
ef_asin.c
ef_atan2.c
ef_atanh.c
ef_cosh.c
ef_exp.c Fix error in exp in magnitude [2e-32,2e-28] 2020-03-09 10:12:25 +01:00
ef_fmod.c
ef_hypot.c Fix hypotf missing mask in hi+lo decomposition 2020-03-19 16:46:17 +01:00
ef_j0.c Fix spurious underflow exceptions for Bessel functions for double(from glibc bug 14155) 2020-03-26 12:21:33 +01:00
ef_j1.c Fix spurious underflow exceptions for Bessel functions for double(from glibc bug 14155) 2020-03-26 12:21:33 +01:00
ef_jn.c newlib: fix various gcc warnings 2018-08-08 10:50:19 +02:00
ef_log.c New expf, exp2f, logf, log2f and powf implementations 2017-10-13 10:58:00 +02:00
ef_log10.c
ef_pow.c Fix error in powf for (-1.0, NaN) input 2020-03-02 16:46:03 +01:00
ef_rem_pio2.c
ef_remainder.c
ef_scalb.c 2009-07-09 Craig Howland <howland@LGSInnovations.com> 2009-07-09 17:04:56 +00:00
ef_sinh.c
ef_sqrt.c * libm/math/ef_sqrt.c: Delete unused variable sign. 2010-03-05 08:55:16 +00:00
el_hypot.c * libc/include/complex.h (cabsl): Add prototype. 2015-02-06 16:14:04 +00:00
er_gamma.c
er_lgamma.c Throughout, run newlib with -Wall -Werror option and fix bugs and 2012-08-08 11:04:18 +00:00
erf_gamma.c
erf_lgamma.c Throughout, run newlib with -Wall -Werror option and fix bugs and 2012-08-08 11:04:18 +00:00
k_cos.c
k_rem_pio2.c newlib: fix various gcc warnings 2018-08-08 10:50:19 +02:00
k_sin.c
k_standard.c Remove HUGE_VAL definition from libm math functions 2019-01-23 10:46:30 +01:00
k_tan.c Fix for k_tan.c specific inputs 2020-03-18 10:05:11 +01:00
kf_cos.c
kf_rem_pio2.c Fix error in float trig. function range reduction 2020-03-03 16:45:22 +01:00
kf_sin.c
kf_tan.c
math.tex Remove matherr, and SVID and X/Open math library configurations 2019-01-23 10:46:24 +01:00
s_asinh.c math: remove TRAD_SYNOPSIS 2017-12-01 03:41:53 -06:00
s_atan.c math: remove TRAD_SYNOPSIS 2017-12-01 03:41:53 -06:00
s_ceil.c
s_cos.c
s_erf.c math: remove TRAD_SYNOPSIS 2017-12-01 03:41:53 -06:00
s_fabs.c math: remove TRAD_SYNOPSIS 2017-12-01 03:41:53 -06:00
s_floor.c math: remove TRAD_SYNOPSIS 2017-12-01 03:41:53 -06:00
s_frexp.c math: remove TRAD_SYNOPSIS 2017-12-01 03:41:53 -06:00
s_ldexp.c math: remove TRAD_SYNOPSIS 2017-12-01 03:41:53 -06:00
s_signif.c
s_sin.c math: remove TRAD_SYNOPSIS 2017-12-01 03:41:53 -06:00
s_tan.c math: remove TRAD_SYNOPSIS 2017-12-01 03:41:53 -06:00
s_tanh.c math: remove TRAD_SYNOPSIS 2017-12-01 03:41:53 -06:00
sf_asinh.c
sf_atan.c
sf_ceil.c
sf_cos.c Remove unused variable 'one' from sf_cos.c 2018-08-29 15:57:27 +02:00
sf_erf.c
sf_fabs.c
sf_floor.c
sf_frexp.c
sf_ldexp.c
sf_signif.c
sf_sin.c Improve performance of sinf/cosf/sincosf 2018-06-21 09:37:04 +02:00
sf_tan.c
sf_tanh.c
w_acos.c Remove matherr, and SVID and X/Open math library configurations 2019-01-23 10:46:24 +01:00
w_acosh.c Remove matherr, and SVID and X/Open math library configurations 2019-01-23 10:46:24 +01:00
w_asin.c Remove matherr, and SVID and X/Open math library configurations 2019-01-23 10:46:24 +01:00
w_atan2.c Remove matherr, and SVID and X/Open math library configurations 2019-01-23 10:46:24 +01:00
w_atanh.c Remove matherr, and SVID and X/Open math library configurations 2019-01-23 10:46:24 +01:00
w_cosh.c Remove HUGE_VAL definition from libm math functions 2019-01-23 10:46:30 +01:00
w_drem.c
w_exp.c Remove HUGE_VAL definition from libm math functions 2019-01-23 10:46:30 +01:00
w_exp2.c Remove matherr, and SVID and X/Open math library configurations 2019-01-23 10:46:24 +01:00
w_fmod.c Remove matherr, and SVID and X/Open math library configurations 2019-01-23 10:46:24 +01:00
w_gamma.c Remove HUGE_VAL definition from libm math functions 2019-01-23 10:46:30 +01:00
w_hypot.c Remove HUGE_VAL definition from libm math functions 2019-01-23 10:46:30 +01:00
w_j0.c Remove HUGE_VAL definition from libm math functions 2019-01-23 10:46:30 +01:00
w_j1.c Remove HUGE_VAL definition from libm math functions 2019-01-23 10:46:30 +01:00
w_jn.c Remove HUGE_VAL definition from libm math functions 2019-01-23 10:46:30 +01:00
w_lgamma.c Remove HUGE_VAL definition from libm math functions 2019-01-23 10:46:30 +01:00
w_log.c Remove HUGE_VAL definition from libm math functions 2019-01-23 10:46:30 +01:00
w_log10.c Remove HUGE_VAL definition from libm math functions 2019-01-23 10:46:30 +01:00
w_pow.c Remove HUGE_VAL definition from libm math functions 2019-01-23 10:46:30 +01:00
w_remainder.c Remove matherr, and SVID and X/Open math library configurations 2019-01-23 10:46:24 +01:00
w_scalb.c Remove HUGE_VAL definition from libm math functions 2019-01-23 10:46:30 +01:00
w_sincos.c
w_sinh.c Remove HUGE_VAL definition from libm math functions 2019-01-23 10:46:30 +01:00
w_sqrt.c Remove matherr, and SVID and X/Open math library configurations 2019-01-23 10:46:24 +01:00
w_tgamma.c 2011-01-12 Ralf Corsépius <ralf.corsepius@rtems.org> 2011-01-12 22:25:15 +00:00
wf_acos.c Use nanf() instead of nan() in single-precision float libm math functions 2019-01-23 10:46:30 +01:00
wf_acosh.c Remove matherr, and SVID and X/Open math library configurations 2019-01-23 10:46:24 +01:00
wf_asin.c Use nanf() instead of nan() in single-precision float libm math functions 2019-01-23 10:46:30 +01:00
wf_atan2.c
wf_atanh.c Remove matherr, and SVID and X/Open math library configurations 2019-01-23 10:46:24 +01:00
wf_cosh.c Use HUGE_VALF instead of HUGE_VAL in single-precision float libm math functions 2019-01-23 10:46:30 +01:00
wf_drem.c
wf_exp.c Use HUGE_VALF instead of HUGE_VAL in single-precision float libm math functions 2019-01-23 10:46:30 +01:00
wf_exp2.c New expf, exp2f, logf, log2f and powf implementations 2017-10-13 10:58:00 +02:00
wf_fmod.c Remove matherr, and SVID and X/Open math library configurations 2019-01-23 10:46:24 +01:00
wf_gamma.c Use HUGE_VALF instead of HUGE_VAL in single-precision float libm math functions 2019-01-23 10:46:30 +01:00
wf_hypot.c Use HUGE_VALF instead of HUGE_VAL in single-precision float libm math functions 2019-01-23 10:46:30 +01:00
wf_j0.c Use HUGE_VALF instead of HUGE_VAL in single-precision float libm math functions 2019-01-23 10:46:30 +01:00
wf_j1.c Use HUGE_VALF instead of HUGE_VAL in single-precision float libm math functions 2019-01-23 10:46:30 +01:00
wf_jn.c Use HUGE_VALF instead of HUGE_VAL in single-precision float libm math functions 2019-01-23 10:46:30 +01:00
wf_lgamma.c Use HUGE_VALF instead of HUGE_VAL in single-precision float libm math functions 2019-01-23 10:46:30 +01:00
wf_log.c Use nanf() instead of nan() in single-precision float libm math functions 2019-01-23 10:46:30 +01:00
wf_log2.c New expf, exp2f, logf, log2f and powf implementations 2017-10-13 10:58:00 +02:00
wf_log10.c Use nanf() instead of nan() in single-precision float libm math functions 2019-01-23 10:46:30 +01:00
wf_pow.c Use HUGE_VALF instead of HUGE_VAL in single-precision float libm math functions 2019-01-23 10:46:30 +01:00
wf_remainder.c Remove matherr, and SVID and X/Open math library configurations 2019-01-23 10:46:24 +01:00
wf_scalb.c Use HUGE_VALF instead of HUGE_VAL in single-precision float libm math functions 2019-01-23 10:46:30 +01:00
wf_sincos.c Improve performance of sinf/cosf/sincosf 2018-06-21 09:37:04 +02:00
wf_sinh.c Use HUGE_VALF instead of HUGE_VAL in single-precision float libm math functions 2019-01-23 10:46:30 +01:00
wf_sqrt.c Remove matherr, and SVID and X/Open math library configurations 2019-01-23 10:46:24 +01:00
wf_tgamma.c 2011-01-12 Ralf Corsépius <ralf.corsepius@rtems.org> 2011-01-12 22:25:15 +00:00
wr_gamma.c Use HUGE_VALF instead of HUGE_VAL in single-precision float libm math functions 2019-01-23 10:46:30 +01:00
wr_lgamma.c Remove HUGE_VAL definition from libm math functions 2019-01-23 10:46:30 +01:00
wrf_gamma.c Use HUGE_VALF instead of HUGE_VAL in single-precision float libm math functions 2019-01-23 10:46:30 +01:00
wrf_lgamma.c Use HUGE_VALF instead of HUGE_VAL in single-precision float libm math functions 2019-01-23 10:46:30 +01:00