From: dxforth@gmail.com   
      
   On 9/11/2025 10:37 pm, albert@spenarnc.xs4all.nl wrote:   
   > 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 ) \ -m : +m + _m @ - _norm_-m ; ( an bn -- sumn )   
   > That can be changed to usigned, probably.   
   > As long as you restrict the modulo to a number less than 8000,0000,0000,0000   
   > this might work equally well for unsigned numbers.   
   > For modulo arithmetic each input has to be in the range 0 .. _m @ .   
   >   
   > As numbers are normally unsigned, restricting MOD to unsigned number   
   > is not an option in my opinion. Also it is a gratitious deviation from   
   > ISO 94, a big nono.   
   > ...   
      
   Because you place value on standards? Standards give the illusion of   
   stability but the reality is the world moves on before our very eyes.   
      
   I can't think of that many instances where I've used signed division. Are   
   there use cases for floored? Sure. But if the argument be 'a positive mod   
   is best' then floored doesn't guarantee that. Realizing there's no one right   
   signed integer division method, I can't get excited about it. I made peace   
   with polyForth's unsigned mods knowing that if signed was needed, it could   
   easily be emulated.   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   
|