1001Ferramentas
🌀 Dev

Fibonacci Generator (first N)

Generate the first N Fibonacci numbers using BigInt for overflow-free output. Useful for didactics, algorithm testing and series analysis.

Gera os N primeiros termos da sequência de Fibonacci usando BigInt — sem overflow.

Total: · Último termo:

The Fibonacci sequence, without losing precision

Each term is the sum of the two before it: 0, 1, 1, 2, 3, 5, 8, 13. Leonardo of Pisa presented it in 1202 as a problem about breeding rabbits, but the pattern shows up far beyond that — in the arrangement of sunflower seeds, in plant branching, in shell spirals. The reason is that the ratio between consecutive terms converges to the golden ratio, which solves efficient packing problems.

Choose how many terms you want and the page generates the sequence. The implementation detail that matters: the numbers are computed with arbitrary-precision integers. The fiftieth term already exceeds 12 billion, and the seventy-ninth exceeds the largest integer a regular JavaScript number represents exactly — from there on, a naive implementation starts returning wrong values with no warning.

Watch out for an indexing trap: some people start counting at 0 and others at 1. This page starts at 0, which is the more common mathematical convention and the one making the closed formula work directly. If you are checking against another source and every value seems shifted by one position, that is almost always why.

Frequently asked questions

How does it relate to the golden ratio?
The ratio of a term to the previous one gets ever closer to phi, roughly 1.618. By the tenth term the approximation is right to three decimals. There is even a closed formula, Binet's, computing any term directly from phi — except it involves irrationals and loses precision in floating point exactly where you need it most.
Why does arbitrary precision matter here?
Because the sequence grows exponentially. Term 79 passes the exact-integer limit in floating point, and from there every sum accumulates error. With arbitrary precision, term 200 comes out exact — 42 digits, all correct.
Does the sequence really appear in nature?
It appears in specific contexts and with a good deal of exaggeration in popular accounts. The solid case is phyllotaxis: the number of spirals in sunflowers and pine cones tends to be a Fibonacci term, because the golden angle spreads seeds without overlap. Nautilus shells and human body proportions are much looser associations than commonly claimed.

Related Tools