Skip to content

Instantly share code, notes, and snippets.

@SergeyTLV
Created October 4, 2020 02:15
Show Gist options
  • Save SergeyTLV/61ba74b575a5aa6e69d766e458e4ff46 to your computer and use it in GitHub Desktop.
Save SergeyTLV/61ba74b575a5aa6e69d766e458e4ff46 to your computer and use it in GitHub Desktop.
precedencegroup PowerPrecedence { higherThan: MultiplicationPrecedence }
infix operator ^^ : PowerPrecedence
func ^^ (radix: Int, power: Int) -> Int {
return Int(pow(Double(radix), Double(power)))
}
// ...
// Then you can do this...
let i2 = 2 ^^ 3
// ... or
print("2³ = \(2 ^^ 3)") // Prints 2³ = 8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment