Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
|
|
@ -0,0 +1,18 @@
|
|||
func raise<T: Numeric>(_ base: T, to exponent: Int) -> T {
|
||||
precondition(exponent >= 0, "Exponent has to be nonnegative")
|
||||
return Array(repeating: base, count: exponent).reduce(1, *)
|
||||
}
|
||||
|
||||
infix operator **: MultiplicationPrecedence
|
||||
|
||||
func **<T: Numeric>(lhs: T, rhs: Int) -> T {
|
||||
return raise(lhs, to: rhs)
|
||||
}
|
||||
|
||||
let someFloat: Float = 2
|
||||
let someInt: Int = 10
|
||||
|
||||
assert(raise(someFloat, to: someInt) == 1024)
|
||||
assert(someFloat ** someInt == 1024)
|
||||
assert(raise(someInt, to: someInt) == 10000000000)
|
||||
assert(someInt ** someInt == 10000000000)
|
||||
Loading…
Add table
Add a link
Reference in a new issue