fixed size integer arithmetic

Richard B. Kreckel kreckel at
Mon Sep 3 00:02:18 CEST 2007

I suppose you guys are talking about modular arithmetic, right?

Evan Lavelle wrote:
> point14 at 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.

Did you try CLN <>? CLN is not C, though. It is C++.

(I may mention that in CLN the modulus (called "invariant" above) is a 
dynamic attribute of the class, not determined at compile time. IOW: 
different moduli are not different C++ types and mismatches cause 
runtime errors.)

Richard B. Kreckel

More information about the gmp-discuss mailing list