Fast Fibonacci

by Ricardo “Rudxain” Fernández Serrata

Version 5 (December 1, 2022)

Download (38 downloads)

Calculates Nth Fib. number in O(1). Supports negatives! (extended)

It uses rounding because Binet's Formula returns some non-integer results, and it's generalized to work with Complex numbers (which AM doesn't support natively)

The subroutine is optimized for speed and float precision, not accuracy, not generalized functions.

Never use this to generate an array of the Fib sequence, because it'll be slower than summation. But if you want an unsorted array of Fib numbers with some missing values, you should use this, because it avoids recursion and loops.

For even faster speed, pre-compute `SQRT5` (to avoid sqrt calls at runtime), and inline it (to avoid latency of block-execution in the Variable-Set). To go even further, remove the subroutine-block and inline the var-set `out` block

4.0 average rating from 1 reviews

5 stars
4 stars
3 stars
2 stars
1 star

Rate and review within the app in the Community section.