Modulus Function
Description
By Eddie Shore, January 2016 (Eddie's Math and Calculator Blog)
Input:
Enter A
Enter B
f B
The program calculates A mod B.
Formula Used:
A mod B = B·frac(A/B)
Add B to result if A·B < 0
.
Examples:
A = 48, B = 3, result = 0
A = 41.3, B = 12, result = 5.3
A = 48, B = -7, result = -1
A = -50.2, B = 36, result = 21.8
Program Resources
Labels
Name |
Description |
|
B |
calculate Y mod X |
|
1 |
recall Y mod X |
|
Storage Registers
Name |
Description |
|
1 |
value A |
|
2 |
value B |
|
3 |
A mod B |
|
Program
Line |
Display |
Key Sequence |
|
000 |
|
|
|
001 |
42,21,12 |
f LBL B |
|
002 |
44 2 |
STO 2 |
|
003 |
34 |
x↔y |
|
004 |
44 1 |
STO 1 |
|
005 |
34 |
x↔y |
|
006 |
10 |
÷ |
|
007 |
42 44 |
f FRAC |
|
008 |
45,20, 2 |
RCL × 2 |
|
009 |
44 3 |
STO 3 |
|
010 |
45 1 |
RCL 1 |
|
011 |
45,20, 2 |
RCL × 2 |
|
012 |
43,30, 1 |
g TEST x>0 |
|
013 |
22 1 |
GTO 1 |
|
014 |
45 3 |
RCL 3 |
|
015 |
45,40, 2 |
RCL + 2 |
|
016 |
44 3 |
STO 3 |
|
017 |
43 32 |
g RTN |
|
018 |
42,21, 1 |
f LBL 1 |
|
019 |
45 3 |
RCL 3 |
|
020 |
43 32 |
g RTN |
|