I created this infix operator ^^
as a substitute to using the pow
function:
infix operator ^^ { associativity left precedence 155 }
func ^^ <T: IntegerLiteralConvertible>(left: T, right: T) -> T {
return pow(left as Double, right as Double)
}
I used the IntegerLiteralConvertible
protocol as a type constraint for the generics left
and right
, because from my understanding this diagramm shows, that it basically includes all number types.
In order to use the pow
function I have to downcast left
and right
to Double
though, which I did using the as
operator. It's not the safest approach, but that's besides the point.
When implementing the function this way swift tells me:
<stdin>:4:12: error: cannot invoke 'pow' with an argument list of type '(Double, Double)'
return pow(left as Double, right as Double)
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Now as far as I know pow
takes two Double
s as parameters, so why is it complaining about this?