diff --git a/src/FixedPointDecimals.jl b/src/FixedPointDecimals.jl index 9e5e25d..dcef0ed 100644 --- a/src/FixedPointDecimals.jl +++ b/src/FixedPointDecimals.jl @@ -297,7 +297,7 @@ for fn in [:trunc, :floor, :ceil] val = _apply_exact_float($(Symbol(fn, "mul")), T, x, powt) reinterpret(FD{T, f}, val) end - # needed to avoid ambiguity + # needed to avoid ambiguity with e.g. `floor(::Type{T}, x::Rational)` @eval function Base.$fn(::Type{FD{T, f}}, x::Rational) where {T, f} reinterpret(FD{T, f}, $fn(T, x * coefficient(FD{T, f}))) end @@ -309,15 +309,12 @@ function Base.round(::Type{FD{T, f}}, x::Real, ::RoundingMode{:Nearest}=RoundNea reinterpret(FD{T, f}, round(T, x * coefficient(FD{T, f}))) end -# needed to avoid ambiguity -function Base.round(::Type{FD{T, f}}, x::Rational, ::RoundingMode{:Nearest}=RoundNearest) where {T, f} - reinterpret(FD{T, f}, round(T, x * coefficient(FD{T, f}))) -end +# needed to avoid ambiguity with `round(::Type{T}, x::Rational{Bool}, ::RoundingMode)` function Base.round(::Type{FD{T, f}}, x::Rational{Bool}, ::RoundingMode{:Nearest}=RoundNearest) where {T, f} - reinterpret(FD{T, f}, round(T, x * coefficient(FD{T, f}))) + reinterpret(FD{T, f}, round(T, x * coefficient(FD{T, f}))) end function Base.round(::Type{FD{T, f}}, x::Rational{Tr}, ::RoundingMode{:Nearest}=RoundNearest) where {T, f, Tr} - reinterpret(FD{T, f}, round(T, x * coefficient(FD{T, f}))) + reinterpret(FD{T, f}, round(T, x * coefficient(FD{T, f}))) end diff --git a/test/FixedDecimal.jl b/test/FixedDecimal.jl index b1d8528..1a6bf25 100644 --- a/test/FixedDecimal.jl +++ b/test/FixedDecimal.jl @@ -1533,5 +1533,8 @@ end @test ceil(FD3, 4//3) == FD3(1.334) @test round(FD3, true) == FD3(1.000) @test round(FD3, 4//3) == FD3(1.333) + @test round(FD3, 1 // 1) == FD3(1) + @test round(FD3, BigInt(1) // 1) == FD3(1) + @test round(FD3, true // true) == FD3(1) @test Bool(FixedDecimal{Int,4}(1)) end diff --git a/test/aqua_test.jl b/test/aqua_test.jl index 12fda00..f9806a7 100644 --- a/test/aqua_test.jl +++ b/test/aqua_test.jl @@ -1,3 +1,4 @@ +using Test, FixedPointDecimals @testset "Aqua" begin using Aqua Aqua.test_all(FixedPointDecimals)