|
55 | 55 | Base.iszero(x::FixedRational) = iszero(x.num)
|
56 | 56 | Base.isone(x::F) where {F<:FixedRational} = x.num == denom(F)
|
57 | 57 | 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} = |
62 | 63 | let
|
63 | 64 | isinteger(x) || throw(InexactError(:convert, I, x))
|
64 | 65 | convert(I, div(x.num, denom(F)))
|
65 | 66 | 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 | + |
66 | 73 | Base.round(::Type{T}, x::F, r::RoundingMode=RoundNearest) where {T,F<:FixedRational} = div(convert(T, x.num), convert(T, denom(F)), r)
|
67 | 74 | Base.decompose(x::F) where {T,F<:FixedRational{T}} = (x.num, zero(T), denom(F))
|
68 | 75 |
|
|
0 commit comments