home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.lang.forth      Forth programmers eat a lot of Bratwurst      117,927 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 117,698 of 117,927   
   albert@spenarnc.xs4all.nl to Anton Ertl   
   Re: Division on riscv   
   10 Nov 25 09:28:05   
   
   In article <2025Nov10.074620@mips.complang.tuwien.ac.at>,   
   Anton Ertl  wrote:   
   >dxf  writes:   
   >>I can't think of that many instances where I've used signed division.   
   >   
   >When Gforth switched from symmetric to floored for / MOD, etc., there   
   >were no complaints that I remember.   
   >   
   >This lack of complaints indicates that division with negative operands   
   >either does not occur, or that it occurs, but the users wanted floored   
   >division and have not used the earlier symmetric /, MOD etc., but have   
   >used FM/MOD instead.   
   >   
   >In the latter case, the users might have started using /, MOD etc. for   
   >such cases in the meantime, and switching back might lead to   
   >complaints.  We are not going to switch back to find that out.   
   >   
   >There have been regular discussions of floored vs. symmetric division,   
   >and the Forth-83 standardization committee found it important enough   
   >to specify that /, MOD etc. are floored, so division with negative   
   >operands is at least on the mind of people.   
   >   
   >Forth-94 specified /, MOD etc. as implementation-defined, which has   
   >led to the regular discussions mentioned above.   
   >   
   >Bernd Paysan, who switched Gforth to floored, used to work on   
   >signal-processing equipment for audio applications.  These signals   
   >tend to be signed numbers (for positive and negative voltages), and   
   >when you scale them with */, rounding towards 0 leads to flatness when   
   >the signal passes through 0 that was not there in the original signal.   
   >Floored division avoids that; rounded division may avoid that, too,   
   >but the round-towards-even tie-breaker is probably a problem.   
   >   
   >>Are   
   >>there use cases for floored?  Sure.  But if the argument be 'a positive mod   
   >>is best' then floored doesn't guarantee that.   
   >   
   >If the divisor is positive, the result of floored MOD is >=0.   
   >   
   >If you have negative divisors and want results that are >=0, there is   
   >also something called "Euclidean division"   
   > where the remainder   
   >satisfies 0<=remainder<|divisor|.   
   >   
   >As long as the divisor is positive, the result of Euclidean division   
   >and floored division are the same, and the remainders are the same,   
   >too.   
   >   
   >If you look at   
   >,   
   >you find that there are some programming languages that specify   
   >Euclidean modulo, sometimes just that and sometimes in addition to   
   >symmetric ("truncated" in the table) or rounded; there seems to be no   
   >language that has both Euclidean and floored, which may indicate that   
   >the cases where they differ (i.e., negative divisors) occur too rarely   
   >to provide both.  In any case, the variants and the page itself   
   >indicate that the topic is not just on the minds of the Forth   
   >community.   
      
   The more mindless, the more problems. I think that FM/MOD and SM/REM   
   are the right decision for Forth. I don't like it that a simple program   
   ported from ciforth versus gforth or vice versa stops working because   
   of floored/symmetric.   
   And then discover that the problem lies in a standard word   
   that is implementation defined and overlooked.   
   I agree with the theoretical underpinning of gforth's decision   
   and ciforth will be compatible in the upcoming version 6.#.#.   
   MOD that is compatible with FM/MOD.   
      
   I have a modulo arithmetic screen +m -m *m /m (modulo is _m).   
   Negative signed or unsigned modulo is all but nonsensical   
   for 64 bit.   
   So my modulo arithmetic is based on a positive modulo,   
   allowing efficient implementation using SM/REM that is probably   
   a low level word. (In riscv ciforth it is.)   
      
   >   
   >- anton   
      
   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)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca