How can I make the exponentiation operator **
in Swift behave the same as in other programming languages.
The question Exponentiation operator in Swift has the following answer which has the highest number of up votes,
infix operator ** { associativity left precedence 170 }
func ** (num: Double, power: Double) -> Double{
return pow(num, power)
}
However, y = -x**2
,
- is interpreted as
(-x)**2 = 4.0
(Swift) - usually it should be interpreted as
-(x**2) = -4.0
(Expected!)