Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(-Inf)^-1 inconsistency for Float64 #55831

Closed
nsajko opened this issue Sep 21, 2024 · 0 comments · Fixed by #55875
Closed

(-Inf)^-1 inconsistency for Float64 #55831

nsajko opened this issue Sep 21, 2024 · 0 comments · Fixed by #55875
Assignees
Labels
maths Mathematical functions

Comments

@nsajko
Copy link
Contributor

nsajko commented Sep 21, 2024

using Test

@testset "inconsistency, possible bug" 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

It fails only for T === Float64, and only in the non-literal case:

Test Summary:               | Pass  Fail  Total  Time
inconsistency, possible bug |    7     1      8  1.8s
  T: Float16                |    2            2  0.0s
  T: Float32                |    2            2  0.0s
  T: Float64                |    1     1      2  1.8s
    literal `-1`            |    1            1  0.0s
    `Int(-1)`               |          1      1  1.8s
  T: BigFloat               |    2            2  0.0s
ERROR: Some tests did not pass: 7 passed, 1 failed, 0 errored, 0 broken.

The reason why the sign of the zero might matter here is perhaps that the zero with negative sign is the identity element for addition in IEEE 754 floating-point. It's suspicious that there's an "odd one out" here, in any case.

@nsajko nsajko added the maths Mathematical functions label Sep 21, 2024
@oscardssmith oscardssmith self-assigned this Sep 21, 2024
KristofferC pushed a commit that referenced this issue Feb 15, 2025
fixes #55831

(cherry picked from commit 2364719)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
maths Mathematical functions
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants