Skip to content

Commit fa238ff

Browse files
oscardssmithKristofferC
authored andcommitted
fix exp(weirdNaN) (#56784)
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)
1 parent d81b037 commit fa238ff

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

base/special/exp.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ end
216216
small_part = muladd(jU, expm1b_kernel(base, r), jL) + jU
217217

218218
if !(abs(x) <= SUBNORM_EXP(base, T))
219+
isnan(x) && return x
219220
x >= MAX_EXP(base, T) && return Inf
220221
x <= MIN_EXP(base, T) && return 0.0
221222
if k <= -53
@@ -243,6 +244,7 @@ end
243244
hi, lo = Base.canonicalize2(1.0, kern)
244245
small_part = fma(jU, hi, muladd(jU, (lo+xlo), very_small))
245246
if !(abs(x) <= SUBNORM_EXP(base, T))
247+
isnan(x) && return x
246248
x >= MAX_EXP(base, T) && return Inf
247249
x <= MIN_EXP(base, T) && return 0.0
248250
if k <= -53

test/math.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,10 @@ end
366366
end
367367
end
368368

369+
@testset "https://github.com/JuliaLang/julia/issues/56782" begin
370+
@test isnan(exp(reinterpret(Float64, 0x7ffbb14880000000)))
371+
end
372+
369373
@testset "test abstractarray trig functions" begin
370374
TAA = rand(2,2)
371375
TAA = (TAA + TAA')/2.

0 commit comments

Comments
 (0)