Skip to content

Commit

Permalink
fix incorrect results in expm1(::Union{Float16, Float32}) (#50989)
Browse files Browse the repository at this point in the history
`unsafe_trunc(UInt, -1.0)` is unspecified behavior but worked fine on
apple and AMD so we didn't notice??? This has been very broken since 1.7.
  • Loading branch information
oscardssmith authored Aug 21, 2023
1 parent 96e5b62 commit 61ebaf6
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
4 changes: 2 additions & 2 deletions base/special/exp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ function expm1(x::Float32)
end
x = Float64(x)
N_float = round(x*Ln2INV(Float64))
N = unsafe_trunc(UInt64, N_float)
N = unsafe_trunc(Int64, N_float)
r = muladd(N_float, Ln2(Float64), x)
hi = evalpoly(r, (1.0, .5, 0.16666667546642386, 0.041666183019487026,
0.008332997481506921, 0.0013966479175977883, 0.0002004037059220124))
Expand All @@ -477,7 +477,7 @@ function expm1(x::Float16)
return Float16(x*evalpoly(x, (1f0, .5f0, 0.16666628f0, 0.04166785f0, 0.008351848f0, 0.0013675707f0)))
end
N_float = round(x*Ln2INV(Float32))
N = unsafe_trunc(UInt32, N_float)
N = unsafe_trunc(Int32, N_float)
r = muladd(N_float, Ln2(Float32), x)
hi = evalpoly(r, (1f0, .5f0, 0.16666667f0, 0.041665863f0, 0.008333111f0, 0.0013981499f0, 0.00019983904f0))
small_part = r*hi
Expand Down
1 change: 1 addition & 0 deletions test/math.jl
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ end
@test exp10(x) exp10(big(x))
@test exp2(x) exp2(big(x))
@test expm1(x) expm1(big(x))
@test expm1(T(-1.1)) expm1(big(T(-1.1)))
@test hypot(x,y) hypot(big(x),big(y))
@test hypot(x,x,y) hypot(hypot(big(x),big(x)),big(y))
@test hypot(x,x,y,y) hypot(hypot(big(x),big(x)),hypot(big(y),big(y)))
Expand Down

0 comments on commit 61ebaf6

Please sign in to comment.