Skip to content

Commit 85ee62e

Browse files
committed
Add support for three-arg div to FixedDecimals in Julia 1.4+.
This commit simply implements `div(x,y,::RoundingMode)` for FixedDecimals by delegating to `div` of the fields.
1 parent c9c4686 commit 85ee62e

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

src/FixedPointDecimals.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,9 @@ for divfn in [:div, :fld, :fld1]
305305
# We don't need any widening logic, since we won't be multiplying by the coefficient.
306306
@eval $divfn(x::T, y::T) where {T <: FD} = T($divfn(x.i, y.i))
307307
end
308+
if VERSION >= v"1.4.0-"
309+
Base.div(x::T, y::T, r::RoundingMode) where {T <: FD} = T(div(x.i, y.i, r))
310+
end
308311

309312
convert(::Type{AbstractFloat}, x::FD) = convert(floattype(typeof(x)), x)
310313
function convert(::Type{TF}, x::FD{T, f}) where {TF <: AbstractFloat, T, f}

test/runtests.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,16 @@ end
536536

537537
@test one(FD{Int32, 2}) ÷ one(FD{Int64, 6}) isa FD{Int64, 6}
538538
end
539+
540+
@testset "div with rounding modes" begin
541+
if VERSION >= v"1.4.0-"
542+
@testset for x in keyvalues[FD2]
543+
for R in (RoundUp, RoundDown, RoundNearest, RoundNearestTiesAway)
544+
@test div(x, 2one(x), R) === div(x, 2, R) === FD2(div(x.i, FD2(2).i, R))
545+
end
546+
end
547+
end
548+
end
539549
end
540550

541551
@testset "abs, sign" begin

0 commit comments

Comments
 (0)