From 3fc38cc212bd9ced150466d06628bc63aa6a0b00 Mon Sep 17 00:00:00 2001 From: Sacha Verweij Date: Sun, 8 Jan 2017 15:55:42 -0800 Subject: [PATCH] Make isimag return false for real numbers that are zero. --- base/complex.jl | 3 ++- test/complex.jl | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/base/complex.jl b/base/complex.jl index 75dc72d6bdf07f..803b323282f65a 100644 --- a/base/complex.jl +++ b/base/complex.jl @@ -92,7 +92,8 @@ isreal(z::Complex) = iszero(imag(z)) Test whether `z` is purely imaginary, i.e. has a real part equal to 0. """ -isimag(z::Number) = iszero(real(z)) +isimag(z::Real) = false +isimag(z::Complex) = iszero(real(z)) isinteger(z::Complex) = isreal(z) & isinteger(real(z)) isfinite(z::Complex) = isfinite(real(z)) & isfinite(imag(z)) isnan(z::Complex) = isnan(real(z)) | isnan(imag(z)) diff --git a/test/complex.jl b/test/complex.jl index bb9aa2d0e7a020..ef6d70eef8e3fc 100644 --- a/test/complex.jl +++ b/test/complex.jl @@ -969,3 +969,6 @@ end # issue #19240 @test big(1)/(10+10im) ≈ (5-5im)/big(100) ≈ big"0.05" - big"0.05"*im + +# Test that isimag yields false for real numbers that are zero +@test !isimag(0)