-
-
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
Missing RoundFromZero support for three-arg div with RoundingMode #34519
Comments
CC: @Keno |
good catch |
Note that the |
We can edit the docstring to reflect additional type coverage, when available. |
Would that do it? function Base.div(x::T, y::T, ::typeof(RoundFromZero)) where T<:Integer
sx = sign(x)
sy = sign(y)
d = div(sx*x, sy*y, RoundUp)
return sx*sy*d
end It might even be possible to drop the restriction to Integer entirely. Edit: won't work for typemin :/ function Base.div(x::T, y::T, ::typeof(RoundFromZero)) where T<:Integer
sx = sign(x)
sy = sign(y)
d = div(-sx*x, -sy*y, RoundUp)
return sx*sy*d
end |
perhaps
|
why is that let block important & do we really have to make that ifelse an external function? |
There is no need to make the ifelse external .. I did that because it kept the code clearer, cleaner to me, as I worked through variations. I found the let block ran somewhat faster (5%). It is not necessary, though, and when broadcasting over vectors this version is just as fast.
|
Why doesn't Julia include support for
When compiled with "-O3", it seems quite fast (only around 40% slower than RoundToZero 15% slower than RoundNearestTiesUp):
Maybe, if this method was compiled into Julia, it could be as fast as the other rounding methods. |
Tried this other version and it runs faster (performance similar to
|
@admin would you create a new issue by splitting off the previous question @jessymilare ? Her question is a good one that we have discussed in the past, although I found no issue about adding support for RoundFromZero as a floating point rounding mode. |
Fixed by #41246 |
It looks like maybe this rounding mode was missed when support for three-arg
div
was added in #33040?:https://github.com/JuliaLang/julia/pull/33040/files#diff-b1fc87557f78879f66387487c7a02689R203-R213
The text was updated successfully, but these errors were encountered: