21 lines
427 B
Swift
21 lines
427 B
Swift
import Foundation
|
|
|
|
precedencegroup PowerPrecedence { higherThan: MultiplicationPrecedence }
|
|
infix operator ^^ : PowerPrecedence
|
|
func ^^ (radix: Int, power: Int) -> Int {
|
|
switch power {
|
|
case Int.min..<0:
|
|
return 0
|
|
case 0:
|
|
return 1
|
|
case 1:
|
|
return radix
|
|
default:
|
|
var result = radix
|
|
for _ in 1..<power {
|
|
result *= radix
|
|
}
|
|
return result
|
|
}
|
|
}
|