Skip to content

Commit

Permalink
Merge b585127 into 317c82b
Browse files Browse the repository at this point in the history
  • Loading branch information
NHDaly committed Apr 19, 2020
2 parents 317c82b + b585127 commit cabb421
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
8 changes: 8 additions & 0 deletions src/FixedPointDecimals.jl
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,14 @@ end
for remfn in [:rem, :mod, :mod1, :min, :max]
@eval Base.$remfn(x::T, y::T) where {T <: FD} = reinterpret(T, $remfn(x.i, y.i))
end
if VERSION >= v"1.4.0-"
# TODO: Add support for (RoundFromZero, RoundNearest, RoundNearestTiesAway), which
# aren't supported for Ints.
for R in (RoundToZero, RoundUp, RoundDown)
Base.rem(x::T, y::T, r::typeof(R)) where {T <: FD} = reinterpret(T, rem(x.i, y.i, r))
end
end

# TODO: When we upgrade to a min julia version >=1.4 (i.e Julia 2.0), this block can be
# dropped in favor of three-argument `div`, below.
for divfn in [:div, :fld, :fld1, :cld]
Expand Down
23 changes: 18 additions & 5 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -537,13 +537,26 @@ end
@test one(FD{Int32, 2}) ÷ one(FD{Int64, 6}) isa FD{Int64, 6}
end

@testset "rem with rounding modes" begin
if VERSION >= v"1.4.0-"
# TODO: Test RoundFromZero, RoundNearest, RoundNearestTiesAway
# See: https://github.com/JuliaLang/julia/issues/34519
@testset for x in keyvalues[FD2],
R in (RoundToZero, RoundUp, RoundDown)
@test rem(x, 2one(x), R) === rem(x, 2, R) === reinterpret(FD2, rem(x.i, FD2(2).i, R))
end
end
@testset for x in keyvalues[FD2], f in (fld, cld, fld1, div)
@test f(x, 2one(x)) === f(x, 2) === FD2(f(x.i, FD2(2).i))
end
end

@testset "div with rounding modes" begin
if VERSION >= v"1.4.0-"
@testset for x in keyvalues[FD2]
# TODO: Test RoundFromZero -- https://github.com/JuliaLang/julia/issues/34519
for R in (RoundToZero, RoundUp, RoundDown, RoundNearest, RoundNearestTiesAway)
@test div(x, 2one(x), R) === div(x, 2, R) === FD2(div(x.i, FD2(2).i, R))
end
# TODO: Test RoundFromZero -- https://github.com/JuliaLang/julia/issues/34519
@testset for x in keyvalues[FD2],
R in (RoundToZero, RoundUp, RoundDown, RoundNearest, RoundNearestTiesAway)
@test div(x, 2one(x), R) === div(x, 2, R) === FD2(div(x.i, FD2(2).i, R))
end
end
@testset for x in keyvalues[FD2], f in (fld, cld, fld1, div)
Expand Down

0 comments on commit cabb421

Please sign in to comment.