-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Conversation
for T in [Float16, Float32, Float64, BigFloat, | ||
Int8, Int16, Int32, Int64, Int128, BigInt, | ||
UInt8, UInt16, UInt32, UInt64, UInt128, | ||
Rational] |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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)) |
There was a problem hiding this comment.
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))
e03d088
to
1a2755a
Compare
Great ideas, @stevengj! I've incorporated the changes mentioned in your comments. Thanks! |
How are things looking now? |
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.