Do you have some sort of key to that thread? I'd like to keep it for
future reference
Is this what you are looking for?
XL: MOD() Function Returns #NUM! Error Value
http://support.microsoft.com/kb/119083/en-us
The reason math programs use PowerMod is that a call like this:
Mod(81703396 ^ 81703396, 23)
would require an intermediate calculation of an exact integer with over
646,000,000 digits in it.
However, it's a very fast calculation via code.
?PowerMod(81703396, 81703396, 23)
4
--
Dana DeLouis
"Niek Otten" wrote in message
...
<MOD function works with double precision integers, but has some
surprising limitations that have been documented in earlier
threads
I thought I remembered that, but I couldn't find it using Google's Group
search.
Do you have some sort of key to that thread? I'd like to keep it for
future reference
--
Kind regards,
Niek Otten
Microsoft MVP - Excel
"Jerry W. Lewis" wrote in message
...
| VBA mod is limited to numbers that can be coerced to the Long type.
Thus
| anything greater than 2.147483647E+09 will overflow. In particular,
your
| original function would fail for general problems mod 162653, since
| 162652*162652 = 2.65E+10.
|
| The worksheet MOD function works with double precision integers, but has
| some surprising limitations that have been documented in earlier
threads.
| You can either "roll your own" mod function (the most robust approach)
or use
| the VBA Evaluate() function to access the worksheet MOD function.
|
| Jerry
|
| "Equiangular" wrote:
|
| Hi Jerry,
|
| I implemented the code according to your idea
|
| Function BigMod2(base As Long, power As Long, divisor As Long) As Long
|
| Dim temp As Long
|
| If power = 1 Then
| BigMod2 = base Mod divisor
| ElseIf power Mod 2 = 0 Then ' even power
| temp = BigMod2(base, power \ 2, divisor)
| BigMod2 = temp * temp Mod divisor
| Else ' odd power
| temp = BigMod2(base, power \ 2, divisor)
| BigMod2 = (((temp * temp) Mod divisor) * base) Mod divisor
| End If
|
| End Function
|
| However, I got #VALUE! error for 13^271 mod 162653
| It fails when calculating 13^33 mod 162653
|
| as 13^16 mod 162653 = 75280
| so 75280 * 75280 mod 162653 = 5667078400 mod 162653
| but 5667078400 2^31-1
|
| Actually my original solution also encounters such error for cases
like
| 65535^2 mod 65536
|
| Jerry W. Lewis wrote:
| Two additional approaches that you could consider:
|
| The simplest approach is to download Maxima from
| http://maxima.sourceforge.net/index.shtml
| and use it to directly calculate mod(13^271,162653);
|
| Or you could note that =Mod(13^5,162653) returns 45987,
| so that 152516 =Mod(45987^2) is equivalent to =Mod(13^10,162653)
| hence 124726 =Mod(152516^2) is equivalent to =Mod(13^20,162653)
| ...
| this accelerates the process used by Equiangular's algorithm.
|
| Jerry
|
| "Diogo" wrote:
|
| Need to calculate via Excel:
|
| mod(13^271;162653)
|
| Any thoughts????
|
| Thanks
|