This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Fix exp10 errno setting on underflow (bug 6787)
- From: "Joseph S. Myers" <joseph at codesourcery dot com>
- To: <libc-alpha at sourceware dot org>
- Date: Fri, 29 Nov 2013 01:48:13 +0000
- Subject: Fix exp10 errno setting on underflow (bug 6787)
- Authentication-results: sourceware.org; auth=none
This patch fixes bug 6787, exp10 not setting errno to ERANGE on
underflow to zero, by fixing underflow tests that only checked
__finite on the result to check for a result of 0 as well.
Tested x86_64 and x86.
2013-11-29 Joseph Myers <joseph@codesourcery.com>
[BZ #6787]
* math/w_exp10.c (__exp10): Handle a zero result as underflow.
* math/w_exp10f.c (__exp10f): Likewise.
* math/w_exp10l.c (__exp10l): Likewise.
* math/libm-test.inc (exp10_test_data): Add more tests and expect
errno settings in existing tests.
diff --git a/math/libm-test.inc b/math/libm-test.inc
index 0c88abc..cc2a2c7 100644
--- a/math/libm-test.inc
+++ b/math/libm-test.inc
@@ -8090,10 +8090,12 @@ static const struct test_f_f_data exp10_test_data[] =
TEST_f_f (exp10, 4932, 1.0e4932L),
TEST_f_f (exp10, -4932, 1.0e-4932L, UNDERFLOW_EXCEPTION),
#endif
+ TEST_f_f (exp10, 1e5, plus_infty, OVERFLOW_EXCEPTION|ERRNO_ERANGE),
+ TEST_f_f (exp10, -1e5, 0, UNDERFLOW_EXCEPTION|ERRNO_ERANGE),
TEST_f_f (exp10, 1e6, plus_infty, OVERFLOW_EXCEPTION|ERRNO_ERANGE),
- TEST_f_f (exp10, -1e6, 0, UNDERFLOW_EXCEPTION),
+ TEST_f_f (exp10, -1e6, 0, UNDERFLOW_EXCEPTION|ERRNO_ERANGE),
TEST_f_f (exp10, max_value, plus_infty, OVERFLOW_EXCEPTION|ERRNO_ERANGE),
- TEST_f_f (exp10, -max_value, 0, UNDERFLOW_EXCEPTION),
+ TEST_f_f (exp10, -max_value, 0, UNDERFLOW_EXCEPTION|ERRNO_ERANGE),
TEST_f_f (exp10, 0.75L, 5.62341325190349080394951039776481231L),
};
diff --git a/math/w_exp10.c b/math/w_exp10.c
index 3db012d..17823f5 100644
--- a/math/w_exp10.c
+++ b/math/w_exp10.c
@@ -28,7 +28,7 @@ double
__exp10 (double x)
{
double z = __ieee754_exp10 (x);
- if (__builtin_expect (!__finite (z), 0)
+ if (__builtin_expect (!__finite (z) || z == 0, 0)
&& __finite (x) && _LIB_VERSION != _IEEE_)
/* exp10 overflow (46) if x > 0, underflow (47) if x < 0. */
return __kernel_standard (x, x, 46 + !!__signbit (x));
diff --git a/math/w_exp10f.c b/math/w_exp10f.c
index 082b34f..e2f9185 100644
--- a/math/w_exp10f.c
+++ b/math/w_exp10f.c
@@ -28,7 +28,7 @@ float
__exp10f (float x)
{
float z = __ieee754_exp10f (x);
- if (__builtin_expect (!__finitef (z), 0)
+ if (__builtin_expect (!__finitef (z) || z == 0, 0)
&& __finitef (x) && _LIB_VERSION != _IEEE_)
/* exp10f overflow (146) if x > 0, underflow (147) if x < 0. */
return __kernel_standard_f (x, x, 146 + !!__signbitf (x));
diff --git a/math/w_exp10l.c b/math/w_exp10l.c
index 10f3f81..19facdd 100644
--- a/math/w_exp10l.c
+++ b/math/w_exp10l.c
@@ -28,7 +28,7 @@ long double
__exp10l (long double x)
{
long double z = __ieee754_exp10l (x);
- if (__builtin_expect (!__finitel (z), 0)
+ if (__builtin_expect (!__finitel (z) || z == 0, 0)
&& __finitel (x) && _LIB_VERSION != _IEEE_)
/* exp10l overflow (246) if x > 0, underflow (247) if x < 0. */
return __kernel_standard_l (x, x, 246 + !!__signbitl (x));
--
Joseph S. Myers
joseph@codesourcery.com