Function Math.fibonacci
Find the nth Fibonacci number.
-
Syntax
Number Math.fibonacci(Number n )
This function will return the nth Fibonacci number. Calculations are based on the Golden Ratio - not a recursive function - so you can compute Fibonacci for large numbers without a stack overflow or timeout.
-
Parameters
Number n- The number to find the Fibonacci number for. Inputs bigger than ~1470 is likely to produce
Infinity.
- Return value The Fibonacci number of the input.
-
Examples
- To find the Fibonacci number of 20
// Output is 6765 var n = Math.fibonacci(20);
- Resources See the Wikipedia entry at http://en.wikipedia.org/wiki/Fibonacci_number#Relation_to_the_Golden_Ratio for the relation between Fibonacci and the Golden Ratio.
-
Download
Source
Unless otherwise noted all code in the JSLab Standard Library is licensed as GPLv3. See http://www.gnu.org/licenses/gpl.html for the entire license.
