Post Reply 
(12C) Modulo, the financial way
05-06-2024, 07:19 PM
Post: #1
(12C) Modulo, the financial way
The modulo operation, sometimes called the 5th basic operation, returns the remainder of an integer division. Normally it is calculated as

a mod b = a - b×INT(a/b)

which can be transformed into a program, in a rather conventional way:

Code:
01 x<>y        #t z b a
02 STO n
03 x<>y        #t z a b
04 ÷           #t t z a/b
05 g LSTx      #t z a/b b
06 x<>y        #t z b a/b
07 g INTG
08 ×           #t t z b×INT
09 RCL n       #t z b×INT a
10 -
11 CHS         #t t z mod
12 g GTO 00

On the other hand, as a financial calculator, we should be surprised if the HP12C wouldn't offer a financial way, too:

Code:
01 f Clear FIN #clears all financial registers
02 PMT         #payment
03 x<>y        #t z b a
04 CHS         #t z b -a
05 PV          #current value with negated sign
06 x<>y        #t z -a b
07 ÷
08 CHS         #t t z n; real quantity of payments
09 n
10 FV          #t t z mod; final value with integer quantity of payments
11 g GTO 00

Usage: a ENTER b R/S

Examples:
20 mod 7 = 6
200 mod 9 = 2
10 mod 6 = 4
40 mod 6 = 4
100 mod 6 = 4
1E9 mod 6 = 4

Have fun modulating numbers!

(Summarised from my original post)
Find all posts by this user
Quote this message in a reply
Post Reply 




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