Skip to content

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

Closed
@nsajko

Description

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

mathsMathematical functions

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions