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

round(pi, base=10) broken #28160

Closed
martinholters opened this issue Jul 18, 2018 · 1 comment
Closed

round(pi, base=10) broken #28160

martinholters opened this issue Jul 18, 2018 · 1 comment
Labels
kind:bug Indicates an unexpected problem or unintended behavior

Comments

@martinholters
Copy link
Member

julia> round(pi)
3.0

julia> round(pi, digits=0)
3.0

julia> round(pi, digits=0, base=10)
3.0

julia> round(pi, base=10)
ERROR: MethodError: no method matching round(::Irrational{:π}, ::RoundingMode{:Nearest})
Closest candidates are:
  round(::Irrational, ::RoundingMode) at irrationals.jl:137
  round(::Real, ::RoundingMode; digits, sigdigits, base) at floatfuncs.jl:127
  round(::Number, ::Any) at deprecated.jl:53
  ...
Stacktrace:
 [1] _round(::Irrational{:π}, ::RoundingMode{:Nearest}, ::Nothing, ::Nothing, ::Int64) at ./floatfuncs.jl:137
#...

The error is a straight lie:

julia> round(pi, RoundingMode{:Nearest}())
3.0

Explicitly thrown here:

julia/base/floatfuncs.jl

Lines 136 to 137 in b6a60dd

# if we hit this method, it means that no `round(x, r)` method is defined
_round(x::Real, r::RoundingMode, digits::Nothing, sigdigits::Nothing, base) = throw(MethodError(round, (x,r)))

@JeffBezanson JeffBezanson added the kind:bug Indicates an unexpected problem or unintended behavior label Jul 18, 2018
@simonbyrne
Copy link
Contributor

Note that the current docstring doesn't actually mention this as an option. Do we want to allow it, or should we just throw a better error message?

simonbyrne added a commit that referenced this issue Jul 19, 2018
simonbyrne added a commit that referenced this issue Jul 23, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind:bug Indicates an unexpected problem or unintended behavior
Projects
None yet
Development

No branches or pull requests

3 participants