fibonacci documentation

This commit is contained in:
Krishna Vedala 2020-05-27 17:58:17 -04:00
parent c27fa436b8
commit 6dfdfa6662
No known key found for this signature in database
GPG Key ID: BA19ACF8FC8792F7
2 changed files with 13 additions and 3 deletions

View File

@ -5,6 +5,8 @@
* Calculate the the value on Fibonacci's sequence given an * Calculate the the value on Fibonacci's sequence given an
* integer as input. * integer as input.
* \f[\text{fib}(n) = \text{fib}(n-1) + \text{fib}(n-2)\f] * \f[\text{fib}(n) = \text{fib}(n-1) + \text{fib}(n-2)\f]
*
* @see fibonacci_large.cpp
*/ */
#include <cassert> #include <cassert>
#include <iostream> #include <iostream>
@ -15,7 +17,8 @@
int fibonacci(unsigned int n) { int fibonacci(unsigned int n) {
/* If the input is 0 or 1 just return the same /* If the input is 0 or 1 just return the same
This will set the first 2 values of the sequence */ This will set the first 2 values of the sequence */
if (n <= 1) return n; if (n <= 1)
return n;
/* Add the last 2 values of the sequence to get next */ /* Add the last 2 values of the sequence to get next */
return fibonacci(n - 1) + fibonacci(n - 2); return fibonacci(n - 1) + fibonacci(n - 2);

View File

@ -1,11 +1,14 @@
/** /**
* Computes N^th Fibonacci number given as * @file
* @brief Computes N^th Fibonacci number given as
* input argument. Uses custom build arbitrary integers library * input argument. Uses custom build arbitrary integers library
* to perform additions and other operations. * to perform additions and other operations.
* *
* Took 0.608246 seconds to compute 50,000^th Fibonacci * Took 0.608246 seconds to compute 50,000^th Fibonacci
* number that contains 10450 digits! * number that contains 10450 digits!
**/ *
* @see fibonacci.cpp
*/
#include <cinttypes> #include <cinttypes>
#include <ctime> #include <ctime>
@ -13,6 +16,10 @@
#include "./large_number.h" #include "./large_number.h"
/** Compute fibonacci numbers using the relation
* \f[f(n)=f(n-1)+f(n-2)\f]
* and returns the result as a large_number type.
*/
large_number fib(uint64_t n) { large_number fib(uint64_t n) {
large_number f0(1); large_number f0(1);
large_number f1(1); large_number f1(1);