dankogai/swift-complex

Support sqrt

fulldecent opened this issue · 3 comments

sqrt() has been supported since the beginning.

x% make repl
xcrun -sdk macosx swiftc -emit-library -emit-module complex/complex.swift complex/exops.swift -module-name Complex
swift -I. -L. -lComplex
Welcome to Apple Swift version 2.1.1 (swiftlang-700.1.101.15 clang-700.1.81). Type :help for assistance.
  1> import Complex
  2> sqrt(-1.0+0.0.i)
$R0: Complex.Complex<Double> = {
  re = 0
  im = 1
}
  3> sqrt(0.0+1.0.i)
$R1: Complex.Complex<Double> = {
  re = 0.70710678118654757
  im = 0.70710678118654757
}
  4>  

Ah sorry, I see it is a standalone function, not a member function.

It is deliberately so since Double (and Float) does not have .sqrt() even after import Foundation.