Integer-Calculation with 24 decimals?

Peter M. Brigham pmbrig at gmail.com
Fri Nov 16 09:24:10 EST 2012


On Nov 13, 2012, at 10:41 AM, R. Hillen wrote:

> I have to do a lot of calculations like 1234516789012345678901234 mod 97;  (always 24 decimals)
> 
> IntegerCalculation in LC with 24 decimals doesn´t work valide.
> 
> Does anyone of you know of an external function or a mathematical trick or … 

Break it down into to 2 shorter strings. This works because you can do all arithmetical operations on the modulo values.

function bigMod bigNumber, modWhat
put length(bigNumber) into tLen
put char 1 to (tLen div 2) of bigNumber into m1
put char (tLen div 2)+1 to -1 of bigNumber into m2
put length(m2) into tPower
put m1 mod modWhat into mm1
put (mm1 * (10^tPower)) mod modWhat into mm1
put m2 mod modWhat into mm2
return (mm1 + mm2) mod modWhat
end bigMod

I tested this technique on smaller numbers and it seems to work.

-- Peter

Peter M. Brigham
pmbrig at gmail.com
http://home.comcast.net/~pmbrig





More information about the use-livecode mailing list