Fixed size arithmatics
Basel Alomair
alomair at u.washington.edu
Wed Jul 1 02:15:42 CEST 2009
Greetings all,
I need to perform fixed size arithmetic (addition and multiplication) on unsigned integers. For example, I want to define three 128-bit integers, a, b, and c. When I do c=a*b, I want multiplication to abort whatever beyond the 128th bit. I know I can use modular operations to get the right result, but efficiency is a factor in my code. The problem with GMP is that when I define a 128-bit integer as
mpz_init2(sum1, 128);
the variable “sum1” will grow automatically, if necessary. But I want the result to always stay within 128 bits, without using the modular operation.
Basically, I want something similar to basic C. When I identify three unsigned long integers a, b, and c; c=a*b will always be a 32-bit integer.
I appreciate your help,
Basel
More information about the gmp-discuss
mailing list