I want to use **
to overload an exponent function. I works if I use something like "^" but the python way of doing is **
and I would like to use that with Swift. Any way to do that?
error: Operator implementation without matching operator declaration
@infix func ** (num: Double, power: Double) -> Double{
return pow(num, power)
}
println(8.0**3.0) // Does not work
^
works as intended? I've only got it to act as an addition:println(1^2) == 3
– Cawnpore^
is the Bitwise XOR Operator.1^2
is just coincidentally equal to1+2
. Please see The Swift Programming Language, Language Guide -> Advanced Operators -> Bitwise XOR Operator. – Sangsanger^
does not act as an exponent. I think I was wrong and misread the question, which suggests that he could overload^
in Swift to act as a caret, but he wanted to use**
, which was not working when trying to overload. – Cawnpore