Base.Inf for other Number types?

@Tamas_Papp’s answer and others proposing/implementing infinity types are a good ones.

If you want to avoid the Union…I started working on a NaNIntegers package, but never finished it. Here’s the start: https://gist.github.com/timholy/569475b24763d1fbd36a42634192cb74. It uses the second-from-top-bit to indicate NaN. You could modify this to use the third-from-top-bit to indicate infinity. Note you have to write your own rules of mathematics, so there’s still a bit of work to do.

I’d generally recommend against mimicking infinity with typemax:

julia> i = typemax(Int)
9223372036854775807

julia> i+1 == i
false

julia> 2*i == i
false

julia> i-1 == i
false

Any infinity that doesn’t obey those properties is not really infinity.

8 Likes