Whoops, that version didn't work. Try this version instead:

####

abstract ExtendedComplex{T<:Real}

immutable ComplexInf{T<:Real} <: ExtendedComplex{T} end

immutable FiniteExtendedComplex{T<:Real} <: ExtendedComplex{T}
    z :: Complex{T}
end

function FiniteExtendedComplex{T<:Real}(r::T, i::T)
    if isfinite(r) && isfinite(i)
        return FiniteExtendedComplex(Complex(r, i))
    else
        return ComplexInf{T}()
    end
end

import Base./

function /{T}(z:: ComplexInf{T}, w:: FiniteExtendedComplex{T})
    return z
end

function /{T}(z:: FiniteExtendedComplex{T}, w:: ComplexInf{T})
    return zero(z)
end

function /{T}(z:: FiniteExtendedComplex{T}, w:: FiniteExtendedComplex{T})
    a = z.z/w.z
    return isfinite(a) ? FiniteExtendedComplex(a) : ComplexInf{T}()
end

Reply via email to