Skip to content

Commit

Permalink
RFC: Export iszero (#19950)
Browse files Browse the repository at this point in the history
* Export and test Base.iszero
  • Loading branch information
ararslan authored and stevengj committed Jan 10, 2017
1 parent 0316883 commit 512339b
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 0 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ Library improvements
* `logging` can be used to redirect `info`, `warn`, and `error` messages
either universally or on a per-module/function basis ([#16213]).

* New `iszero(x)` function to quickly check whether `x` is zero (or is all zeros, for an array) ([#19950]).

Compiler/Runtime improvements
-----------------------------

Expand Down
1 change: 1 addition & 0 deletions base/exports.jl
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,7 @@ export
isreal,
isimag,
issubnormal,
iszero,
lcm,
ldexp,
leading_ones,
Expand Down
1 change: 1 addition & 0 deletions doc/src/stdlib/numbers.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ Base.issubnormal
Base.isfinite
Base.isinf
Base.isnan
Base.iszero
Base.nextfloat
Base.prevfloat
Base.isinteger
Expand Down
16 changes: 16 additions & 0 deletions test/numbers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2864,3 +2864,19 @@ let types = (Base.BitInteger_types..., BigInt, Bool)
end

@test !isempty(complex(1,2))

@testset "iszero" begin
# Numeric scalars
for T in Iterators.flatten(subtypes.([AbstractFloat, Signed, Unsigned]))
@test iszero(T(0))
@test iszero(Complex{T}(0))
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])
@test iszero(zeros(Int, 5))
end

0 comments on commit 512339b

Please sign in to comment.