Skip to content

Commit 41e0464

Browse files
oscardssmithKristofferC
authored andcommitted
fix (-Inf)^-1 inconsistency (#55875)
fixes #55831 (cherry picked from commit 2364719)
1 parent 0a7da08 commit 41e0464

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

base/math.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1217,7 +1217,8 @@ end
12171217
# this method is only reliable for -2^20 < n < 2^20 (cf. #53881 #53886)
12181218
@assume_effects :terminates_locally @noinline function pow_body(x::Float64, n::Integer)
12191219
y = 1.0
1220-
xnlo = ynlo = 0.0
1220+
xnlo = -0.0
1221+
ynlo = 0.0
12211222
n == 3 && return x*x*x # keep compatibility with literal_pow
12221223
if n < 0
12231224
rx = inv(x)

test/math.jl

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1505,7 +1505,19 @@ end
15051505
@test E^n == Inf
15061506
@test E^float(n) == Inf
15071507

1508-
# #55633
1508+
# issue #55831
1509+
@testset "literal pow zero sign" begin
1510+
@testset "T: $T" for T (Float16, Float32, Float64, BigFloat)
1511+
@testset "literal `-1`" begin
1512+
@test -0.0 === Float64(T(-Inf)^-1)
1513+
end
1514+
@testset "`Int(-1)`" begin
1515+
@test -0.0 === Float64(T(-Inf)^Int(-1))
1516+
end
1517+
end
1518+
end
1519+
1520+
# issue #55633
15091521
struct Issue55633_1 <: Number end
15101522
struct Issue55633_3 <: Number end
15111523
struct Issue55633_9 <: Number end

0 commit comments

Comments
 (0)