From 0b840c71c1d05734bd9b66e8b9f1dace80943485 Mon Sep 17 00:00:00 2001 From: Oscar Smith Date: Fri, 26 Aug 2022 05:11:05 -0400 Subject: [PATCH] fix bug when error is infinite (#46436) (cherry picked from commit c491e7912603facb0adfc04592c88b17d3e281c2) --- base/math.jl | 4 ++-- test/math.jl | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/base/math.jl b/base/math.jl index eb69c555d985b5..3b5465bc86e192 100644 --- a/base/math.jl +++ b/base/math.jl @@ -1068,8 +1068,8 @@ end xnlo += err n >>>= 1 end - !isfinite(x) && return x*y - return muladd(x, y, muladd(y, xnlo, x*ynlo)) + err = muladd(y, xnlo, x*ynlo) + return ifelse(isfinite(x) & isfinite(err), muladd(x, y, err), x*y) end function ^(x::Float32, n::Integer) diff --git a/test/math.jl b/test/math.jl index 56d97562ca0abb..1946e73829eb68 100644 --- a/test/math.jl +++ b/test/math.jl @@ -1362,6 +1362,7 @@ end end # test for large negative exponent where error compensation matters @test 0.9999999955206014^-1.0e8 == 1.565084574870928 + @test 3e18^20 == Inf end # Test that sqrt behaves correctly and doesn't exhibit fp80 double rounding.