Skip to content

Commit 09d107a

Browse files
committed
Fix method ambiguity for Bool(::FixedRational)
1 parent 3a43627 commit 09d107a

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/fixed_rational.jl

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,21 @@ end
5555
Base.iszero(x::FixedRational) = iszero(x.num)
5656
Base.isone(x::F) where {F<:FixedRational} = x.num == denom(F)
5757
Base.isinteger(x::F) where {F<:FixedRational} = iszero(x.num % denom(F))
58-
Base.convert(::Type{Rational{R}}, x::F) where {R,F<:FixedRational} = Rational{R}(x.num, denom(F))
59-
Base.convert(::Type{Rational}, x::F) where {F<:FixedRational} = Rational{eltype(F)}(x.num, denom(F))
60-
Base.convert(::Type{AF}, x::F) where {AF<:AbstractFloat,F<:FixedRational} = convert(AF, x.num) / convert(AF, denom(F))
61-
Base.convert(::Type{I}, x::F) where {I<:Integer,F<:FixedRational} =
58+
59+
Rational{R}(x::F) where {R,F<:FixedRational} = Rational{R}(x.num, denom(F))
60+
Rational(x::F) where {F<:FixedRational} = Rational{eltype(F)}(x)
61+
(::Type{AF})(x::F) where {AF<:AbstractFloat,F<:FixedRational} = convert(AF, x.num) / convert(AF, denom(F))
62+
(::Type{I})(x::F) where {I<:Integer,F<:FixedRational} =
6263
let
6364
isinteger(x) || throw(InexactError(:convert, I, x))
6465
convert(I, div(x.num, denom(F)))
6566
end
67+
Bool(x::F) where {F<:FixedRational} =
68+
let
69+
iszero(x) || isone(x) || throw(InexactError(:convert, Bool, x))
70+
return x.num == denom(F)
71+
end
72+
6673
Base.round(::Type{T}, x::F, r::RoundingMode=RoundNearest) where {T,F<:FixedRational} = div(convert(T, x.num), convert(T, denom(F)), r)
6774
Base.decompose(x::F) where {T,F<:FixedRational{T}} = (x.num, zero(T), denom(F))
6875

0 commit comments

Comments
 (0)