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

Closed
fingolfin opened this issue Aug 22, 2023 · 3 comments · Fixed by #40
Closed

Inconsistency in arithmetic of infinites of different types #47

fingolfin opened this issue Aug 22, 2023 · 3 comments · Fixed by #40

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

@putianyi889
Copy link
Contributor

fixed by #40

putianyi889 added a commit to putianyi889/Infinities.jl that referenced this issue Nov 26, 2024
dlfivefifty added a commit that referenced this issue Nov 29, 2024
* fix ambiguities

* Update cardinality.jl

* update

* update

* update

* update

* update

* multiplication

* Update ambiguities.jl

* update

* isinf and isfinite

* mod

* fld, cld, div

* cleanup

* cleanup and add a test

* test ComplexInfinity promotion

* Update Infinities.jl

* Update runtests.jl

* coverage

* coverage

* add a note

* add tests for #47

---------

Co-authored-by: Sheehan Olver <[email protected]>
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

Successfully merging a pull request may close this issue.

3 participants