fixed size integer arithmetic

Evan Lavelle sa212+gmp at cyconix.com
Thu Aug 30 17:02:12 CEST 2007


point14 at magma.ca wrote:
> Hello,
> 
> Is it possible in GMP to have the size of integers (like mpz_t) to be 
> fixed in size and invariant (eg, a fixed number of bits) as well as being 
> arbitrarily large?
> 
> I mean once it's declared or initialized to be of a certain size, the size 
> no longer changes, and arithmetic operations (add, mul, etc) that would 
> normaly grow the number would simply cause it to roll over.
> 
> Is this possible with GMP and if not, do you have suggestions?

I looked at this some time ago, and went through maybe 6 different 
libraries to get this functionality, and looked in some detail at ltm 
and gmp. My conclusion - possibly incorrect - is that there's nothing 
obvious out there which does this for you. The whole structure of ltm 
(which I reverse-engineered in detail) and gmp (which I looked at in 
less detail) is geared to maintaining precision where you get bit 
growth. Fixed-precision is a completely different mindset and is not of 
interest to number-theoretic people.

I had to roll my own in the end, which was about a month's work; the 
main complication was actually getting a good C++ front-end. You may 
also find that you need to write some simple variable-precision 
multiplication and addition code to scan integers if you don't know the 
input precision in advance.

HTH

Evan


More information about the gmp-discuss mailing list