Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RFC: Export iszero #19950

Merged
merged 3 commits into from
Jan 10, 2017
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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]).

* `iszero` is now exported from `Base` ([#19950]).
Copy link
Member

Choose a reason for hiding this comment

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

This assumes that people already know what this function is.

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

Copy link
Member Author

Choose a reason for hiding this comment

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

Much, much better. I've gone with that. Thanks!


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]))
Copy link
Contributor

@tkelman tkelman Jan 14, 2017

Choose a reason for hiding this comment

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

these types should probably just be written out - there's a type SOE.Sgnd defined in the core test that causes a failure here if it runs in the same worker

@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