Post Reply 
(42, all flavours) Integer Division - how?
12-14-2020, 06:59 AM (This post was last modified: 12-14-2020 07:59 AM by Werner.)
Post: #22
RE: (42, all flavours) Integer Division - how?
(corrected)
using floor(q) now, and the 'correct or not' approach:
(replace all NOPs with LBL 00 on a real 42S, or the DM42 for the time being)

Code:
 { 45-Byte Prgm } @     X       Y       Z       T
 LBL "DIV" @            b       a
 RCL ST Y
 RCL ST Y
 /
 IP @                  q        b       a       a
 LASTX
 X<Y?
 DSE ST Y
 NOP @                        floor(q)  b       a
 R^
 STO ST Y @            a        a       q       b
 R^
 MOD @          b      a%b      a       q       q
 ISG ST L @     c
 NOP
 X<>Y
 LASTX @                c       a       a%b     q 
 MOD
 STO- ST Y @    c       a%c     a'      q       q
 X<> ST T @     c       q       a'      q
 LASTX @                c       q       a'      q
 MOD @          c       b'      a'      q       q
 X#Y?
 RCL- ST L
 X#Y?
 DSE ST T
 NOP
 R^
 END

Cheers, Werner

41CV†,42S,48GX,49G,DM42,DM41X,17BII,15CE,DM15L,12C,16CE
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: (42, all flavours) Integer Division - how? - Werner - 12-14-2020 06:59 AM



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