|
1 | 1 | module Infinities |
2 | 2 |
|
3 | | -import Base: angle, isone, iszero, isinf, isfinite, abs, one, zero, isless, |
| 3 | +import Base: angle, isone, iszero, isinf, isfinite, abs, one, oneunit, zero, isless, |
4 | 4 | +, -, *, ==, <, ≤, >, ≥, fld, cld, div, mod, min, max, sign, signbit, |
5 | 5 | string, show, promote_rule, convert, getindex |
6 | 6 |
|
@@ -42,6 +42,8 @@ sign(y::Infinity) = 1 |
42 | 42 | angle(x::Infinity) = 0 |
43 | 43 |
|
44 | 44 | one(::Type{Infinity}) = 1 |
| 45 | +oneunit(::Type{Infinity}) = 1 |
| 46 | +oneunit(::Infinity) = 1 |
45 | 47 | zero(::Infinity) = 0 |
46 | 48 |
|
47 | 49 | isinf(::Infinity) = true |
@@ -139,6 +141,16 @@ isfinite(::RealInfinity) = false |
139 | 141 | promote_rule(::Type{Infinity}, ::Type{RealInfinity}) = RealInfinity |
140 | 142 | convert(::Type{RealInfinity}, ::Infinity) = RealInfinity(false) |
141 | 143 |
|
| 144 | +convert(::Type{Float64}, x::RealInfinity) = sign(x)*Inf64 |
| 145 | +convert(::Type{Float32}, x::RealInfinity) = sign(x)*Inf32 |
| 146 | +convert(::Type{Float16}, x::RealInfinity) = sign(x)*Inf16 |
| 147 | +Base.Float64(x::RealInfinity) = convert(Float64, x) |
| 148 | +Base.Float32(x::RealInfinity) = convert(Float32, x) |
| 149 | +Base.Float16(x::RealInfinity) = convert(Float16, x) |
| 150 | +Base.BigFloat(x::RealInfinity) = sign(x)*BigFloat(Inf) |
| 151 | +convert(::Type{AF}, x::RealInfinity) where AF<:AbstractFloat = sign(x)*convert(AF, Inf) |
| 152 | + |
| 153 | + |
142 | 154 | signbit(y::RealInfinity) = y.signbit |
143 | 155 | sign(y::RealInfinity) = 1-2signbit(y) |
144 | 156 | angle(x::RealInfinity) = π*signbit(x) |
|
0 commit comments