Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions base/rational.jl
Original file line number Diff line number Diff line change
Expand Up @@ -421,8 +421,8 @@ function *(x::Bool, y::T)::promote_type(Bool,T) where T<:Rational
return ifelse(x, y, copysign(zero(y), y))
end
*(y::Rational, x::Bool) = x * y
/(x::Rational, y::Union{Rational, Integer, Complex{<:Union{Integer,Rational}}}) = x//y
/(x::Union{Integer, Complex{<:Union{Integer,Rational}}}, y::Rational) = x//y
/(x::Rational, y::Union{Rational, Integer}) = x//y
/(x::Integer, y::Rational) = x//y
inv(x::Rational{T}) where {T} = checked_den(x.den, x.num)

fma(x::Rational, y::Rational, z::Rational) = x*y+z
Expand Down
15 changes: 15 additions & 0 deletions test/rational.jl
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,21 @@ end
end

@test Rational(rand_int, 3)/Complex(3, 2) == Complex(Rational(rand_int, 13), -Rational(rand_int*2, 39))
@test (1//1) / complex(0, 1) === 0//1 - 1//1*im
@test (0//1) / complex(0, 1) === 0//1 + 0//1*im
@test (0//1) / complex(1, 0) === 0//1 + 0//1*im
@test (0//1) / complex(1, 1) === 0//1 + 0//1*im
@test (1//1) / complex(1, 1) === 1//2 - 1//2*im
@test (0//1) / complex(1//1, 1//1) === 0//1 + 0//1*im
@test (1//1) / complex(1//1, 1//1) === 1//2 - 1//2*im
@test (0//1) / complex(1//0, 0//1) === 0//1 + 0//1*im
@test (1//1) / complex(1//1, 1//0) === 0//1 + 0//1*im
@test_throws DivideError (0//1) / complex(0, 0)
@test_throws DivideError (1//1) / complex(0, 0)
@test_throws DivideError (1//0) / complex(0, 0)

# 1//200 - 1//200*im cannot be represented as Complex{Rational{Int8}}
@test_throws OverflowError (Int8(1)//Int8(1)) / (Int8(100) + Int8(100)im)

@test Complex(rand_int, 0) == Rational(rand_int)
@test Rational(rand_int) == Complex(rand_int, 0)
Expand Down