home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power-Programmierung
/
CD1.mdf
/
forth
/
compiler
/
fpc
/
source
/
p2_16dc.seq
< prev
next >
Wrap
Text File
|
1990-03-31
|
3KB
|
98 lines
\ INTDIV PROGRAM FOR P1.16
\ Revised by Dickson Cheng 03/31/90 17:19:12.07
\ Make grid for plot.
: GRID ( -- )
0 10 AT 60 0 DO 197 EMIT 196 EMIT 2 +LOOP
197 EMIT
21 1 DO 30 I AT 197 EMIT LOOP
9 9 AT -10 . 50 9 AT 10 .
28 0 AT 10 . 27 20 AT -10 . ;
\ Display divisor.
: .DIVISOR ( n -- )
40 1 AT ." Divisor = n = " . ;
\ Display division equations.
: .EQN ( -- )
40 18 AT ." m = nq + r"
40 19 AT ." m/n = q + r/n"
0 22 AT
." ( m = dividend, n = divisor, q = quotient, and r = remainder )" ;
\ Floored integer division... quotient vs dividend.
: FQVSM ( n -- )
1 1 AT ." FLOORED q vs m" DUP .DIVISOR .EQN
30 0 AT ASCII q EMIT 61 10 AT ASCII m EMIT
5 21 AT ." Quotient vs Dividend for Floored Integer Division"
16 -15 DO I OVER / 10 SWAP -
I 15 + 2* SWAP AT
4 EMIT LOOP DROP ;
\ Floored integer division... remainder vs dividend.
: FRVSM ( n -- )
1 1 AT ." FLOORED r vs m " DUP .DIVISOR .EQN
30 0 AT ASCII r EMIT 62 10 AT ASCII m EMIT
5 21 AT ." Remainder vs Dividend for Floored Integer Division"
16 -15 DO I OVER MOD 10 SWAP -
I 15 + 2* SWAP AT
4 EMIT LOOP DROP ;
\ Symmetric integer division form of /MOD
: S/MOD ( m n -- r q )
2DUP XOR 0<
IF 2DUP
ABS SWAP ABS SWAP
/ NEGATE
-ROT 2 PICK
* -
SWAP
ELSE /MOD
THEN ;
\ Symmetric integer division form of /
: S/ ( m n -- q )
S/MOD NIP ;
\ Symetric integer division form of MOD
: SMOD ( m n -- r )
S/MOD DROP ;
\ Symmetric integer division... quotient vs dividend.
: SQVSM ( n -- )
1 1 AT ." SYMMETRIC r vs m " DUP .DIVISOR .EQN
31 0 AT ASCII q EMIT 62 10 AT ASCII m EMIT
5 21 AT ." Quotient vs Dividend for Symmetric Integer Division"
16 -15 DO I OVER S/ 10 SWAP -
I 15 + 2* SWAP AT
4 EMIT LOOP DROP ;
\ Symmetric integer division... remainder vs dividend.
: SRVSM ( n -- )
1 1 AT ." SYMMETRIC r vs m " DUP .DIVISOR .EQN
31 0 AT ASCII r EMIT 62 10 AT ASCII m EMIT
5 21 AT ." Remainder vs Dividend for Symmetric Integer Division"
16 -15 DO I OVER SMOD 10 SWAP -
I 15 + 2* SWAP AT
4 EMIT LOOP DROP ;
\ Run through the four plots for an integer divisor.
: INTDIV ( n -- )
-10 MAX 10 MIN ?DUP
IF
CURSOR-OFF
DUP DARK GRID FQVSM KEY DROP
DUP DARK GRID FRVSM KEY DROP
DUP DARK GRID SQVSM KEY DROP
DUP DARK GRID SRVSM KEY DROP
CURSOR-ON
DROP
ELSE DARK CR ." Can't divide by zero dummy"
THEN ;
: MESSAGE ( -- )
DARK CR ." To run INTDIV type n INTDIV." ;
MESSAGE