# Small numbercial analysis question

1. Aug 6, 2004

### DrKareem

I was doing a small numbercal analysis problem that required the use of huge numbers. At first i was surprised that my code didn't work, even after double and triple checking, and after tracing the programme, i found out the mistake that i did. Firstly i used integers, and when the numbers started to increase they went bigger than the integer number range on C++ and started to give a negative number. Anyways, i used long and it worked ok for most of the numbers that needed calculations, but still some iteration couldn't be done since they also went out of range.

How could i solve this problem?

2. Aug 6, 2004

### Kludgy

Wow, well in the case of integers it is a simpler problem. Extending floating point datatypes is more complicated.

It is not so hard to create a larger integer class as long as you follow the same bitwise rules than intrinsic integer types follow. And the basic arithmetic operators can be overriden in C++ to make it pretty transparent.

But to save you some trouble, there are many C++ numerics libraries out there that have already done this. Try starting with "c++ numerics library" in google.

I can't speak for any of them because I haven't used them before.

3. Aug 6, 2004

### DrKareem

Thx, will do.

Still open to more suggestions though :)

4. Aug 6, 2004

### rgrig

Are 64 bits enough for you? If so then use long long (with g++) or __int64 (with VS); or their unsigned counterparts. Otherwise a quick solution might be to switch to Java and use the library class BigInteger.

5. Aug 6, 2004

### robphy

Do you require these huge numbers to be integers? If not, then maybe "double" or "long double" is better.

Otherwise, as others suggest, you might need some Big Integer support, e.g.,
http://mysite.verizon.net/mccutchen/bigint/
http://www.swox.com/gmp/ [Broken]
http://www.apfloat.org/apfloat/

(I haven't tried any of these myself.)

Last edited by a moderator: May 1, 2017
6. Aug 6, 2004

Last edited: Aug 6, 2004
7. Aug 10, 2004

### DrKareem

I'm thankful. It hasn't occured to me to use Java, which i will be doing, and for educational purposed i'll also check out and test the links grady and robphy gave.

8. Aug 11, 2004

### gnome

If you don't have to work in Unix, get ubasic (free download) from
http://www.simtel.net/category.php?id=299 [Broken]

It comes "ready to go" with built-in capability to handle integers and rational numbers up to 2600 DIGITS long, plus other impressive features.

Last edited by a moderator: May 1, 2017