Fibonacci vs. C
Bignums
One shortcoming in C/C++ is the absence of any facility for extended-precision math. Interpreted languages such as Python seem to have good support for arbitrary precision, and Java has a Bignum class which provides a reasonable level of functionality. For C and C++ programmers sticking to the standard libarry, sorry, no help available. You’re usually stuck with the native precision of your machine, generally 32 or 64 bits these days. You can squeak out a bit more by storing integers in floating point numbers, but you’re still going to bump into the ceiling on problems that generate a lot of digits.
I ran into this shortcoming recently when looking at problem 25 at Project Euler. In short, it asks:
What is the first term in the Fibonacci sequence to contain 1000 digits?
Now, writing a Fibonacci function in C is easy enough:
Related Reading
More Insights
| To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy. | |

