Skip to content

Commit a123e68

Browse files
authored
Remove one of the redundant round definitions; add test coverage (#113)
1 parent 515934e commit a123e68

File tree

3 files changed

+8
-7
lines changed

3 files changed

+8
-7
lines changed

src/FixedPointDecimals.jl

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ for fn in [:trunc, :floor, :ceil]
297297
val = _apply_exact_float($(Symbol(fn, "mul")), T, x, powt)
298298
reinterpret(FD{T, f}, val)
299299
end
300-
# needed to avoid ambiguity
300+
# needed to avoid ambiguity with e.g. `floor(::Type{T}, x::Rational)`
301301
@eval function Base.$fn(::Type{FD{T, f}}, x::Rational) where {T, f}
302302
reinterpret(FD{T, f}, $fn(T, x * coefficient(FD{T, f})))
303303
end
@@ -309,15 +309,12 @@ function Base.round(::Type{FD{T, f}}, x::Real, ::RoundingMode{:Nearest}=RoundNea
309309
reinterpret(FD{T, f}, round(T, x * coefficient(FD{T, f})))
310310
end
311311

312-
# needed to avoid ambiguity
313-
function Base.round(::Type{FD{T, f}}, x::Rational, ::RoundingMode{:Nearest}=RoundNearest) where {T, f}
314-
reinterpret(FD{T, f}, round(T, x * coefficient(FD{T, f})))
315-
end
312+
# needed to avoid ambiguity with `round(::Type{T}, x::Rational{Bool}, ::RoundingMode)`
316313
function Base.round(::Type{FD{T, f}}, x::Rational{Bool}, ::RoundingMode{:Nearest}=RoundNearest) where {T, f}
317-
reinterpret(FD{T, f}, round(T, x * coefficient(FD{T, f})))
314+
reinterpret(FD{T, f}, round(T, x * coefficient(FD{T, f})))
318315
end
319316
function Base.round(::Type{FD{T, f}}, x::Rational{Tr}, ::RoundingMode{:Nearest}=RoundNearest) where {T, f, Tr}
320-
reinterpret(FD{T, f}, round(T, x * coefficient(FD{T, f})))
317+
reinterpret(FD{T, f}, round(T, x * coefficient(FD{T, f})))
321318
end
322319

323320

test/FixedDecimal.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1533,5 +1533,8 @@ end
15331533
@test ceil(FD3, 4//3) == FD3(1.334)
15341534
@test round(FD3, true) == FD3(1.000)
15351535
@test round(FD3, 4//3) == FD3(1.333)
1536+
@test round(FD3, 1 // 1) == FD3(1)
1537+
@test round(FD3, BigInt(1) // 1) == FD3(1)
1538+
@test round(FD3, true // true) == FD3(1)
15361539
@test Bool(FixedDecimal{Int,4}(1))
15371540
end

test/aqua_test.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using Test, FixedPointDecimals
12
@testset "Aqua" begin
23
using Aqua
34
Aqua.test_all(FixedPointDecimals)

0 commit comments

Comments
 (0)