Skip to content

Commit 3d27318

Browse files
committed
angle -> signbit
1 parent ce53268 commit 3d27318

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed

src/Infinities.jl

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -253,8 +253,16 @@ max(::Infinity, x::RealInfinity) = ∞
253253
#######
254254

255255
# angle is π*a where a is (false==0) and (true==1)
256+
257+
"""
258+
ComplexInfinity(signbit)
259+
260+
represents an infinity in the complex plane with the angle
261+
specified by `π * signbit`. The use of the name `signbit` is
262+
for consistency with `RealInfinity`.
263+
"""
256264
struct ComplexInfinity{T<:Real} <: Number
257-
angle::T
265+
signbit::T
258266
end
259267

260268
ComplexInfinity{T}() where T = ComplexInfinity(zero(T))
@@ -277,31 +285,31 @@ convert(::Type{ComplexInfinity{T}}, x::RealInfinity) where T = ComplexInfinity{T
277285
convert(::Type{ComplexInfinity}, x::RealInfinity) = ComplexInfinity(x)
278286

279287

280-
sign(y::ComplexInfinity{<:Integer}) = mod(y.angle,2) == 0 ? 1 : -1
281-
angle(x::ComplexInfinity) = π*x.angle
288+
sign(y::ComplexInfinity{<:Integer}) = mod(y.signbit,2) == 0 ? 1 : -1
289+
angle(x::ComplexInfinity) = π*x.signbit
282290
mod(::ComplexInfinity{<:Integer}, ::Integer) = NotANumber()
283291

284292

285293
show(io::IO, x::ComplexInfinity) = print(io, "$(exp(im*π*x.angle))")
286294

287-
==(x::ComplexInfinity, y::Infinity) = x.angle == 0
288-
==(y::Infinity, x::ComplexInfinity) = x.angle == 0
289-
==(x::ComplexInfinity, y::RealInfinity) = x.angle == signbit(y)
290-
==(y::RealInfinity, x::ComplexInfinity) = x.angle == signbit(y)
291-
==(x::ComplexInfinity, y::ComplexInfinity) = x.angle == y.angle
295+
==(x::ComplexInfinity, y::Infinity) = x.signbit == 0
296+
==(y::Infinity, x::ComplexInfinity) = x.signbit == 0
297+
==(x::ComplexInfinity, y::RealInfinity) = x.signbit == signbit(y)
298+
==(y::RealInfinity, x::ComplexInfinity) = x.signbit == signbit(y)
299+
==(x::ComplexInfinity, y::ComplexInfinity) = x.signbit == y.angle
292300

293301
==(x::ComplexInfinity, y::Number) = isinf(y) && angle(y) == angle(x)
294302
==(y::Number, x::ComplexInfinity) = x == y
295303

296-
isless(x::ComplexInfinity{Bool}, y::ComplexInfinity{Bool}) = x.angle && !y.angle
304+
isless(x::ComplexInfinity{Bool}, y::ComplexInfinity{Bool}) = x.signbit && !y.angle
297305
isless(x::Number, y::ComplexInfinity{Bool}) = !y.angle && x  ∞
298-
isless(x::ComplexInfinity{Bool}, y::Number) = x.angle && y  -
306+
isless(x::ComplexInfinity{Bool}, y::Number) = x.signbit && y  -
299307

300308
-(y::ComplexInfinity{B}) where B<:Integer = sign(y) == 1 ? ComplexInfinity(one(B)) : ComplexInfinity(zero(B))
301309

302310
function +(x::ComplexInfinity, y::ComplexInfinity)
303311
x == y || throw(ArgumentError("Angles must be the same to add ∞"))
304-
promote_type(typeof(x),typeof(y))(x.angle)
312+
promote_type(typeof(x),typeof(y))(x.signbit)
305313
end
306314

307315
+(x::ComplexInfinity, y::Infinity) = x+ComplexInfinity(y)

0 commit comments

Comments
 (0)