(12C) Modulo (the remainder after division )

01092018, 06:03 AM
(This post was last modified: 01092018 07:04 AM by Gamo.)
Post: #1




(12C) Modulo (the remainder after division )
The modulo operation finds the remainder after division of one number by another.
Example: X ENTER Y R/S 6 MOD 4 = 2 7 MOD 4 = 3 1235 MOD 25 = 10 91596 MOD 123 = 84 456654 MOD 104 = 94 Special one: 98765 MOD 43210 = 12345 Program: Code:
With this small program I do not see Round Off Error yet. Gamo 

01092018, 09:32 AM
(This post was last modified: 01092018 09:45 AM by Dieter.)
Post: #2




RE: (12C) Modulo (the remainder after division )
(01092018 06:03 AM)Gamo Wrote: The modulo operation finds the remainder after division of one number by another. There is more than you see in FIX 2. ;) 7 mod 3 => 0,99999999 20 mod 7 => 5,999999999 200 mod 9 => 1,999999980 1E+9 mod 6 => 4,2 Or take you own examples: 91596 mod 123 => 82,99999640 456654 mod 104 => 93,99998400 98765 mod 43210 => 12344,99999 You could add 0,4 + INTG to round the results to an integer which would help in most cases. But this limits the output to integers so that 123 mod 2,5 = 0,5 cannot be calculated. And in a way this also is like cheating. ;) As already noted, using b*frac(a/b) is not a good idea at all as it causes the shown roundoff errors. A better method is a – b*int(a/b). However, this requires some more steps if you want to preserve the stack: Code: 01 X<>Y This calculates all above examples correctly. All these methods are limited by cases where due to limited precision a/b is returned as an integer although it actually is not. Example: With 10digit precision 8E+9 / 3 = 2666666667 so that the modulus is returned as 0 (frac method) or –1 (int method) instead of 2. Dieter 

01102018, 06:44 AM
(This post was last modified: 01102018 06:45 AM by Gamo.)
Post: #3




RE: (12C) Modulo (the remainder after division )
Thank You Dieter
Your program algorithm is very precise. Gamo 

02152018, 05:15 AM
Post: #4




RE: (12C) Modulo (the remainder after division )
Another MOD program for 12C
Code:
Example: MOD (156511533, 1546223) 156511533 ENTER 1546223 R/S result 343010 Gamo 

12052019, 12:03 PM
(This post was last modified: 12062019 04:31 AM by Gamo.)
Post: #5




RE: (12C) Modulo (the remainder after division )
This little MOD function routine must be the perfect one of all, I hope.
Procedure: x mod y = remainder X [ENTER] Y [R/S] display Answer Program: Code:
Example: 98765 mod 4321 98765 [ENTER] 4321 [R/S] display 3703 Gamo 

12052019, 12:36 PM
Post: #6




RE: (12C) Modulo (the remainder after division )
Although that routine is very short, it suffers from roundoff error. It even gets the answer wrong for your example (as can be seen if you set FIX 9, as Dieter pointed out previously in this thread). The 10step routine you posted previously gets the correct answer.
<0ɸ0> Joe 

« Next Oldest  Next Newest »

User(s) browsing this thread: 1 Guest(s)