Created
October 4, 2020 02:15
-
-
Save SergeyTLV/61ba74b575a5aa6e69d766e458e4ff46 to your computer and use it in GitHub Desktop.
Saved from https://stackoverflow.com/questions/24196689/how-to-get-the-power-of-some-integer-in-swift-language
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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