mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
21 lines
397 B
Swift
21 lines
397 B
Swift
// RUN: %swift -i %s | FileCheck %s
|
|
// REQUIRES: swift_interpreter
|
|
|
|
def computeCountLeadingZeroes(x : Int) -> Int {
|
|
var r = 64
|
|
while (x != 0) {
|
|
x >>= 1
|
|
r--
|
|
}
|
|
return r
|
|
}
|
|
|
|
def testeCountLeadingZeroes() {
|
|
for var i = 1; i < 1000; i++ {
|
|
assert(countLeadingZeros(i) == computeCountLeadingZeroes(i))
|
|
}
|
|
}
|
|
|
|
testeCountLeadingZeroes()
|
|
println("done!") // CHECK: {{^done!$}}
|