Below is the answer to the original question of how to add a power operator for Int
numbers:
infix operator ^^ { associativity left precedence 160 }
func ^^ (radix: Int, power: Int) -> Int {
return Int(pow(CGFloat(radix), CGFloat(power)))
}
How would one generalise this so that it works for Double
, Float
, and Int
?