Skip to content

Commit 94b4be6

Browse files
committed
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).
1 parent 15a1d62 commit 94b4be6

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

math/erf.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ erf (double x)
4747
{ /* a < 2^(-28). */
4848
if (ia < 0x00800000)
4949
{ /* a < 2^(-1015). */
50-
double y = x + TwoOverSqrtPiMinusOne * x;
50+
double y = fma (TwoOverSqrtPiMinusOne, x, x);
5151
return check_uflow (y);
5252
}
5353
return x + TwoOverSqrtPiMinusOne * x;

math/erff.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ erff (float x)
4545
{ /* |x| < 2^(-28). */
4646
if (unlikely (ia12 < 0x040))
4747
{ /* |x| < 2^(-119). */
48-
float y = x + TwoOverSqrtPiMinusOne * x;
48+
float y = fmaf (TwoOverSqrtPiMinusOne, x, x);
4949
return check_uflowf (y);
5050
}
5151
return x + TwoOverSqrtPiMinusOne * x;

0 commit comments

Comments
 (0)