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. | |
Best of the Web
First C Compiler Now on Github
The earliest known C compiler by the legendary Dennis Ritchie has been published on the repository.
HTML5 Mobile Development: Seven Good Ideas (and Three Bad Ones)
HTML5 Mobile Development: Seven Good Ideas (and Three Bad Ones)
Building Bare Metal ARM Systems with GNU
All you need to know to get up and running... and programming on ARM
Amazon's Vogels Challenges IT: Rethink App Dev
Amazon Web Services CTO says promised land of cloud computing requires a new generation of applications that follow different principles.
How to Select a PaaS Partner
Eventually, the vast majority of Web applications will run on a platform-as-a-service, or PaaS, vendor's infrastructure. To help sort out the options, we sent out a matrix with more than 70 decision points to a variety of PaaS providers.

