Skip to content

round(pi, base=10) broken #28160

Closed
Closed

Description

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)))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    bugIndicates an unexpected problem or unintended behavior

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions