Discussion:
[PATCH] Fix powf overflow handling in non-nearest rounding mode [BZ #23961]
(too old to reply)
Szabolcs Nagy
2018-12-10 15:08:15 UTC
Permalink
The threshold value at which powf overflows depends on the rounding mode
and the current check did not take this into account. So when the result
was rounded away from zero it could become infinity without setting
errno to ERANGE.

Example: pow(0x1.7ac7cp+5, 23) is 0x1.fffffep+127 + 0.1633ulp

If the result goes above 0x1.fffffep+127 + 0.5ulp then errno is set,
which is fine in nearest rounding mode, but

powf(0x1.7ac7cp+5, 23) is inf in upward rounding mode
powf(-0x1.7ac7cp+5, 23) is -inf in downward rounding mode

and the previous implementation did not set errno in these cases.

The fix tries to avoid affecting the common code path or calling a
function that may introduce a stack frame, so float arithmetics is used
to check the rounding mode and the threshold is selected accordingly.

2018-12-10 Szabolcs Nagy <***@arm.com>

[BZ #23961]
* math/auto-libm-test-in: Add new test case.
* math/auto-libm-test-out-pow: Regenerated.
* sysdeps/ieee754/flt-32/e_powf.c (__powf): Fix overflow check.
Joseph Myers
2018-12-10 22:15:27 UTC
Permalink
Post by Szabolcs Nagy
[BZ #23961]
* math/auto-libm-test-in: Add new test case.
* math/auto-libm-test-out-pow: Regenerated.
* sysdeps/ieee754/flt-32/e_powf.c (__powf): Fix overflow check.
OK.

(It's possible some architecture with its own powf implementation could
need to XFAIL the new tests if that architecture doesn't get overflow
exactly right for those cases: the test infrastructure doesn't currently
support marking a test as very close to the overflow threshold and then
allowing appropriately for computed results on the other side of that
threshold only being slightly inaccurate, so OK, as long as they handle
errno / exceptions consistently with the returned value.)
--
Joseph S. Myers
***@codesourcery.com
Loading...