Skip to content

Commit

Permalink
Relax gen-auto-libm-tests may-underflow rules, test log1p in all roun…
Browse files Browse the repository at this point in the history
…ding modes.

gen-auto-libm-tests presently allows but does not require underflow
exceptions for results with magnitude in the range (greatest
subnormal, least normal].

In some cases, the magnitude of the exact result is very slightly
above the least normal, but rounding in the implementation results in
it effectively computing an infinite-precision result that is slightly
below the least normal, so raising an underflow exception.  This is in
accordance with the documented accuracy goals, but results in
testsuite failures.

This patch changes the logic to allow underflows when the mathematical
result is up to 0.5ulp above the least normal (so in any case where
the round-to-nearest result is the least normal).  Ideally underflows
in all these cases would be accepted only when an underflow with the
actual result is consistent with the rounding mode (in FE_TOWARDZERO
mode, a return value of the least normal implies that the
infinite-precision result did not underflow so there should be no
underflow exception, for example), so as to match the documented goals
more precisely - whereas at present the tests for exceptions are
completely independent of the tests of the returned values.  (The same
applies to overflow exceptions as well - they too should be checked
for consistency with the result, as in FE_TOWARDZERO mode a result
1ulp below the largest finite value should be inconsistent with an
overflow exception and cause a failure with overflow rather than
simply being considered a 1ulp error when overflow is expected.)  But
the present patch at least deals with the cases causing spurious
failures so that (a) certain existing tests no longer need to be
marked as having spurious exceptions (such markings in
auto-libm-test-in end up applying to more cases than just those they
are needed for) and (b) log1p can be tested in all rounding modes
without introducing more such failures.  This patch duly moves tests
of log1p to ALL_RM_TEST.

Tested x86_64 and x86 and ulps updated accordingly.

	[BZ #16357]
	[BZ #16599]
	* math/gen-auto-libm-tests.c (fp_format_desc): Add field
	min_plus_half.
	(fp_formats): Update initializers.
	(init_fp_formats): Initialize new field.
	(output_for_one_input_case): Allow underflow for results up to
	min_plus_half.
	* math/libm-test.inc (log1p_test): Use ALL_RM_TEST.
	* math/auto-libm-test-in: Don't mark some underflows from asin and
	atanh as spurious.
	* math/auto-libm-test-out: Regenerated.
	* sysdeps/i386/fpu/libm-test-ulps: Update.
	* sysdeps/x86_64/fpu/libm-test-ulps: Likewise.
  • Loading branch information
Joseph Myers committed Mar 25, 2014
1 parent 003e49e commit 046651c
Show file tree
Hide file tree
Showing 8 changed files with 367 additions and 299 deletions.
17 changes: 17 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
2014-03-25 Joseph Myers <joseph@codesourcery.com>

[BZ #16357]
[BZ #16599]
* math/gen-auto-libm-tests.c (fp_format_desc): Add field
min_plus_half.
(fp_formats): Update initializers.
(init_fp_formats): Initialize new field.
(output_for_one_input_case): Allow underflow for results up to
min_plus_half.
* math/libm-test.inc (log1p_test): Use ALL_RM_TEST.
* math/auto-libm-test-in: Don't mark some underflows from asin and
atanh as spurious.
* math/auto-libm-test-out: Regenerated.
* sysdeps/i386/fpu/libm-test-ulps: Update.
* sysdeps/x86_64/fpu/libm-test-ulps: Likewise.

2014-03-25 Andreas Schwab <schwab@suse.de>

* libio/Makefile (tst-ftell-partial-wide-ENV)
Expand Down
8 changes: 4 additions & 4 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ Version 2.20

* The following bugs are resolved with this release:

15347, 15804, 15894, 16002, 16284, 16447, 16532, 16545, 16574, 16600,
16609, 16610, 16611, 16613, 16623, 16632, 16634, 16639, 16642, 16649,
16670, 16674, 16677, 16680, 16683, 16689, 16695, 16701, 16706, 16707,
16712, 16713, 16714, 16731, 16743.
15347, 15804, 15894, 16002, 16284, 16357, 16447, 16532, 16545, 16574,
16599, 16600, 16609, 16610, 16611, 16613, 16623, 16632, 16634, 16639,
16642, 16649, 16670, 16674, 16677, 16680, 16683, 16689, 16695, 16701,
16706, 16707, 16712, 16713, 16714, 16731, 16743.

* Running the testsuite no longer terminates as soon as a test fails.
Instead, a file tests.sum (xtests.sum from "make xcheck") is generated,
Expand Down
8 changes: 3 additions & 5 deletions math/auto-libm-test-in
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,8 @@ asin -0x0.ffffffffffffp0
asin 0x0.ffffffffffffffffp0
asin -0x0.ffffffffffffffffp0
# Bug 16351: underflow exception may be missing.
# Bug 16599: spurious underflow may occur.
asin min missing-underflow
asin -min missing-underflow spurious-underflow:dbl-64:x86
asin -min missing-underflow
asin min_subnorm missing-underflow
asin -min_subnorm missing-underflow

Expand Down Expand Up @@ -175,9 +174,8 @@ atanh 0x1p-5
atanh 0x1p-10
atanh 0x1.2345p-20
# Bug 16352: underflow exception may be missing.
# Bug 16357: spurious underflow may occur.
atanh min missing-underflow spurious-underflow:ldbl-96-intel:x86
atanh -min missing-underflow spurious-underflow:ldbl-96-intel:x86
atanh min missing-underflow
atanh -min missing-underflow
atanh min_subnorm missing-underflow
atanh -min_subnorm missing-underflow

Expand Down
558 changes: 279 additions & 279 deletions math/auto-libm-test-out

Large diffs are not rendered by default.

23 changes: 15 additions & 8 deletions math/gen-auto-libm-tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,8 @@ typedef struct
int min_exp;
/* The largest normal value. */
mpfr_t max;
/* The value 0.5ulp above the least positive normal value. */
mpfr_t min_plus_half;
/* The least positive normal value, 2^(MIN_EXP-1). */
mpfr_t min;
/* The greatest positive subnormal value. */
Expand All @@ -183,13 +185,13 @@ typedef struct
enumeration. */
static fp_format_desc fp_formats[fp_num_formats] =
{
{ "flt-32", "f", NULL, 24, 128, -125, {}, {}, {}, {} },
{ "dbl-64", "", NULL, 53, 1024, -1021, {}, {}, {}, {} },
{ "ldbl-96-intel", "L", NULL, 64, 16384, -16381, {}, {}, {}, {} },
{ "ldbl-96-m68k", "L", NULL, 64, 16384, -16382, {}, {}, {}, {} },
{ "ldbl-128", "L", NULL, 113, 16384, -16381, {}, {}, {}, {} },
{ "flt-32", "f", NULL, 24, 128, -125, {}, {}, {}, {}, {} },
{ "dbl-64", "", NULL, 53, 1024, -1021, {}, {}, {}, {}, {} },
{ "ldbl-96-intel", "L", NULL, 64, 16384, -16381, {}, {}, {}, {}, {} },
{ "ldbl-96-m68k", "L", NULL, 64, 16384, -16382, {}, {}, {}, {}, {} },
{ "ldbl-128", "L", NULL, 113, 16384, -16381, {}, {}, {}, {}, {} },
{ "ldbl-128ibm", "L", "0x1.fffffffffffff7ffffffffffff8p+1023",
106, 1024, -968, {}, {}, {}, {} },
106, 1024, -968, {}, {}, {}, {}, {} },
};

/* The supported rounding modes. */
Expand Down Expand Up @@ -702,6 +704,10 @@ init_fp_formats ()
assert_exact (mpfr_set_ui_2exp (fp_formats[f].min, 1,
fp_formats[f].min_exp - 1,
MPFR_RNDN));
mpfr_init2 (fp_formats[f].min_plus_half, fp_formats[f].mant_dig + 1);
assert_exact (mpfr_set (fp_formats[f].min_plus_half,
fp_formats[f].min, MPFR_RNDN));
mpfr_nextabove (fp_formats[f].min_plus_half);
mpfr_init2 (fp_formats[f].subnorm_max, fp_formats[f].mant_dig);
assert_exact (mpfr_set (fp_formats[f].subnorm_max, fp_formats[f].min,
MPFR_RNDN));
Expand Down Expand Up @@ -1841,8 +1847,9 @@ output_for_one_input_case (FILE *fp, const char *filename, test_function *tf,
<= 0));
may_underflow
|= (!mpfr_zero_p (generic_outputs[i].value.f)
&& mpfr_cmpabs (generic_outputs[i].value.f,
fp_formats[f].min) <= 0);
&& (mpfr_cmpabs (generic_outputs[i].value.f,
fp_formats[f].min_plus_half)
<= 0));
}
/* If the result is an exact zero, the sign may
depend on the rounding mode, so recompute it
Expand Down
4 changes: 1 addition & 3 deletions math/libm-test.inc
Original file line number Diff line number Diff line change
Expand Up @@ -7823,9 +7823,7 @@ static const struct test_f_f_data log1p_test_data[] =
static void
log1p_test (void)
{
START (log1p, 0);
RUN_TEST_LOOP_f_f (log1p, log1p_test_data, );
END;
ALL_RM_TEST (log1p, 0, log1p_test_data, RUN_TEST_LOOP_f_f, END);
}


Expand Down
24 changes: 24 additions & 0 deletions sysdeps/i386/fpu/libm-test-ulps
Original file line number Diff line number Diff line change
Expand Up @@ -1288,6 +1288,30 @@ Function: "log1p":
ildouble: 1
ldouble: 1

Function: "log1p_downward":
double: 1
float: 1
idouble: 1
ifloat: 1
ildouble: 2
ldouble: 2

Function: "log1p_towardzero":
double: 1
float: 1
idouble: 1
ifloat: 1
ildouble: 2
ldouble: 2

Function: "log1p_upward":
double: 1
float: 1
idouble: 1
ifloat: 1
ildouble: 1
ldouble: 1

Function: "log_downward":
ildouble: 1
ldouble: 1
Expand Down
24 changes: 24 additions & 0 deletions sysdeps/x86_64/fpu/libm-test-ulps
Original file line number Diff line number Diff line change
Expand Up @@ -1362,6 +1362,30 @@ ifloat: 1
ildouble: 1
ldouble: 1

Function: "log1p_downward":
double: 1
float: 1
idouble: 1
ifloat: 1
ildouble: 2
ldouble: 2

Function: "log1p_towardzero":
double: 1
float: 1
idouble: 1
ifloat: 1
ildouble: 2
ldouble: 2

Function: "log1p_upward":
double: 1
float: 1
idouble: 1
ifloat: 1
ildouble: 1
ldouble: 1

Function: "log_downward":
float: 1
ifloat: 1
Expand Down

0 comments on commit 046651c

Please sign in to comment.