Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.forth > #26978
| From | anton@mips.complang.tuwien.ac.at (Anton Ertl) |
|---|---|
| Newsgroups | comp.lang.forth |
| Subject | Re: Double multiplication |
| Date | 2013-11-26 16:13 +0000 |
| Organization | Institut fuer Computersprachen, Technische Universitaet Wien |
| Message-ID | <2013Nov26.171319@mips.complang.tuwien.ac.at> (permalink) |
| References | <l72gu7$qj0$1@odin.sdf-eu.org> |
David Meyer <papa@sdf.org> writes:
>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?
It's needed rarely.
>I hope a little more
>fiddling will show me how to multiply signed doubles, too.
If you (like everyone else) uses 2s-complement for signed numbers,
then for n-bit x n-bit -> n-bit multiplication there is no difference
between signed and unsigned. That's why Forth has no U*. And that's
why UD* is the same as D*.
This hinges on the fact that you can view the negative 2s-complement
number x as being the unsigned number 2^n+x (which is in the range of
unsigned numbers). If you multiply x with y, you get 2^n*y+x*y, and
2^n*y has only 0 bits in the lowest n bits, so it does not influence
the result.
Concerning the implementation, I'll have a go at it:
: d* { al ah bl bh -- cl ch }
\ (2^m*ah+al)+(2^m*bh+bl) =
\ 2^(2*m)*ah*bh+2^m*(ah*bl+al*bh)+al*bl
\ take this modulo 2^(2*m), making ah*bh irrelevant
al bh * ah bl * + 0 swap
al bl um* d+ ;
- anton
--
M. Anton Ertl http://www.complang.tuwien.ac.at/anton/home.html
comp.lang.forth FAQs: http://www.complang.tuwien.ac.at/forth/faq/toc.html
New standard: http://www.forth200x.org/forth200x.html
EuroForth 2013: http://www.euroforth.org/ef13/
Back to comp.lang.forth | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Double multiplication David Meyer <papa@sdf.org> - 2013-11-26 16:06 +0000
Re: Double multiplication anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2013-11-26 16:13 +0000
Re: Double multiplication "Alex McDonald" <blog@rivadpm.com> - 2013-11-26 22:59 +0000
Re: Double multiplication Hans Bezemer <the.beez.speaks@gmail.com> - 2013-11-27 22:34 +0100
Re: Double multiplication anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2013-11-28 15:51 +0000
Re: Double multiplication mhx@iae.nl - 2013-11-26 10:14 -0800
Re: Double multiplication "Ed" <invalid@invalid.com> - 2013-12-01 23:41 +1100
Re: Double multiplication mhx@iae.nl - 2013-12-02 02:23 -0800
Re: Double multiplication "Ed" <invalid@invalid.com> - 2013-12-05 22:19 +1100
Re: Double multiplication Hans Bezemer <the.beez.speaks@gmail.com> - 2013-12-05 13:14 +0100
Re: Double multiplication Coos Haak <chforth@hccnet.nl> - 2013-12-06 00:16 +0100
Re: Double multiplication "Rod Pemberton" <dont_use_email@xnohavenotit.cnm> - 2013-12-05 21:24 -0500
Re: Double multiplication albert@spenarnc.xs4all.nl (Albert van der Horst) - 2013-11-26 20:20 +0000
Re: Double multiplication "Elizabeth D. Rather" <erather@forth.com> - 2013-11-26 11:43 -1000
csiph-web