diff options
author | Szabolcs Nagy <szabolcs.nagy@arm.com> | 2020-11-13 17:09:00 +0000 |
---|---|---|
committer | Szabolcs Nagy <szabolcs.nagy@arm.com> | 2020-11-13 17:22:21 +0000 |
commit | 94b4be6009322a584cd3f7b74f22565a162bddfa (patch) | |
tree | 649d783fee95bcb7ed810a0b5689a933ad1ff8e9 | |
parent | 15a1d62bf0d6e6069a917b633b5013e36f08e017 (diff) | |
download | arm-optimized-routines-94b4be6009322a584cd3f7b74f22565a162bddfa.tar.gz |
math: fix spurious underflow in erff and erf
The code relied on the final x + c*x to be done via an fma, otherwise
the intermediate c*x could underflow for tiny (almost subnormal) x.
Use explicit fmaf like elsewhere (this code is not expected to be
fast when fma is not inlined, but at least it should be correct).
-rw-r--r-- | math/erf.c | 2 | ||||
-rw-r--r-- | math/erff.c | 2 |
2 files changed, 2 insertions, 2 deletions
@@ -47,7 +47,7 @@ erf (double x) { /* a < 2^(-28). */ if (ia < 0x00800000) { /* a < 2^(-1015). */ - double y = x + TwoOverSqrtPiMinusOne * x; + double y = fma (TwoOverSqrtPiMinusOne, x, x); return check_uflow (y); } return x + TwoOverSqrtPiMinusOne * x; diff --git a/math/erff.c b/math/erff.c index 9b9ccc2..a58e825 100644 --- a/math/erff.c +++ b/math/erff.c @@ -45,7 +45,7 @@ erff (float x) { /* |x| < 2^(-28). */ if (unlikely (ia12 < 0x040)) { /* |x| < 2^(-119). */ - float y = x + TwoOverSqrtPiMinusOne * x; + float y = fmaf (TwoOverSqrtPiMinusOne, x, x); return check_uflowf (y); } return x + TwoOverSqrtPiMinusOne * x; |