Skip to content

Commit

Permalink
Clean up Complex Rational division.
Browse files Browse the repository at this point in the history
  • Loading branch information
simonbyrne authored and mfasi committed Sep 5, 2016
1 parent 5f9d43f commit bc01951
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
16 changes: 4 additions & 12 deletions base/rational.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,9 @@ function //(x::Rational, y::Rational)
checked_mul(xn,yd)//checked_mul(xd,yn)
end

//(x::Complex, y::Real ) = complex(real(x)//y,imag(x)//y)
function //(x::Number, y::Complex)
xr = complex(Rational(real(x)),Rational(imag(x)))
yr = complex(Rational(real(y)),Rational(imag(y)))
xr // yr
end
function //{Ra<:Rational,Rb<:Rational}(x::Complex{Ra}, y::Complex{Rb})
xy = x*y'
yy = real(y*y')
complex(real(xy)//yy, imag(xy)//yy)
end
//(x::Complex, y::Real) = complex(real(x)//y,imag(x)//y)
//(x::Number, y::Complex) = x*y'//abs2(y)


//(X::AbstractArray, y::Number) = X .// y
.//(X::AbstractArray, y::Number) = reshape([ x // y for x in X ], size(X))
Expand Down Expand Up @@ -196,7 +188,7 @@ function *(x::Rational, y::Rational)
checked_mul(xn,yn) // checked_mul(xd,yd)
end
/(x::Rational, y::Rational) = x//y
/(x::Rational, z::Complex ) = inv(z/x)
/{T<:Union{Integer,Rational}}(x::Rational, y::Complex{T}) = x//y

fma(x::Rational, y::Rational, z::Rational) = x*y+z

Expand Down
6 changes: 6 additions & 0 deletions test/numbers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2756,3 +2756,9 @@ testmi(typemax(UInt32)-UInt32(1000):typemax(UInt32), map(UInt32, 1:100))
@test indices(1) == ()
@test indices(1,1) == 1:1
@test_throws BoundsError indices(1,-1)

# issue #15920
@test Rational(0, 1) / Complex(3, 2) == 0

# issue #16282
@test_throws MethodError 3 // 4.5im

0 comments on commit bc01951

Please sign in to comment.