This newbie may be missing something obvious, but Gforth has no words for
multiplying two double-precision integers, nor does it appear that anyone
on the Internet has any interest in doing so with Gforth or any other
Forth implementations. Is it really such a useless thing to do?
For my own satisfaction if no one else's, I've fiddled around and
pieced-together a way to multiply unsigned doubles. I hope a little more
fiddling will show me how to multiply signed doubles, too. The file
attached below is a work-in-progress, but comments are welcome.
\ double-arith.fs - Double-precision arithmetic extensions
\ Copyright 2013 David Meyer <
pa...@sdf.org> +JMJ
\ Copying and distribution of this file, with or without
\ modification, are permitted in any medium without royalty
\ provided the copyright notice and this notice are preserved.
\ This file is offered as-is, without any warranty.
\ MAXU - Maximum value of unsigned single
s" MAX-U" environment? drop constant MAXU
\ md* - Multiply double by unsigned single (iterative method)
: md* ( d u -- d*u )
0. rot
0 u+do 2over d+ loop
2nip
;
\ mudu* - Multiply unsigned double by unsigned single
: mudu* ( ud u -- ud*u ) tuck * >r m* r> + ;
\ ud* - Multiply two unsigned doubles
: ud* ( ud1 ud2 -- ud1*ud2 )
{ a1 b1 a2 b2 }
a1 a2 um*
MAXU a1 um* b2 mudu* d+
MAXU a2 um* b1 mudu* d+
MAXU MAXU um* b1 mudu* b2 mudu* d+
;
--
pa...@sdf.org
SDF Public Access UNIX System -
http://sdf.lonestar.org