Sujet : Re: exercise in double number arithmetic
De : dxforth (at) *nospam* gmail.com (dxf)
Groupes : comp.lang.forthDate : 10. Jul 2024, 14:08:59
Autres entêtes
Organisation : Ausics - https://newsgroups.ausics.net
Message-ID : <668e87ec$1@news.ausics.net>
References : 1 2 3 4 5 6 7 8 9
User-Agent : Mozilla Thunderbird
On 10/07/2024 6:41 pm, dxf wrote:
On 10/07/2024 5:51 pm, Gerry Jackson wrote:
>
[...] I found I had another definition for D/MOD from Forth Dimensions Vol 14 Issue 6, p 27 "Math - Who Needs It"
https://www.forth.org/fd/FD-V14N6.pdf
I've no idea how good it is
Here's the source file (32MATH.SEQ) for those interested:
https://pastebin.com/mfU8FZ1x
Here's one I had lying around. Not sure if I used it so may require checking
first! The 2variable is an eye-sore. Perhaps someone can eliminate it without
resorting to locals :)
2variable d
\ Divide quad by double. Unsigned.
: DUM/MOD ( uq ud -- udrem udquot )
d 2! [ 16 cells ] literal 0 do
dup >r 2swap dup >r d2* 2swap d2*
r> 0< dup d- 2dup d 2@ du< 0= r> 0< or
if d 2@ d- 2swap 1 0 d+ 2swap then
loop 2swap ;
\ Divide doubles. Unsigned.
: DU/MOD ( ud1 ud2 -- udrem udquot )
0 0 2swap dum/mod ;
\ Divide doubles. Signed. Symmetric.
: D/MOD ( d1 d2 -- drem dquot )
2 pick 2dup xor 2>r dabs 2swap dabs
2swap du/mod r> 0< if dnegate then
r> 0< if 2swap dnegate 2swap then ;