Re: M/MOD
- From: anton@xxxxxxxxxxxxxxxxxxxxxxxxxx (Anton Ertl)
- Date: Mon, 25 Jun 2007 08:47:53 GMT
"Ed" <nospam@xxxxxxxxxxx> writes:
Even if floored and symmetric division were both supported
in hardware, it's likely symmetric would still win because the
algorithm is simpler.
: fm/mod ( d1 n1 -- n2 n3 )
dup >r dup 0< IF negate >r dnegate r> THEN
over 0< IF tuck + swap THEN
um/mod
r> 0< IF swap negate swap THEN ;
: sm/rem ( d1 n1 -- n2 n3 )
over >r dup >r abs -rot
dabs rot um/mod
r> r@ xor 0< IF negate THEN
r> 0< IF swap negate swap THEN ;
I don't see a significant difference in simplicity. The timing
results on the PPC, which does not have double-by-single division in
hardware, also suggest that symmetric is not faster unless it's better
supported in hardware.
Speed, however, is not the issue. Now that C99 has adopted
Fortran convention and mandated symmetric division, other
languages will inevitably follow.
You could also make an RfD for standardizing / and friends as
symmetric. However, the last such discussion led to Bernd making
Gforth's / and friends floored by default, so you might find that a
hard fight.
- 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 2007: http://www.complang.tuwien.ac.at/anton/euroforth2007/
.
- Prev by Date: Re: M/MOD
- Next by Date: Re: Build your own Forth for Microchip PIC (Episode 837)
- Previous by thread: Re: M/MOD
- Next by thread: Re: M/MOD
- Index(es):
Relevant Pages
|