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

Inconsistency in arithmetic of infinites of different types #47

Open
fingolfin opened this issue Aug 22, 2023 · 2 comments
Open

Inconsistency in arithmetic of infinites of different types #47

fingolfin opened this issue Aug 22, 2023 · 2 comments

Comments

@fingolfin
Copy link

This is fine:

julia> RealInfinity() - RealInfinity()
ERROR: ArgumentError: Cannot subtract ∞ from ∞
Stacktrace:
 [1] -(x::RealInfinity, y::RealInfinity)
   @ Infinities ~/.julia/packages/Infinities/r8p4Q/src/Infinities.jl:195
 [2] top-level scope
   @ REPL[12]:1

This is also fine:

julia> Inf - Inf
NaN

This is not:

julia> RealInfinity() - Inf
+∞

julia> Inf - RealInfinity()
-∞
@dlfivefifty
Copy link
Member

Thanks for spotting this. I guess somewhere assumes floats are finite...

@fingolfin
Copy link
Author

Yeah it is this code:

for Typ in (:Number, :Real, :Integer, :AbstractFloat)
    @eval begin
        isless(x::RealInfinity, y::$Typ) = signbit(x) && y  -isless(x::$Typ, y::RealInfinity) = !signbit(y) && x +(::$Typ, y::RealInfinity) = y
        +(y::RealInfinity, ::$Typ) = y
        -(y::RealInfinity, ::$Typ) = y
        -(::$Typ, y::RealInfinity) = -y
        function *(a::$Typ, y::RealInfinity)
            iszero(a) && throw(ArgumentError("Cannot multiply $a * $y"))
            a > 0 ? y : (-y)
        end
    end
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants