From b3a99ad6b7d98773a10fb84c365790f9cff2415c Mon Sep 17 00:00:00 2001 From: Alex Arslan Date: Mon, 9 Jan 2017 16:05:10 -0800 Subject: [PATCH 1/3] Export and test Base.iszero --- base/exports.jl | 1 + doc/src/stdlib/numbers.md | 1 + test/numbers.jl | 16 ++++++++++++++++ 3 files changed, 18 insertions(+) diff --git a/base/exports.jl b/base/exports.jl index a15267a329604..0020e1120482e 100644 --- a/base/exports.jl +++ b/base/exports.jl @@ -360,6 +360,7 @@ export isreal, isimag, issubnormal, + iszero, lcm, ldexp, leading_ones, diff --git a/doc/src/stdlib/numbers.md b/doc/src/stdlib/numbers.md index 715a8319f9b18..8a6508d0ae326 100644 --- a/doc/src/stdlib/numbers.md +++ b/doc/src/stdlib/numbers.md @@ -67,6 +67,7 @@ Base.issubnormal Base.isfinite Base.isinf Base.isnan +Base.iszero Base.nextfloat Base.prevfloat Base.isinteger diff --git a/test/numbers.jl b/test/numbers.jl index 75e950d2511f7..f260609b25be3 100644 --- a/test/numbers.jl +++ b/test/numbers.jl @@ -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 From 1009821701b8eb120ef3b20a314e0b56c7d84706 Mon Sep 17 00:00:00 2001 From: Alex Arslan Date: Tue, 10 Jan 2017 13:51:55 -0800 Subject: [PATCH 2/3] News item for iszero export [ci skip] --- NEWS.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/NEWS.md b/NEWS.md index 81db6bd8a8609..467f133f97b54 100644 --- a/NEWS.md +++ b/NEWS.md @@ -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]). + * `iszero` is now exported from `Base` ([#19950]). + Compiler/Runtime improvements ----------------------------- From 8b90fb4b24562111e8a91282d274f2cabc79c2ab Mon Sep 17 00:00:00 2001 From: Alex Arslan Date: Tue, 10 Jan 2017 14:01:07 -0800 Subject: [PATCH 3/3] Improve NEWS item wording for iszero [ci skip] --- NEWS.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index 467f133f97b54..4debf14c80e7a 100644 --- a/NEWS.md +++ b/NEWS.md @@ -159,7 +159,7 @@ Library improvements * `logging` can be used to redirect `info`, `warn`, and `error` messages either universally or on a per-module/function basis ([#16213]). - * `iszero` is now exported from `Base` ([#19950]). + * New `iszero(x)` function to quickly check whether `x` is zero (or is all zeros, for an array) ([#19950]). Compiler/Runtime improvements -----------------------------