02-06-2019, 07:15 PM
02-06-2019, 09:26 PM
Any concrete use case?
In general see the 50g advanced user reference pdf . Page 3-150
If you put x on level2 and y on level1 and then you use MOD you get: x mod y.
In general see the 50g advanced user reference pdf . Page 3-150
If you put x on level2 and y on level1 and then you use MOD you get: x mod y.
02-07-2019, 05:21 AM
pier4r's reference gives this information:
Just in case you don't have the Advanced manual.
AURM is available here:
https://www.hpcalc.org/details/7141
Code:
Modulo Function: Returns a remainder defined by: x mod y = x – y floor (x/y)
Mod (x, y) is periodic in x with period y. Mod (x, y) lies in the interval [0, y) for y > 0 and in (y, 0]
for y < 0.
Algebraic syntax: argument 1 MOD argument 2
Just in case you don't have the Advanced manual.
AURM is available here:
https://www.hpcalc.org/details/7141
02-07-2019, 08:22 AM
Arithmetic Modulo commands
ADDTMOD ........................... 3-9
DIVMOD ........................... 3-63
DIV2MOD .......................... 3-62
EXPANDMOD ........................ 3-80
FACTORMOD ........................ 3-83
GCDMOD ........................... 3-96
INVMOD .......................... 3-120
MOD ............................. 3-150
MODSTO .......................... 3-150
MULTMOD ......................... 3-153
POWMOD .......................... 3-175
SUBTMOD ......................... 3-243
Maybe the question is more about these commands?
Best would be to come up with an example that you need explained.
Cheers
Thomas
ADDTMOD ........................... 3-9
DIVMOD ........................... 3-63
DIV2MOD .......................... 3-62
EXPANDMOD ........................ 3-80
FACTORMOD ........................ 3-83
GCDMOD ........................... 3-96
INVMOD .......................... 3-120
MOD ............................. 3-150
MODSTO .......................... 3-150
MULTMOD ......................... 3-153
POWMOD .......................... 3-175
SUBTMOD ......................... 3-243
Maybe the question is more about these commands?
Best would be to come up with an example that you need explained.
Cheers
Thomas
02-07-2019, 01:20 PM
Quote:Modulo Function: Returns a remainder defined by: x mod y = x – y floor (x/y)
Although it is defined this way, it cannot be calculated same way.
My guess is there is an algorithm to reduce x a bit at a time, like this ?
123e45 mod 12345 ≡ 123e9 * 1e36 ≡ 12285e7 * 1e29 ≡ 4035e8 * 1e21 ≡ 8535e8 * 1e13 ≡ 6810e8 * 1e5 ≡ 270e5 ≡ 1485
Or, reduce exponents, like this ?
123e45 mod 12345 ≡ 1e11^4 * 1230 ≡ 6475^4 * 1230 ≡ 2005^2 * 1230 ≡ 7900 * 1230 ≡ 1485
Reducing exponents way look faster, but may get into overflow issue.
02-07-2019, 02:42 PM
The 50g's POWMOD command uses the CAS variable MODULO for the modulus. Joe Horn posted a program for another calculator (the Prime, I think) that accepts a user-input modulus but I can't find it at the moment. Here is my 50g version:
Input is x, y, m to return (x^y) mod m.
Code:
\<< PUSH CASDIR MODULO \-> M
\<< MODSTO POWMOD
IF DUP 0 <
THEN MODULO +
END M MODSTO POP
\>>
\>>
Input is x, y, m to return (x^y) mod m.