Quadmath.jl icon indicating copy to clipboard operation
Quadmath.jl copied to clipboard

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

Open jwortmann opened this issue 8 months ago • 2 comments

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? https://github.com/JuliaMath/Quadmath.jl/blob/f6ea87e58fa4bdf1dfbf4179f91e298c337278ee/src/Quadmath.jl#L341-L343

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

jwortmann avatar Jun 05 '25 16:06 jwortmann