Skip to content

Commit

Permalink
Add /(::Rational, ::Complex) method.
Browse files Browse the repository at this point in the history
This was needlessly casting to floats before.
  • Loading branch information
StefanKarpinski committed Jan 24, 2011
1 parent 2119a0a commit 93710f3
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions complex.j
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,14 @@ inv(z::Complex) = conj(z)/norm(z)
-(z::Complex) = Complex(-z.re, -z.im)
+(z::Complex, w::Complex) = Complex(z.re + w.re, z.im + w.im)
-(z::Complex, w::Complex) = Complex(z.re - w.re, z.im - w.im)
*(z::Complex, w::Complex) = Complex(z.re*w.re - z.im*w.im,
z.re*w.im + z.im*w.re)
*(z::Complex, w::Complex) = Complex(z.re * w.re - z.im * w.im,
z.re * w.im + z.im * w.re)

==(z::Complex, w::Complex) = (z.re == w.re && z.im == w.im)

/(z::Number, w::Complex) = z*inv(w)
/(z::Complex, x::Real) = Complex(z.re/x, z.im/x)
/(x::Rational, z::Complex) = inv(z/x)

function /(a::Complex, b::Complex)
are = a.re; aim = a.im; bre = b.re; bim = b.im
Expand Down

0 comments on commit 93710f3

Please sign in to comment.