Skip to content

Commit

Permalink
fix exp of large negative Float16 (JuliaLang#42688)
Browse files Browse the repository at this point in the history
  • Loading branch information
oscardssmith authored Oct 19, 2021
1 parent e1d831b commit 02f7861
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
6 changes: 3 additions & 3 deletions base/special/exp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -304,9 +304,9 @@ end
N = unsafe_trunc(Int32, N_float)
r = muladd(N_float, LogB(base, Float16), x)
small_part = expb_kernel(base, r)
if !(abs(x) <= SUBNORM_EXP(base, T))
x > MAX_EXP(base, T) && return Inf16
x < MIN_EXP(base, T) && return zero(Float16)
if !(abs(x) <= 25)
x > 16 && return Inf16
x < 25 && return zero(Float16)
end
twopk = reinterpret(T, (N+Int32(127)) << Int32(23))
return Float16(twopk*small_part)
Expand Down
7 changes: 5 additions & 2 deletions test/math.jl
Original file line number Diff line number Diff line change
Expand Up @@ -316,10 +316,13 @@ end
X = Iterators.flatten((minval:T(.1):maxval,
minval/100:T(.0021):maxval/100,
minval/10000:T(.000021):maxval/10000,
nextfloat(zero(T)) ))
nextfloat(zero(T)),
T(-100):T(1):T(100) ))
for x in X
y, yb = func(x), func(widen(x))
@test abs(y-yb) <= 1.2*eps(T(yb))
if isfinite(eps(T(yb)))
@test abs(y-yb) <= 1.2*eps(T(yb))
end
end
end
@testset "$T $func edge cases" begin
Expand Down

0 comments on commit 02f7861

Please sign in to comment.