Re: M/MOD



"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/
.



Relevant Pages

  • Re: [SLE] compile 2.6.13 kernel SUSE 9.3 devices not recognized
    ... > menu.lst points to the kernel correctly. ... If /dev/hda6 is the swap partition, I've seen the same or similar ... Other kernels I assume boot without problems. ... types of hardware, so I prune my config to suit the hardware I have. ...
    (SuSE)
  • Re: Advice on changing to 64 bits
    ... and that the processor has Intel's hardware vitualization capabilities. ... into swap, after switching to 10 64-bit, I had to add 2GB more of swap and ... memory usage went down quite a bit. ... the throughput between the ram and CPU) otherwise i've found little ...
    (Fedora)
  • Re: Legality of software "handmedowns"
    ... >measures to be taken just when you're swapping out hardware are ridiculous. ... >Alright, then. ... Who's the hotshot I would call whenever I decide to swap out ...
    (microsoft.public.windowsxp.help_and_support)
  • Re: Legality of software "handmedowns"
    ... >measures to be taken just when you're swapping out hardware are ridiculous. ... >Alright, then. ... Who's the hotshot I would call whenever I decide to swap out ...
    (microsoft.public.windowsxp.general)
  • Re: M/MOD
    ... defines a floored division function one is using symmetric division to get ... r> 0< IF swap negate swap THEN; ... UM/MOD. ... M. Anton Ertl http://www.complang.tuwien.ac.at/anton/home.html ...
    (comp.lang.forth)