Fast Fibonacci

by Ricardo Fernández Serrata

Version 2 (March 2, 2021)

Download (5 downloads)

Computes Nth Fib. number in O(1) (constant time). It uses the rounding method because the alternative expression {(pow(phi, n) - pow(1 - phi, n)) / rt5} returns some non-integer results because of IEEE 754 issues.

Theoretically, the alternative expression should be more accurate than the expression used here, but this algorithm is optimized for speed and float precision, not accuracy.

Never use this to generate an array of the Fib sequence, because it will be slower than computing simple additions. But if you want an unsorted array of Fib numbers with some missing values, you should use this because it computes faster by avoiding recursion and loops

4.0 average rating from 1 reviews

5 stars
4 stars
3 stars
2 stars
1 star

Reviews and ratings can be submitted in the app.