Hacker News new | past | comments | ask | show | jobs | submit login

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?




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).




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: