Question

What is the easiest way to handle huge numbers in C? I need to store values in the Area 1000^900...

Does anybody know of an easy way to do that? Any help would really be appreciated!

Was it helpful?

Solution

Use libgmp:

GMP is a free library for arbitrary precision arithmetic, operating on signed integers, rational numbers, and floating-point numbers. There is no practical limit to the precision except the ones implied by the available memory in the machine GMP runs on...

Since version 6, GMP is distributed under the dual licenses, GNU LGPL v3 and GNU GPL v2...

GMP's main target platforms are Unix-type systems, such as GNU/Linux, Solaris, HP-UX, Mac OS X/Darwin, BSD, AIX, etc. It also is known to work on Windows in both 32-bit and 64-bit mode...

OTHER TIPS

There are a few libraries to help you do this (arbitrary precision mathematics):

Assuming this isn't work related (ie you're doing it for fun or its a hobby or just an oportunity to learn something), coding up a library for arbitrary precision maths is a relatively interesting project. But if you need to absolutely rely on it and aren't interested in the nuts and bolts just use a library.

There are a number of libraries for handling huge numbers around. Do you need integer or floating point arithmetic?

You could look at the code built into Python for the task.

You could look at the extensions for Perl for the task.

You could look at the code in OpenSSL for the task.

You could look at the GNU MP (multi-precision) library - as mentioned by kmkaplan.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top