In article <6910400f$1@news.ausics.net>, dxf wrote:   
   >On 9/11/2025 12:47 am, albert@spenarnc.xs4all.nl wrote:   
   >> The division in ciforth was default symmetric. The motivation is that   
   >> SM/REM is a wrapper for the single instruction IDIV while floored   
   >> is more complicated.   
   >> Signed division has a speed advantage for modular arithmetic too.   
   >> [   
   >> Normalizing a remainder to the range 0 .. _m is easily done by   
   >>   
   >> : _norm_-m DUP 0< _m @ AND + ;   
   >>   
   >> (Note that all constituents are assembler primitives, such that   
   >> they can be collated into one assembler word.)   
   >> ]   
   >>   
   >> There are m modulo classes modulo m. Then it embarrasses mathematicians   
   >> that `` I1 @ m MOD '' and `` I2 @ m MOD '' are not equal,   
   >> despite i1 and i2 having the same modulo class.   
   >> Symmetric division:   
   >> 2 3 MOD .   
   >> 2 OK   
   >> -1 3 MOD .   
   >> -1 OK   
   >>   
   >> So gforth (at least 0.7.3) avoids this   
   >> 2 3 MOD . 2 ok   
   >> -1 3 MOD . 2 ok   
   >> ...   
   >   
   >2 3 MOD . 2 ok   
   >-1 3 MOD . 0 ok   
   >   
   >All 'mod' operators in polyForth were unsigned ;-)   
   >   
      
   Interesting. I didn't think of that alternative.   
   However that is only useful in modular arithmetic.   
      
   There is a simple way to detect overflow in modular addition,   
   for signed numbers.   
   : _norm_-m DUP 0< _m @ AND + ; ( x -- xn ) \ -mIN by PP with good reason. Gratitious, no.   
      
   Groetjes Albert   
   --   
   The Chinese government is satisfied with its military superiority over USA.   
   The next 5 year plan has as primary goal to advance life expectancy   
   over 80 years, like Western Europe.   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   
|