long long int 
Author Message
 long long int

I suppose this is a bit off-topic, but you guys know your way around C,
and what I'm after has to be ANSI C compliant source code.

Does anyone have any advice on the best approach to handling integers
larger than 2^31?  I've been using doubles to extend the range of
numbers I can handle, but I recently learned the hard way that this is
not a secure way to deal with these big numbers.  The loss of precision
caused a recursive routine to never reach its terminal condition.  It
was a booger to debug.  I've implemented a work around to trap the
condition and prevent the program stack overflow, but the real fix is
to do this with extremely large integers.

Any good extended int math libraries?  I actually don't need much
functionality other than the arithmetic operators (+, -, *, /) and
comparison operators (==, >, <, >=, <=).  I'll trade functionality to
gain portability if it come to that.  I could write these functions
myself, but surely someone else has done this better than I could.

2^127 would be larger than anything I'll encounter.

Sent via Deja.com http://www.*-*-*.com/
Share what you know. Learn what you don't.



Tue, 26 Feb 2002 03:00:00 GMT  
 long long int

Quote:

> I suppose this is a bit off-topic, but you guys know your way around C,
> and what I'm after has to be ANSI C compliant source code.

> Does anyone have any advice on the best approach to handling integers
> larger than 2^31?


For ANSI-C compliant source code the only portable solution is to use a
self defined data type with corresponding math functions for all
operations you want to perform. There are a number of math packages
available that implement integer data type of an arbitrary precision. The
best one known to me is the MIRACL large integer package at:  
http://indigo.ie/~mscott/

Quote:
> I've been using doubles to extend the range of
> numbers I can handle, but I recently learned the hard way that this is
> not a secure way to deal with these big numbers.

Yes, and one important reason is that ANSI-C only guaranties a DBL_DIG
value of 10. A value of 15 (for DBL_DIG) is quite typical, but not
mandatory, and therefore not portable.

Stephan
(initiator of the campaign against grumpiness in c.l.c)



Tue, 26 Feb 2002 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. char size (was long long long long long int)

2. typecasting int to long long int

3. long long int

4. long long int into octets (and back again)

5. long long int

6. unsigned long long int

7. Assigning and printing long long int's

8. long long int

9. long long long long integers

10. long int versus long

11. Help! INT longer than LONG

12. Handling very large integers without "long long int"

 

 
Powered by phpBB® Forum Software