1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

examples/fibonacci: stop before overflowing and use u64

This commit is contained in:
ath3 2019-10-30 12:54:38 +01:00 committed by Alexander Medvednikov
parent ba6cc5df2a
commit 9abbfa7862

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