From ca121b117f2c9c97a4c121334481a96c94fef3a0 Mon Sep 17 00:00:00 2001 From: Joseph Myers Date: Mon, 11 Jun 2018 16:33:42 +0000 Subject: Fix ldbl-96 fma (Inf, Inf, finite) (bug 23272). As reported in bug 23272, the ldbl-96 implementation of fma (fma for double, in terms of ldbl-96 as the internal arithmetic type, as used on 32-bit x86) is missing some of the special-case handling for non-finite arguments, resulting in incorrect NaN results when the first two arguments are infinities, the third is finite and so the infinities go through the logic for finite arguments. This patch fixes it by handling all cases of non-finite arguments up front, with additional fma tests for the problem cases being added to the testsuite. Tested for x86_64 and x86. [BZ #23272] * sysdeps/ieee754/ldbl-96/s_fma.c (__fma): Start by handling all cases of non-finite arguments. * math/libm-test-fma.inc (fma_test_data): Add more tests. --- sysdeps/ieee754/ldbl-96/s_fma.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'sysdeps/ieee754/ldbl-96') diff --git a/sysdeps/ieee754/ldbl-96/s_fma.c b/sysdeps/ieee754/ldbl-96/s_fma.c index f7f4dfd28d..986879cda5 100644 --- a/sysdeps/ieee754/ldbl-96/s_fma.c +++ b/sysdeps/ieee754/ldbl-96/s_fma.c @@ -32,14 +32,12 @@ double __fma (double x, double y, double z) { - if (__glibc_unlikely (isinf (z))) - { - /* If z is Inf, but x and y are finite, the result should be - z rather than NaN. */ - if (isfinite (x) && isfinite (y)) - return (z + x) + y; - return (x * y) + z; - } + if (__glibc_unlikely (!isfinite (x) || !isfinite (y))) + return x * y + z; + else if (__glibc_unlikely (!isfinite (z))) + /* If z is Inf, but x and y are finite, the result should be z + rather than NaN. */ + return (z + x) + y; /* Ensure correct sign of exact 0 + 0. */ if (__glibc_unlikely ((x == 0 || y == 0) && z == 0)) -- cgit 1.4.1