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

added iszero #305

Merged
merged 1 commit into from
Jan 14, 2017
Merged
Show file tree
Hide file tree
Changes from all 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
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,11 @@ Currently, the `@compat` macro supports the following syntaxes:
* `transcode` converts between UTF-xx string encodings in Julia 0.5 (as a lightweight
alternative to the LegacyStrings package) ([#17323])

* `∘` (typically used infix as `f ∘ g`) for function composition can be used in 0.5 and earlier. [#17155](https://github.com/JuliaLang/julia/pull/17155)
* `∘` (typically used infix as `f ∘ g`) for function composition can be used in 0.5 and earlier ([#17155])

* The method of `!` to negate functions (typically used as a unary operator, as in `!isinteger`) can be used in 0.5 and earlier. [#17155](https://github.com/JuliaLang/julia/pull/17155)
* The method of `!` to negate functions (typically used as a unary operator, as in `!isinteger`) can be used in 0.5 and earlier ([#17155]).

* `iszero(x)` efficiently checks whether `x == zero(x)` (including arrays) can be used in 0.5 and earlier ([#19950]).

## Renamed functions

Expand Down Expand Up @@ -266,6 +268,7 @@ includes this fix. Find the minimum version from there.
[#16563]: https://github.com/JuliaLang/julia/issues/16563
[#16603]: https://github.com/JuliaLang/julia/issues/16603
[#16972]: https://github.com/JuliaLang/julia/issues/16972
[#17155]: https://github.com/JuliaLang/julia/issues/17155
[#17302]: https://github.com/JuliaLang/julia/issues/17302
[#17323]: https://github.com/JuliaLang/julia/issues/17323
[#17510]: https://github.com/JuliaLang/julia/issues/17510
Expand All @@ -275,3 +278,4 @@ includes this fix. Find the minimum version from there.
[#18977]: https://github.com/JuliaLang/julia/issues/18977
[#19088]: https://github.com/JuliaLang/julia/issues/19088
[#19246]: https://github.com/JuliaLang/julia/issues/19246
[#19950]: https://github.com/JuliaLang/julia/issues/19950
8 changes: 8 additions & 0 deletions src/Compat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1708,6 +1708,14 @@ if !isdefined(Base, :numerator)
export numerator, denominator
end

# julia #19950
if !isdefined(Base, :iszero)
iszero(x) = x == zero(x)
iszero(x::Number) = x == 0
iszero(x::AbstractArray) = all(iszero, x)
export iszero
end

# julia#19088
if VERSION < v"0.6.0-dev.1256"
Base.take!(io::Base.AbstractIOBuffer) = takebuf_array(io)
Expand Down
16 changes: 16 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1560,6 +1560,22 @@ let str = randstring(20)
@test filter(!islower, str) == replace(str, r"[a-z]", "")
end

# julia#19950, tests from Base (#20028)
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))
end
if T<:AbstractFloat
@test iszero(T(-0.0))
@test iszero(Complex{T}(-0.0))
end
end
@test !iszero([0, 1, 2, 3])
@test iszero([0, 0, 0, 0])

x = view(1:10, 2:4)
D = Diagonal(x)
@test D[1,1] == 2
Expand Down