Generalized Generator of Gigantic Fibonacci numbers.
We've got you covered! Not that you can see it with your small eyes, but it makes an impression by overflowing your text buffer.
Try our product!
There actually exists a mathematical relation:
∃ GFib(x) ∀ k∈Z ( [k ≥ 0 ⇒ GFib(k) = Fib(k)] ∧ [k < 0 ⇒ GFib(k) = NFib(k)] ∧ [GFib(k+2) = GFib(k+1)+GFib(k)] ), where:
- Fib –– Fibonacci –– Classic Fibonacci function
- GFib –– GeneralFibonacci –– Generalized Fibonacci function
- NFib –– Negabonacci –– Fibonacci accepting Negative indexes
dotnet run <Fibonacci index>
The Fibonacci index can be any integer.
- Positive indices return the corresponding Fibonacci number.
- Negative indices return the corresponding Negabonacci number.
-
Negative Indexing: Fibonacci numbers for negative indices follow the pattern: F(-n) = (-1)^(n+1) × F(n) .
This means:- F(-1) = 1
- F(-2) = -1
- F(-3) = 2
-
Large Numbers: This implementation uses
BigInteger
to handle very large Fibonacci numbers. For example, Fibonacci(1,000,000) can be computed without overflow issues. -
Performance: Matrix exponentiation is used for efficient computation, making it feasible to calculate Fibonacci numbers for very large indices quickly.
- Speed: Efficient computation using matrix exponentiation.
- Accuracy: Gives correct output even for integers of very large absolute value.
- Flexibility: Computes Fibonacci numbers for both positive and negative indices.
Feel free to fork this project, submit issues, and make pull requests. For major changes, please open an issue first to discuss what you would like to change.
This project is licensed under the MIT License - see the LICENSE.txt file for details.
Inspired by the classical Fibonacci sequence and its mathematical beauty.
For any inquiries, please contact tomasz_nehring@outlook.com.