From 3868be3b5811749172e3ca45f037d602e4891545 Mon Sep 17 00:00:00 2001 From: oscarddssmith Date: Wed, 25 Sep 2024 12:38:12 -0400 Subject: [PATCH 1/2] set xnlo to -0.0 initially --- base/math.jl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/base/math.jl b/base/math.jl index da51ab3a17bd0..d2596cd9f5456 100644 --- a/base/math.jl +++ b/base/math.jl @@ -1252,7 +1252,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) From 3f4bf013461b5ffe20605cd2c42e607bb28a51d6 Mon Sep 17 00:00:00 2001 From: Oscar Smith Date: Wed, 25 Sep 2024 15:35:36 -0400 Subject: [PATCH 2/2] add test --- test/math.jl | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/test/math.jl b/test/math.jl index c0a2d8bf8c9f8..5403ccf2e9c57 100644 --- a/test/math.jl +++ b/test/math.jl @@ -1498,6 +1498,16 @@ end n = Int64(1024 / log2(E)) @test E^n == Inf @test E^float(n) == Inf + @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 end # Test that sqrt behaves correctly and doesn't exhibit fp80 double rounding.