Skip to content

round(::Float128, ::RoundingMode{:Nearest}) not implemented #93

Open
@jwortmann

Description

@jwortmann
julia> using Quadmath

julia> x = Float128(1.3)
1.30000000000000004440892098500626162e+00

julia> floor(Int, x)
1

julia> ceil(Int, x)
2

julia> round(Int, x)
ERROR: MethodError: no method matching round(::Float128, ::RoundingMode{:Nearest})
This error has been manually thrown, explicitly, so the method may exist but be intentionally marked as unimplemented.

Closest candidates are:
  round(::Real, ::RoundingMode; digits, sigdigits, base)
   @ Base floatfuncs.jl:50
  round(::Type{T}, ::Any, ::RoundingMode) where T>:Missing
   @ Base missing.jl:148
  round(::Type{T}, ::Any, ::RoundingMode) where T
   @ Base rounding.jl:479
  ...

Stacktrace:
 [1] round(x::Float128, r::RoundingMode{:Nearest}; digits::Nothing, sigdigits::Nothing, base::Nothing)
   @ Base .\floatfuncs.jl:56
 [2] round(x::Float128, r::RoundingMode{:Nearest})
   @ Base .\floatfuncs.jl:50
 [3] round(::Type{Int64}, x::Float128, r::RoundingMode{:Nearest})
   @ Base .\rounding.jl:479
 [4] round(::Type{Int64}, x::Float128)
   @ Base .\rounding.jl:477
 [5] top-level scope
   @ REPL[8]:1

Is the ::RoundingMode{:Nearest} intentionally not implemented, or is it just an oversight?

Quadmath.jl/src/Quadmath.jl

Lines 341 to 343 in f6ea87e

round(x::Float128, r::RoundingMode{:Down}) = floor(x)
round(x::Float128, r::RoundingMode{:Up}) = ceil(x)
round(x::Float128, r::RoundingMode{:ToZero}) = round(x)

It seems to work if I copy the implementation from line 343:

julia> Base.round(x::Float128, r::RoundingMode{:Nearest}) = round(x)

julia> round(Int, x)
1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions