Skip to content

Commit 2eb9378

Browse files
committed
Fix Base.cld() for FixedDecimals.
Before: ```julia julia> let FD2 = FixedDecimal{Int,2} cld(FD2(0.01), FD2(2)) end FixedDecimal{Int64,2}(0.00) ``` After: ```julia julia> let FD2 = FixedDecimal{Int,2} cld(FD2(0.01), FD2(2)) end FixedDecimal{Int64,2}(1.00) ```
1 parent 85ee62e commit 2eb9378

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

src/FixedPointDecimals.jl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -300,12 +300,14 @@ end
300300
for remfn in [:rem, :mod, :mod1, :min, :max]
301301
@eval $remfn(x::T, y::T) where {T <: FD} = reinterpret(T, $remfn(x.i, y.i))
302302
end
303-
for divfn in [:div, :fld, :fld1]
303+
for divfn in [:div, :fld, :fld1, :cld]
304304
# div(x.i, y.i) eliminates the scaling coefficient, so we call the FD constructor.
305305
# We don't need any widening logic, since we won't be multiplying by the coefficient.
306-
@eval $divfn(x::T, y::T) where {T <: FD} = T($divfn(x.i, y.i))
306+
@eval Base.$divfn(x::T, y::T) where {T <: FD} = T($divfn(x.i, y.i))
307307
end
308308
if VERSION >= v"1.4.0-"
309+
# div(x.i, y.i) eliminates the scaling coefficient, so we call the FD constructor.
310+
# We don't need any widening logic, since we won't be multiplying by the coefficient.
309311
Base.div(x::T, y::T, r::RoundingMode) where {T <: FD} = T(div(x.i, y.i, r))
310312
end
311313

test/runtests.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,9 @@ end
545545
end
546546
end
547547
end
548+
@testset for x in keyvalues[FD2], f in (fld, cld, fld1, div)
549+
@test f(x, 2one(x)) === f(x, 2) === FD2(f(x.i, FD2(2).i))
550+
end
548551
end
549552
end
550553

0 commit comments

Comments
 (0)