Add custom overloads for rem(x,y,::RoundingMode) for FixedDecimals#53
Add custom overloads for rem(x,y,::RoundingMode) for FixedDecimals#53NHDaly wants to merge 2 commits intonhd-explicit-base-extendingfrom
Conversation
However, the simple overload does not seem to work, since it is
ambiguous with `rem(x,y,::RoundingMode{Up})`, for example, so for `rem`,
we're manually overloading all RoundingModes.
|
@TotalVerb I originally added the straightforward method, below, but it gave a MethodAmbiguity error: julia> Base.rem(x::T, y::T, r::RoundingMode) where {T <: FD} = reinterpret(T, rem(x.i, y.i, r))julia> rem(x, x, RoundUp)
ERROR: MethodError: rem(::FixedDecimal{Int64,2}, ::FixedDecimal{Int64,2}, ::RoundingMode{:Up}) is ambiguous. Candidates:
rem(x::T, y::T, r::RoundingMode) where T<:FixedDecimal in Main at REPL[20]:1
rem(x, y, ::RoundingMode{:Up}) in Base at div.jl:69
Possible fix, define
rem(::T, ::T, ::RoundingMode{:Up}) where T<:FixedDecimalSo i implemented all the more specific methods instead. This actually leads me to wonder whether we should be doing the And in fact, the generic definition of Those defs are here: I'm wondering if we're not supposed to be overloading three-argument |
|
Additionally, one other concern: The default 3-arg julia> @which rem(FD2(0.5), FD2(2), RoundToZero)
rem(x::T, y::T, r::RoundingMode{:ToZero}) where T<:FixedDecimal in FixedPointDecimals at /Users/daly/julia-dev/FixedPointDecimals/src/FixedPointDecimals.jl:302
julia> @which rem(FD2(0.5), 2, RoundToZero)
rem(x, y, ::RoundingMode{:ToZero}) in Base at div.jl:67 |
|
This seems to be an unfortunate inconsistency within Julia itself (where the |
Apply PR Review suggestion from @omus.
Okay yeah, makes sense. Then i'm going to put this PR on hold until such time as it's resolved in Base? |
|
That sounds reasonable to me. Thanks for your hard work!
…On Sun., Apr. 19, 2020, 12:10 Nathan Daly, ***@***.***> wrote:
If the # TODO resolves in Base, then we will need to implement something
like this PR, but until then I suppose it is not needed.
Okay yeah, makes sense. Then i'm going to put this PR on hold until such
time as it's resolved in Base?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#53 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ADCOMBXYG6UR3PNOBURUGWDRNMO7TANCNFSM4KOV7M3Q>
.
|
However, the simple overload does not seem to work, since it is
ambiguous with
rem(x,y,::RoundingMode{Up}), for example, so forrem,we're manually overloading all RoundingModes.