From: the.beez.speaks@gmail.com   
      
   On 14-04-2024 13:06, albert@spenarnc.xs4all.nl wrote:   
   > In article <661a5369$1@news.ausics.net>, dxf wrote:   
   >> On 12/04/2024 6:27 pm, albert@spenarnc.xs4all.nl wrote:   
   >>> In article <66188ab1$1@news.ausics.net>, dxf wrote:   
   >>>> On 12/04/2024 1:11 am, albert@spenarnc.xs4all.nl wrote:   
   >>>>>   
   >>>>> While others indulge in endless discussions about DRSHIFT   
   >>>>> I thought to attempt some literate programming.   
   >>>>   
   >>>> It didn't prompt you to test your own implementation?   
   >>>>   
   >>>> ( D0= D0<> D0< D= D< D- M+ DRSHIFT DLSHIFT DU< ) \ AvdH B6Mar22   
   >>>>   
   >>>> : DLSHIFT >R SWAP DUP R@ LSHIFT SWAP 8 CELLS R@ - RSHIFT ROT R>   
   >>>> LSHIFT OR ;   
   >>>>   
   >>>> : DRSHIFT >R DUP R@ RSHIFT SWAP 8 CELLS R@ - LSHIFT ROT R>   
   >>>> RSHIFT OR SWAP ;   
   >>>>   
   >>>> 0 4 d. 17179869184 ok   
   >>>> 0 4 0 drshift d. 17179869188 ok   
   >>>>   
   >>>> 4 0 d. 4 ok   
   >>>> 4 0 0 dlshift d. 17179869188 ok   
   >>>>   
   >>>   
   >>> Good catch! Shifting over 8 CELLS is an ambiguous condition.   
   >>> insert   
   >>> DUP 0= IF EXIT THEN   
   >>> in front of the code.   
   >>   
   >> That handles the specific case '0 shift' but the ambiguous condition   
   >> you mention arises again here:   
   >>   
   >> HEX   
   >> 03 01 8 cells dlshift .( Expected: 00 03 Got: ) swap u. u. cr   
   >> FF 00 8 cells dlshift .( Expected: 00 FF Got: ) swap u. u. cr   
   >> 00 01 8 cells drshift .( Expected: 01 00 Got: ) swap u. u. cr   
   >> 00 FF 8 cells drshift .( Expected: FF 00 Got: ) swap u. u. cr   
   >> DECIMAL   
      
   Sure, I had to adapt it a bit: 4tH is segmented, so 1 CELLS renders 1.   
   [HEX] only works at compile time, so HEX is added to allow for runtime   
   behavior. And sure, not all of this stuff is core, so some libs are   
   added as well.   
      
   include lib/dbldot.4th \ if you insist..   
   include lib/dshift.4th \ identical to routine posted on c.l.f.   
      
   [HEX] HEX   
   03 01 8 /cell * dlshift .( Expected: 00 03 Got: ) swap u. u. cr   
   FF 00 8 /cell * dlshift .( Expected: 00 FF Got: ) swap u. u. cr   
   00 01 8 /cell * drshift .( Expected: 01 00 Got: ) swap u. u. cr   
   00 FF 8 /cell * drshift .( Expected: FF 00 Got: ) swap u. u. cr   
   [DECIMAL] DECIMAL   
      
   But it's rock solid:   
      
   $ pp4th -x clfdrshift.4th   
   Expected: 00 03 Got: 0 3   
   Expected: 00 FF Got: 0 FF   
   Expected: 01 00 Got: 1 0   
   Expected: FF 00 Got: FF 0   
      
   Hans Bezemer   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   
|