Hacker News new | ask | show | jobs
by MrRage 4243 days ago
I always thought the fastest was the closed form formula: http://en.wikipedia.org/wiki/Fibonacci_number#Closed-form_ex...

Unless looping and counting is that much faster than doing some floating point math?

2 comments

Only "faster" because you precompute digits of the golden ratio, and will quickly become inaccurate unless you compute more of them
The closed form will become inaccurate at some point. However, there is a way to calculate Fibonacci accurately with O(log(n)) time (ignoring the time to multiply - otherwise O(M(n) log(n)) where M(n) is the time to multiply two numbers of n digits).