examples/fibonacci: stop before overflowing and use u64

pull/2592/head
ath3 2019-10-30 12:54:38 +01:00 committed by Alexander Medvednikov
parent ba6cc5df2a
commit 9abbfa7862
1 changed files with 9 additions and 3 deletions

View File

@ -14,10 +14,16 @@ fn main() {
// Parse first argument and cast it to int
stop := os.args[1].int()
// Can only calculate correctly until rank 92
if stop > 92 {
println('rank must be 92 or less')
return
}
// Three consecutive terms of the sequence
mut a := i64(0)
mut b := i64(0)
mut c := i64(1)
mut a := u64(0)
mut b := u64(0)
mut c := u64(1)
for i := 0; i < stop; i++ {
// Set a and b to the next term