-\ @(#) math.fth 98/01/26 1.2\r
-\ Extended Math routines\r
-\ FM/MOD SM/REM\r
-\\r
-\ Author: Phil Burk\r
-\ Copyright 1994 3DO, Phil Burk, Larry Polansky, Devid Rosenboom\r
-\\r
-\ The pForth software code is dedicated to the public domain,\r
-\ and any third party may reproduce, distribute and modify\r
-\ the pForth software code or any derivative works thereof\r
-\ without any compensation or license. The pForth software\r
-\ code is provided on an "as is" basis without any warranty\r
-\ of any kind, including, without limitation, the implied\r
-\ warranties of merchantability and fitness for a particular\r
-\ purpose and their equivalents under the laws of any jurisdiction.\r
-\r
-anew task-math.fth\r
-decimal\r
-\r
-: FM/MOD { dl dh nn | dlp dhp nnp rem quo -- rem quo , floored }\r
- dl dh dabs -> dhp -> dlp\r
- nn abs -> nnp\r
- dlp dhp nnp um/mod -> quo -> rem\r
- dh 0< \r
- IF \ negative dividend\r
- nn 0< \r
- IF \ negative divisor\r
- rem negate -> rem\r
- ELSE \ positive divisor\r
- rem 0=\r
- IF\r
- quo negate -> quo\r
- ELSE\r
- quo 1+ negate -> quo\r
- nnp rem - -> rem\r
- THEN\r
- THEN\r
- ELSE \ positive dividend\r
- nn 0< \r
- IF \ negative divisor\r
- rem 0=\r
- IF\r
- quo negate -> quo\r
- ELSE\r
- nnp rem - negate -> rem\r
- quo 1+ negate -> quo\r
- THEN\r
- THEN\r
- THEN\r
- rem quo\r
-;\r
-\r
-: SM/REM { dl dh nn | dlp dhp nnp rem quo -- rem quo , symmetric }\r
- dl dh dabs -> dhp -> dlp\r
- nn abs -> nnp\r
- dlp dhp nnp um/mod -> quo -> rem\r
- dh 0< \r
- IF \ negative dividend\r
- rem negate -> rem\r
- nn 0> \r
- IF \ positive divisor\r
- quo negate -> quo\r
- THEN\r
- ELSE \ positive dividend\r
- nn 0< \r
- IF \ negative divisor\r
- quo negate -> quo\r
- THEN\r
- THEN\r
- rem quo\r
-;\r
-\r
-\r
-: /MOD ( a b -- rem quo )\r
- >r s>d r> sm/rem\r
-;\r
-\r
-: MOD ( a b -- rem )\r
- /mod drop\r
-;\r
-\r
-: */MOD ( a b c -- rem a*b/c , use double precision intermediate value )\r
- >r m*\r
- r> sm/rem\r
-;\r
-: */ ( a b c -- a*b/c , use double precision intermediate value )\r
- */mod\r
- nip\r
-;\r
+\ @(#) math.fth 98/01/26 1.2
+\ Extended Math routines
+\ FM/MOD SM/REM
+\
+\ Author: Phil Burk
+\ Copyright 1994 3DO, Phil Burk, Larry Polansky, Devid Rosenboom
+\
+\ The pForth software code is dedicated to the public domain,
+\ and any third party may reproduce, distribute and modify
+\ the pForth software code or any derivative works thereof
+\ without any compensation or license. The pForth software
+\ code is provided on an "as is" basis without any warranty
+\ of any kind, including, without limitation, the implied
+\ warranties of merchantability and fitness for a particular
+\ purpose and their equivalents under the laws of any jurisdiction.
+
+anew task-math.fth
+decimal
+
+: FM/MOD { dl dh nn | dlp dhp nnp rem quo -- rem quo , floored }
+ dl dh dabs -> dhp -> dlp
+ nn abs -> nnp
+ dlp dhp nnp um/mod -> quo -> rem
+ dh 0<
+ IF \ negative dividend
+ nn 0<
+ IF \ negative divisor
+ rem negate -> rem
+ ELSE \ positive divisor
+ rem 0=
+ IF
+ quo negate -> quo
+ ELSE
+ quo 1+ negate -> quo
+ nnp rem - -> rem
+ THEN
+ THEN
+ ELSE \ positive dividend
+ nn 0<
+ IF \ negative divisor
+ rem 0=
+ IF
+ quo negate -> quo
+ ELSE
+ nnp rem - negate -> rem
+ quo 1+ negate -> quo
+ THEN
+ THEN
+ THEN
+ rem quo
+;
+
+: SM/REM { dl dh nn | dlp dhp nnp rem quo -- rem quo , symmetric }
+ dl dh dabs -> dhp -> dlp
+ nn abs -> nnp
+ dlp dhp nnp um/mod -> quo -> rem
+ dh 0<
+ IF \ negative dividend
+ rem negate -> rem
+ nn 0>
+ IF \ positive divisor
+ quo negate -> quo
+ THEN
+ ELSE \ positive dividend
+ nn 0<
+ IF \ negative divisor
+ quo negate -> quo
+ THEN
+ THEN
+ rem quo
+;
+
+
+: /MOD ( a b -- rem quo )
+ >r s>d r> sm/rem
+;
+
+: MOD ( a b -- rem )
+ /mod drop
+;
+
+: */MOD ( a b c -- rem a*b/c , use double precision intermediate value )
+ >r m*
+ r> sm/rem
+;
+: */ ( a b c -- a*b/c , use double precision intermediate value )
+ */mod
+ nip
+;