|
1 | 1 | module Infinities |
2 | 2 |
|
3 | 3 | import Base: angle, isone, iszero, isinf, isfinite, abs, one, zero, isless, |
4 | | - +, -, *, ==, <, ≤, >, ≥, fld, cld, div, mod, min, max, sign, string, show |
| 4 | + +, -, *, ==, <, ≤, >, ≥, fld, cld, div, mod, min, max, sign, signbit, |
| 5 | + string, show, promote_rule, convert |
5 | 6 |
|
| 7 | +export ∞, Infinity, RealInfinity, ComplexInfinity, NotANumber |
6 | 8 |
|
7 | 9 | """ |
8 | 10 | NotANumber() |
@@ -290,19 +292,19 @@ angle(x::ComplexInfinity) = π*x.signbit |
290 | 292 | mod(::ComplexInfinity{<:Integer}, ::Integer) = NotANumber() |
291 | 293 |
|
292 | 294 |
|
293 | | -show(io::IO, x::ComplexInfinity) = print(io, "$(exp(im*π*x.angle))∞") |
| 295 | +show(io::IO, x::ComplexInfinity) = print(io, "$(exp(im*π*x.signbit))∞") |
294 | 296 |
|
295 | 297 | ==(x::ComplexInfinity, y::Infinity) = x.signbit == 0 |
296 | 298 | ==(y::Infinity, x::ComplexInfinity) = x.signbit == 0 |
297 | 299 | ==(x::ComplexInfinity, y::RealInfinity) = x.signbit == signbit(y) |
298 | 300 | ==(y::RealInfinity, x::ComplexInfinity) = x.signbit == signbit(y) |
299 | | -==(x::ComplexInfinity, y::ComplexInfinity) = x.signbit == y.angle |
| 301 | +==(x::ComplexInfinity, y::ComplexInfinity) = x.signbit == y.signbit |
300 | 302 |
|
301 | 303 | ==(x::ComplexInfinity, y::Number) = isinf(y) && angle(y) == angle(x) |
302 | 304 | ==(y::Number, x::ComplexInfinity) = x == y |
303 | 305 |
|
304 | | -isless(x::ComplexInfinity{Bool}, y::ComplexInfinity{Bool}) = x.signbit && !y.angle |
305 | | -isless(x::Number, y::ComplexInfinity{Bool}) = !y.angle && x ≠ ∞ |
| 306 | +isless(x::ComplexInfinity{Bool}, y::ComplexInfinity{Bool}) = x.signbit && !y.signbit |
| 307 | +isless(x::Number, y::ComplexInfinity{Bool}) = !y.signbit && x ≠ ∞ |
306 | 308 | isless(x::ComplexInfinity{Bool}, y::Number) = x.signbit && y ≠ -∞ |
307 | 309 |
|
308 | 310 | -(y::ComplexInfinity{B}) where B<:Integer = sign(y) == 1 ? ComplexInfinity(one(B)) : ComplexInfinity(zero(B)) |
|
323 | 325 |
|
324 | 326 |
|
325 | 327 | # ⊻ is xor |
326 | | -*(a::ComplexInfinity{Bool}, b::ComplexInfinity{Bool}) = ComplexInfinity(a.angle ⊻ b.angle) |
327 | | -*(a::ComplexInfinity, b::ComplexInfinity) = ComplexInfinity(a.angle + b.angle) |
| 328 | +*(a::ComplexInfinity{Bool}, b::ComplexInfinity{Bool}) = ComplexInfinity(a.signbit ⊻ b.signbit) |
| 329 | +*(a::ComplexInfinity, b::ComplexInfinity) = ComplexInfinity(a.signbit + b.signbit) |
328 | 330 | *(a::Infinity, b::ComplexInfinity) = ComplexInfinity(a)*b |
329 | 331 | *(a::ComplexInfinity, b::Infinity) = a*ComplexInfinity(b) |
330 | 332 | *(a::RealInfinity, b::ComplexInfinity) = ComplexInfinity(a)*b |
|
333 | 335 | *(a::Real, y::ComplexInfinity) = a > 0 ? y : (-y) |
334 | 336 | *(y::ComplexInfinity, a::Real) = a*y |
335 | 337 |
|
336 | | -*(a::Number, y::ComplexInfinity) = ComplexInfinity(y.angle+angle(a)/π) |
| 338 | +*(a::Number, y::ComplexInfinity) = ComplexInfinity(y.signbit+angle(a)/π) |
337 | 339 | *(y::ComplexInfinity, a::Number) = a*y |
338 | 340 |
|
339 | 341 | *(a::Number, y::Infinity) = a*ComplexInfinity(y) |
|
0 commit comments