Skip to content

Commit ec76d27

Browse files
oscardssmithnalimilan
authored andcommitted
fix incorrect results in expm1(::Union{Float16, Float32}) (#50989)
`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. (cherry picked from commit 61ebaf6)
1 parent 10de6c4 commit ec76d27

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

base/special/exp.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ function expm1(x::Float32)
460460
end
461461
x = Float64(x)
462462
N_float = round(x*Ln2INV(Float64))
463-
N = unsafe_trunc(UInt64, N_float)
463+
N = unsafe_trunc(Int64, N_float)
464464
r = muladd(N_float, Ln2(Float64), x)
465465
hi = evalpoly(r, (1.0, .5, 0.16666667546642386, 0.041666183019487026,
466466
0.008332997481506921, 0.0013966479175977883, 0.0002004037059220124))
@@ -477,7 +477,7 @@ function expm1(x::Float16)
477477
return Float16(x*evalpoly(x, (1f0, .5f0, 0.16666628f0, 0.04166785f0, 0.008351848f0, 0.0013675707f0)))
478478
end
479479
N_float = round(x*Ln2INV(Float32))
480-
N = unsafe_trunc(UInt32, N_float)
480+
N = unsafe_trunc(Int32, N_float)
481481
r = muladd(N_float, Ln2(Float32), x)
482482
hi = evalpoly(r, (1f0, .5f0, 0.16666667f0, 0.041665863f0, 0.008333111f0, 0.0013981499f0, 0.00019983904f0))
483483
small_part = r*hi

test/math.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ end
188188
@test exp10(x) exp10(big(x))
189189
@test exp2(x) exp2(big(x))
190190
@test expm1(x) expm1(big(x))
191+
@test expm1(T(-1.1)) expm1(big(T(-1.1)))
191192
@test hypot(x,y) hypot(big(x),big(y))
192193
@test hypot(x,x,y) hypot(hypot(big(x),big(x)),big(y))
193194
@test hypot(x,x,y,y) hypot(hypot(big(x),big(x)),hypot(big(y),big(y)))

0 commit comments

Comments
 (0)