From 9abbfa7862cca5daf368bf2af424a09c3851f416 Mon Sep 17 00:00:00 2001 From: ath3 <45574139+ath3@users.noreply.github.com> Date: Wed, 30 Oct 2019 12:54:38 +0100 Subject: [PATCH] examples/fibonacci: stop before overflowing and use u64 --- examples/fibonacci.v | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/examples/fibonacci.v b/examples/fibonacci.v index 3cef7cb02f..5976fef4cf 100644 --- a/examples/fibonacci.v +++ b/examples/fibonacci.v @@ -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