-
Notifications
You must be signed in to change notification settings - Fork 22
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
Add custom overloads for rem(x,y,::RoundingMode) for FixedDecimals #53
base: nhd-explicit-base-extending
Are you sure you want to change the base?
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<:FixedDecimal So 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.