Skip to content

Commit

Permalink
fix exp(weirdNaN) (#56784)
Browse files Browse the repository at this point in the history
Fixes #56782
Fix `exp(reinterpret(Float64, 0x7ffbb14880000000))` returning non-NaN
value. This should have minimal performance impact since it's already in
the fallback branch.

(cherry picked from commit 19e06d3)
  • Loading branch information
oscardssmith authored and KristofferC committed Jan 13, 2025
1 parent 70b34b2 commit 708c42d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
2 changes: 2 additions & 0 deletions base/special/exp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ end
small_part = muladd(jU, expm1b_kernel(base, r), jL) + jU

if !(abs(x) <= SUBNORM_EXP(base, T))
isnan(x) && return x
x >= MAX_EXP(base, T) && return Inf
x <= MIN_EXP(base, T) && return 0.0
if k <= -53
Expand Down Expand Up @@ -243,6 +244,7 @@ end
hi, lo = Base.canonicalize2(1.0, kern)
small_part = fma(jU, hi, muladd(jU, (lo+xlo), very_small))
if !(abs(x) <= SUBNORM_EXP(base, T))
isnan(x) && return x
x >= MAX_EXP(base, T) && return Inf
x <= MIN_EXP(base, T) && return 0.0
if k <= -53
Expand Down
4 changes: 4 additions & 0 deletions test/math.jl
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,10 @@ end
end
end

@testset "https://github.com/JuliaLang/julia/issues/56782" begin
@test isnan(exp(reinterpret(Float64, 0x7ffbb14880000000)))
end

@testset "test abstractarray trig functions" begin
TAA = rand(2,2)
TAA = (TAA + TAA')/2.
Expand Down

0 comments on commit 708c42d

Please sign in to comment.