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

Explicitly list types in iszero test #20028

Merged
merged 2 commits into from
Jan 15, 2017
Merged

Conversation

ararslan
Copy link
Member

This addresses @tkelman's comment in #19950 (comment). I've restructured the iszero tests such that the types are explicitly listed out. I've also consolidated more of the other tests into the loop.

for T in [Float16, Float32, Float64, BigFloat,
Int8, Int16, Int32, Int64, Int128, BigInt,
UInt8, UInt16, UInt32, UInt64, UInt128,
Rational]
Copy link
Member

Choose a reason for hiding this comment

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

This makes me realize that we could use iszero(x::Rational) = iszero(x.num), which saves a comparison compared to the fallback method that does == 0

Copy link
Member

@stevengj stevengj Jan 14, 2017

Choose a reason for hiding this comment

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

Rather than including Rational in this list, I would check iszero(Rational{T}(0)) if T <: Integer in the loop.

for T in [Float16, Float32, Float64, BigFloat,
Int8, Int16, Int32, Int64, Int128, BigInt,
UInt8, UInt16, UInt32, UInt64, UInt128,
Rational]
@test iszero(T(0))
@test iszero(Complex{T}(0))
Copy link
Member

@stevengj stevengj Jan 14, 2017

Choose a reason for hiding this comment

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

If T<:AbstractFloat, we should also check iszero(T(-0.0)) and iszero(Complex{T}(-0.0))

@ararslan
Copy link
Member Author

Great ideas, @stevengj! I've incorporated the changes mentioned in your comments. Thanks!

@ararslan ararslan added the test This change adds or pertains to unit tests label Jan 14, 2017
@ararslan
Copy link
Member Author

How are things looking now?

@tkelman tkelman merged commit cf99703 into JuliaLang:master Jan 15, 2017
@ararslan ararslan deleted the aa/iszero-test branch January 15, 2017 04:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
test This change adds or pertains to unit tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants