fixed size integer arithmetic

Martin d Anjou point14 at magma.ca
Wed Aug 29 16:12:12 CEST 2007


> If you are looking to emulate roll-over the same way that unsigned
> integer arithmetic is handled in a standard CPU, then you can just use
> the modular arithmetic functions and set your modulus to be an
> appropriate power of 2.

Yes this is what I need, but the sizes are not always powers of 2. Is this 
possible with GMP?

Martin

> For example unsigned 64-bit integer arithmetic on every CPU that I can 
> think of is effectively just arithmetic modulo 2^64.  If you want to 
> work only with 1024 bit unsigned integers, then just perform your 
> arithmetic modulo 2^1024.
>
> Is that what you were asking?
>
> --jason
>
>
> --09-F9-11-02-9D-74-E3-5B-D8-41-56-C5-63-56-88-C0--
> Jason Worth Martin
> Asst. Prof. of Mathematics
> James Madison University
> http://www.math.jmu.edu/~martin
> phone: (+1) 540-568-5101
> fax: (+1) 540-568-6857
>
> "Ever my heart rises as we draw near the mountains.
> There is good rock here." -- Gimli, son of Gloin
>
>
> ----------------------------------------------------------------------------------
>
> Message: 1
> Date: Tue, 28 Aug 2007 23:22:52 -0400 (EDT)
> From: point14 at magma.ca
> Subject: fixed size integer arithmetic
> To: gmp-discuss at swox.com
> Message-ID:
>       <Pine.LNX.4.64.0708282250520.9717 at ordimartin.mda.zapto.org>
> Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed
>
> 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?
>
> Thanks,
> Martin
>
>


More information about the gmp-discuss mailing list