formatting source-code for c7ff9d66f1

This commit is contained in:
github-actions 2020-06-24 17:14:57 +00:00
parent c7ff9d66f1
commit 4c6b3b86c1

View File

@ -19,7 +19,7 @@
#include <cstdio> #include <cstdio>
#include <iostream> #include <iostream>
/** /**
* maximum number that can be computed - The result after 93 cannot be stored * maximum number that can be computed - The result after 93 cannot be stored
* in a `uint64_t` data type. * in a `uint64_t` data type.
*/ */
@ -28,16 +28,19 @@
/** Algorithm */ /** Algorithm */
uint64_t fib(uint64_t n) { uint64_t fib(uint64_t n) {
static uint64_t f1 = 1, f2 = 1; // using static keyword will retain the values of f1 and f2 for the next function call. static uint64_t f1 = 1,
f2 = 1; // using static keyword will retain the values of
// f1 and f2 for the next function call.
if (n <= 2) if (n <= 2)
return f2; return f2;
if (n >= 93) { if (n >= 93) {
std::cerr << "Cannot compute for n>93 due to limit of 64-bit integers\n"; std::cerr
<< "Cannot compute for n>93 due to limit of 64-bit integers\n";
return 0; return 0;
} }
uint64_t temp = f2; // we do not need temp to be static uint64_t temp = f2; // we do not need temp to be static
f2 += f1; f2 += f1;
f1 = temp; f1 = temp;