1 \ @(#) math.fth 98/01/26 1.2
2 \ Extended Math routines
6 \ Copyright 1994 3DO, Phil Burk, Larry Polansky, David Rosenboom
8 \ Permission to use, copy, modify, and/or distribute this
9 \ software for any purpose with or without fee is hereby granted.
11 \ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
12 \ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
13 \ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
14 \ THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR
15 \ CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
16 \ FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
17 \ CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
18 \ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
23 : FM/MOD { dl dh nn | dlp dhp nnp rem quo -- rem quo , floored }
24 dl dh dabs -> dhp -> dlp
26 dlp dhp nnp um/mod -> quo -> rem
28 IF \ negative dividend
32 ELSE \ positive divisor
41 ELSE \ positive dividend
48 nnp rem - negate -> rem
56 : SM/REM { dl dh nn | dlp dhp nnp rem quo -- rem quo , symmetric }
57 dl dh dabs -> dhp -> dlp
59 dlp dhp nnp um/mod -> quo -> rem
61 IF \ negative dividend
67 ELSE \ positive dividend
77 : /MOD ( a b -- rem quo )
85 : */MOD ( a b c -- rem a*b/c , use double precision intermediate value )
89 : */ ( a b c -- a*b/c , use double precision intermediate value )