Skip to content

Commit

Permalink
fix bug when error is infinite (#46436)
Browse files Browse the repository at this point in the history
(cherry picked from commit c491e79)
  • Loading branch information
oscardssmith authored and KristofferC committed Aug 26, 2022
1 parent 649f568 commit 0b840c7
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
4 changes: 2 additions & 2 deletions base/math.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions test/math.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 0b840c7

Please sign in to comment.