Schafkopf-Server/Sources/App/Extensions/Power.swift

21 lines
427 B
Swift
Raw Permalink Normal View History

2021-12-01 22:48:10 +01:00
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
}
}