Files
swift-mirror/test/Interpreter/complex.swift
David Farler b7d17b25ba Rename -parse flag to -typecheck
A parse-only option is needed for parse performance tracking and the
current option also includes semantic analysis.
2016-11-28 10:50:55 -08:00

22 lines
610 B
Swift

// RUN: %target-typecheck-verify-swift
public struct Complex {
public var real = 0.0, imag = 0.0
public func magnitude() -> Double {
return real * real + imag * imag
}
public init() {}
public init(real: Double, imag: Double) {
self.real = real
self.imag = imag
}
}
public func * (lhs: Complex, rhs: Complex) -> Complex {
return Complex(real: lhs.real * rhs.real - lhs.imag * rhs.imag,
imag: lhs.real * rhs.imag + lhs.imag * rhs.real)
}
public func + (lhs: Complex, rhs: Complex) -> Complex {
return Complex(real: lhs.real + rhs.real, imag: lhs.imag + rhs.imag)
}