Skip to content

Commit

Permalink
Explicitly list types in iszero test (#20028)
Browse files Browse the repository at this point in the history
* Add a method for iszero(::Rational)

* Explicitly list types in iszero test
  • Loading branch information
ararslan authored and tkelman committed Jan 15, 2017
1 parent ce5a62a commit cf99703
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
2 changes: 2 additions & 0 deletions base/rational.jl
Original file line number Diff line number Diff line change
Expand Up @@ -398,3 +398,5 @@ end
function ^{T<:Rational}(z::Complex{T}, n::Integer)
n >= 0 ? power_by_squaring(z,n) : power_by_squaring(inv(z),-n)
end

iszero(x::Rational) = iszero(numerator(x))
13 changes: 9 additions & 4 deletions test/numbers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2867,14 +2867,19 @@ end

@testset "iszero" begin
# Numeric scalars
for T in Iterators.flatten(subtypes.([AbstractFloat, Signed, Unsigned]))
for T in [Float16, Float32, Float64, BigFloat,
Int8, Int16, Int32, Int64, Int128, BigInt,
UInt8, UInt16, UInt32, UInt64, UInt128]
@test iszero(T(0))
@test iszero(Complex{T}(0))
if T <: Integer
@test iszero(Rational{T}(0))
elseif T <: AbstractFloat
@test iszero(T(-0.0))
@test iszero(Complex{T}(-0.0))
end
end
@test iszero(BigFloat(0))
@test !iszero(nextfloat(BigFloat(0)))
@test iszero(BigInt(0))
@test iszero(0//1)

# Array reduction
@test !iszero([0, 1, 2, 3])
Expand Down

1 comment on commit cf99703

@nanosoldier
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Executing the daily benchmark build, I will reply here when finished:

@nanosoldier runbenchmarks(ALL, isdaily = true)

Please sign in to comment.