-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Use iszero and isone in MPFR #23322
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
Use iszero and isone in MPFR #23322
Conversation
@@ -275,7 +275,7 @@ big(::Type{<:AbstractFloat}) = BigFloat | |||
function convert(::Type{Rational{BigInt}}, x::AbstractFloat) | |||
if isnan(x); return zero(BigInt)//zero(BigInt); end | |||
if isinf(x); return copysign(one(BigInt),x)//zero(BigInt); end | |||
if x == 0; return zero(BigInt) // one(BigInt); end | |||
if iszero(x); return zero(BigInt) // one(BigInt); end |
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.
Perhaps nix the extra spaces and/or restore alignment with the preceding lines?
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.
I have another PR that changes this, which will conflict anyways. So I prefer to see one merge first before making any additional changes.
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.
lgtm modulo the minor comments! :)
I don't have anything against this patch (actually, I'm in favor of it), but on Julia 0.6 I see a fairly different benchmark result: julia> x = BigFloat(0)
0.000000000000000000000000000000000000000000000000000000000000000000000000000000
julia> @btime iszero($x)
9.517 ns (0 allocations: 0 bytes)
true
julia> f(x) = x == 0
f (generic function with 1 method)
julia> @btime f($x)
9.763 ns (0 allocations: 0 bytes)
true (is BenchmarkTools still broken on master?) |
@giordano My benchmarks used the commit right before BenchmarkTools broke on master |
On 952dc93, on my machine: julia> x = BigFloat(0)
0.000000000000000000000000000000000000000000000000000000000000000000000000000000
julia> @btime iszero($x)
9.453 ns (0 allocations: 0 bytes)
true
julia> f(x) = x == 0
f (generic function with 1 method)
julia> @btime f($x)
9.167 ns (0 allocations: 0 bytes)
true |
maybe we should run the BigFloat benchmarks here |
@nanosoldier |
Your benchmark job has completed - no performance regressions were detected. A full report can be found here. cc @ararslan |
No allocations and is faster