home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power-Programmierung
/
CD1.mdf
/
forth
/
compiler
/
fpc
/
source
/
p4_23dc.seq
< prev
next >
Wrap
Text File
|
1990-04-16
|
1KB
|
30 lines
\ Problem 4.23 04/16/90 16:44:18.64
\ This is Forth 83 floored integer division
\ for double numbers using SMITH's coded UMD/MOD
\ Divides two double numbers. All numbers are signed doubles.
: D/MOD ( dn1 dn2 -- drem dquot )
2DUP >R >R \ Save dn2 complete with sign for later.
2 PICK >R \ Save sign of dn1 for later.
DABS >R >R \ Save uddivisor for a moment
DABS 0 0 R> R> \ uqdividend uddivisor
UMD/MOD 2SWAP \ udquot udrem
R@ ?DNEGATE \ apply sign to remainder.
R> R> R@ SWAP >R XOR \ find sign of quotient.
IF R> R> D+ 2SWAP \ adjust remainder.
DNEGATE 1. D- \ adjust quotient.
ELSE R> R> 2DROP 2SWAP
THEN ; \ drem dquot
\ Leave the Forth 83 "floored integer quotient" result for dn1/dn2
: D/ ( dn1 dn2 -- dquot )
D/MOD 2SWAP 2DROP ;
\ Leave the Forth 83 "floored integer remainder" result for dn1/dn2
: DMOD ( dn1 dn2 -- drem )
D/MOD 2DROP ;