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

Missing round methods for RoundNearest #15115

Closed
iamed2 opened this issue Feb 17, 2016 · 7 comments
Closed

Missing round methods for RoundNearest #15115

iamed2 opened this issue Feb 17, 2016 · 7 comments
Labels
maths Mathematical functions upstream The issue is with an upstream dependency, e.g. LLVM

Comments

@iamed2
Copy link
Contributor

iamed2 commented Feb 17, 2016

A number of round methods which take a RoundingMode do not accept RoundNearest (but do accept the other modes). Evidence:

julia> round(0.5, RoundNearest)
ERROR: MethodError: no method matching round(::Type{Float64}, ::Float64, ::RoundingMode{:Nearest})
Closest candidates are:
  round{T}(::Type{T}, ::Rational{T<:Integer}, ::RoundingMode{:Nearest})
  round{T<:Integer}(::Type{T<:Integer}, ::AbstractFloat, ::RoundingMode{T})
  round{T,R}(::Type{T}, ::AbstractArray{R,1}, ::RoundingMode{T})
  ...
 in eval(::Module, ::Any) at ./boot.jl:267

julia> round(0.5, RoundDown)
0.0

This appears to be the case on 0.4 and master.

The missing methods are round{T<:FloatingPoint}(::T, ::RoundingMode{:Nearest}). There are other methods I found which depend on those, such as round(::Type{Int64}, ::Float64, ::RoundingMode{:Nearest}).

It seems to me like either round(::Number, RoundingMode{:Nearest}) should call round(::Number) or the reverse should be true. If the latter option is preferred, there's a bunch of code overhaul to do, and packages probably have to be updated as well.

@simonbyrne
Copy link
Contributor

Yes, it should. Unfortunately, LLVM doesn't support it, though hopefully they should in future as roundeven is part of the most recent C floating point technical spec: see #8750 (comment) for the full details.

@iamed2
Copy link
Contributor Author

iamed2 commented Feb 17, 2016

Oh, so it functionally can't be done, and round doesn't actually do RoundNearest? If that's the case, why do the docs say that the default is RoundNearest?

@simonbyrne
Copy link
Contributor

round(x) uses the current rounding mode (set via setrounding), which by default is RoundNearest.

@iamed2
Copy link
Contributor Author

iamed2 commented Feb 17, 2016

If I understand correctly, it is impossible to have a RoundNearest rounding mode for floats because there's no way to ensure the correct behaviour other than setting the rounding mode?

@simonbyrne
Copy link
Contributor

Yes, exactly.

@kshyatt
Copy link
Contributor

kshyatt commented May 10, 2016

It seems like this was an issue with the modes LLVM provides, which we can't do much about. I'm going to close this - feel free to reopen if I'm wrong in doing so.

@kshyatt kshyatt closed this as completed May 10, 2016
@kshyatt kshyatt added upstream The issue is with an upstream dependency, e.g. LLVM maths Mathematical functions labels May 10, 2016
@iamed2
Copy link
Contributor Author

iamed2 commented May 10, 2016

I think it would be nice to have a living issue for it, but this isn't it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
maths Mathematical functions upstream The issue is with an upstream dependency, e.g. LLVM
Projects
None yet
Development

No branches or pull requests

3 participants