Skip to content

Commit

Permalink
fix (-Inf)^-1 inconsistency (#55875)
Browse files Browse the repository at this point in the history
fixes #55831

(cherry picked from commit 2364719)
  • Loading branch information
oscardssmith authored and KristofferC committed Feb 15, 2025
1 parent 0a7da08 commit 41e0464
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
3 changes: 2 additions & 1 deletion base/math.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1217,7 +1217,8 @@ end
# this method is only reliable for -2^20 < n < 2^20 (cf. #53881 #53886)
@assume_effects :terminates_locally @noinline function pow_body(x::Float64, n::Integer)
y = 1.0
xnlo = ynlo = 0.0
xnlo = -0.0
ynlo = 0.0
n == 3 && return x*x*x # keep compatibility with literal_pow
if n < 0
rx = inv(x)
Expand Down
14 changes: 13 additions & 1 deletion test/math.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1505,7 +1505,19 @@ end
@test E^n == Inf
@test E^float(n) == Inf

# #55633
# issue #55831
@testset "literal pow zero sign" begin
@testset "T: $T" for T (Float16, Float32, Float64, BigFloat)
@testset "literal `-1`" begin
@test -0.0 === Float64(T(-Inf)^-1)
end
@testset "`Int(-1)`" begin
@test -0.0 === Float64(T(-Inf)^Int(-1))
end
end
end

# issue #55633
struct Issue55633_1 <: Number end
struct Issue55633_3 <: Number end
struct Issue55633_9 <: Number end
Expand Down

0 comments on commit 41e0464

Please sign in to comment.