Complex number
Quick tips

  Jan 25, 2016 -   read
  swift, complexNumber

Since a complex number is comprised of a real and imaginary component, two complex numbers are equal if and only if their respective real and imaginary components are equal.

Complex number

Complex.swift

struct Complex<T: SignedNumberType> {
    let real: T
    let imaginary: T
}
extension Complex: Equatable {}

// MARK: Equatable

func ==<T>(lhs: Complex<T>, rhs: Complex<T>) -> Bool {
    return lhs.real == rhs.real && lhs.imaginary == rhs.imaginary
}
Suraj Pathak
Swift Brewer