Re: [Oberon] Assumed issue in the Lola-2 compiler
@ Paul Reed:
-1/16 is -0.0625 not 0. (I agree there are indeed multiple integer solutions if you don't also add the range restriction on r.)
From the language report we can conclude that the operators and result of DIV and MOD (i.e. x, y, q and r) are (algebraic) integers. We can also assume that in the equation 'x = q*y + r' the multiplication and addition are proper mathematical operators. Since the given equation uses mathematical operators we can expect that rounding also follows proper mathematical rules. Therefore the rational number -1/16 is rounded to the algebraic integer 0, which would be the mathematically proper solution of q = x DIV y = ( x - r ) / y with x = -1 and y = 16.
But as mentioned: I have a viable solution which re-uses features of C to simulate the Oberon implementation. Best R.K.
All In my point of view the Oberon spec is rather clear: - q = x DIV y, r = x MOD y, x = q*y + r, 0 <= r < y - MOD is always positive ( 0 <= r < y) - It follows this pattern For x = -1 and y = 8 the only integers fulfilling the defining equation set is q = -1, r = 7. DIV is rounding down to nearest integer. br Jörg -----Original Message----- From: Oberon <oberon-bounces@lists.inf.ethz.ch> On Behalf Of rochus.keller@bluewin.ch Sent: Monday, April 15, 2019 4:13 PM To: oberon@lists.inf.ethz.ch Subject: Re: [Oberon] Assumed issue in the Lola-2 compiler @ Paul Reed:
-1/16 is -0.0625 not 0. (I agree there are indeed multiple integer
solutions if you don't also add the range restriction on r.)
From the language report we can conclude that the operators and result of DIV and MOD (i.e. x, y, q and r) are (algebraic) integers.
We can also assume that in the equation 'x = q*y + r' the multiplication and addition are proper mathematical operators. Since the given equation uses mathematical operators we can expect that rounding also follows proper mathematical rules. Therefore the rational number -1/16 is rounded to the algebraic integer 0, which would be the mathematically proper solution of q = x DIV y = ( x - r ) / y with x = -1 and y = 16. But as mentioned: I have a viable solution which re-uses features of C to simulate the Oberon implementation. Best R.K. -- <mailto:Oberon@lists.inf.ethz.ch> Oberon@lists.inf.ethz.ch mailing list for ETH Oberon and related systems <https://lists.inf.ethz.ch/mailman/listinfo/oberon> https://lists.inf.ethz.ch/mailman/listinfo/oberon
Joerg: this discussion should become an Appendix to the Language Report. We will then know what we are doing when we write a program using these operators. Wojtek ________________________________________ From: Oberon [oberon-bounces@lists.inf.ethz.ch] on behalf of Joerg [joerg.straube@iaeth.ch] Sent: Monday, April 15, 2019 10:53 AM To: rochus.keller@bluewin.ch; 'ETH Oberon and related systems' Subject: Re: [Oberon] Assumed issue in the Lola-2 compiler All In my point of view the Oberon spec is rather clear: - q = x DIV y, r = x MOD y, x = q*y + r, 0 <= r < y - MOD is always positive ( 0 <= r < y) - It follows this pattern [cid:image003.png@01D4F3AB.C0FB2A30] For x = -1 and y = 8 the only integers fulfilling the defining equation set is q = -1, r = 7. DIV is rounding down to nearest integer. br Jörg -----Original Message----- From: Oberon <oberon-bounces@lists.inf.ethz.ch> On Behalf Of rochus.keller@bluewin.ch Sent: Monday, April 15, 2019 4:13 PM To: oberon@lists.inf.ethz.ch Subject: Re: [Oberon] Assumed issue in the Lola-2 compiler @ Paul Reed:
-1/16 is -0.0625 not 0. (I agree there are indeed multiple integer
solutions if you don't also add the range restriction on r.)
From the language report we can conclude that the operators and result of DIV and MOD (i.e. x, y, q and r) are (algebraic) integers.
We can also assume that in the equation 'x = q*y + r' the multiplication and addition are proper mathematical operators. Since the given equation uses mathematical operators we can expect that rounding also follows proper mathematical rules. Therefore the rational number -1/16 is rounded to the algebraic integer 0, which would be the mathematically proper solution of q = x DIV y = ( x - r ) / y with x = -1 and y = 16. But as mentioned: I have a viable solution which re-uses features of C to simulate the Oberon implementation. Best R.K. -- Oberon@lists.inf.ethz.ch<mailto:Oberon@lists.inf.ethz.ch> mailing list for ETH Oberon and related systems https://lists.inf.ethz.ch/mailman/listinfo/oberon<https://urldefense.proofpoint.com/v2/url?u=https-3A__lists.inf.ethz.ch_mailman_listinfo_oberon&d=DwMFAw&c=kbmfwr1Yojg42sGEpaQh5ofMHBeTl9EI2eaqQZhHbOU&r=uUiA_zLpwaGJIlq-_BM9w1wVOuyqPwHi3XzJRa-ybV0&m=ER49YUosIU_AK9lBnIe3-FHGrEt9WcbbQZvIhCnQEA0&s=cLRrZcojDDGrEAOCDYipJ4TTgJSnYgZcFwd93HnGpYc&e=>
Hi all, just two remarks: 1. On Mo, 2019-04-15 at 16:53 +0200, joerg.straube@iaeth.ch wrote:
In my point of view the Oberon spec is rather clear: q = x DIV y, r = x MOD y, x = q*y + r, 0 <= r < y
This implies 0 < y and leaves the case y <= 0 unspecified (y = 0 can of course be excluded). 2. On Mo, 2019-04-15 at 14:35 +0200, rochus.keller@bluewin.ch wrote:
Ok, I think I found a decent solution. [..] But I can avoid this indetermination by using the following two functions and re-using features of the C language.
The C language spec is rather reluctant to exactly define the result of the % operator (at least the C89 version; I didn't look into the newer standards). It says (K&R, 2nd edition, A7.6 Multiplicative Operators): ".. it is always true that (a/b)*b + a%b is equal to a. If both operands are non-negative, then the remainder is non-negative and smaller than the divisor; if not, it is guaranteed only that the absolute value of the remainder is smaller than the absolute value of the divisor." The implication of this is that you cannot use % consistently across implementations (and not even within an implementation) if any of its arguments could be negative. Regards, Hellwig
>On Mo, 2019-04-15 at 16:53 +0200, joerg.straube@iaeth.ch wrote: >> In my point of view the Oberon spec is rather clear: >> q = x DIV y, r = x MOD y, x = q*y + r, 0 <= r < y >This implies 0 < y and leaves the case y <= 0 unspecified >(y = 0 can of course be excluded). Correct. The discussion was (only) about negative x. br Jörg
Somewhere in my past I took a course that included the theory of numbers, and it included the definition of division. Since then I have always been interested and attentive to that definition. There is a very close connection between the MOD operator in mathematics and the so called "clock numbers." Those are the familiar everyday numbers MOD 12. The Oberon definition follows the mathematical definition. If we call noon today "0" and we are plotting a graph, we want 1 hour before noon to be graphed at 11, pretty much as we do in the graph of MOD 8 in this conversation. So making strip charts and such with time data results in "as expected" results. Many calculators and also runtime environments for other languages do this incorrectly. They simply carry the negative sign into the results for both mod and div. This is not correct behavior from a mathematician's point of view. On Mon, Apr 15, 2019 at 9:54 AM Joerg <joerg.straube@iaeth.ch> wrote:
All
In my point of view the Oberon spec is rather clear:
- q = x DIV y, r = x MOD y, x = q*y + r, 0 <= r < y
- MOD is always positive ( 0 <= r < y)
- It follows this pattern
For x = -1 and y = 8 the only integers fulfilling the defining equation set is q = -1, r = 7.
DIV is rounding down to nearest integer.
br
Jörg
-----Original Message----- From: Oberon <oberon-bounces@lists.inf.ethz.ch> On Behalf Of rochus.keller@bluewin.ch Sent: Monday, April 15, 2019 4:13 PM To: oberon@lists.inf.ethz.ch Subject: Re: [Oberon] Assumed issue in the Lola-2 compiler
@ Paul Reed:
-1/16 is -0.0625 not 0. (I agree there are indeed multiple integer
solutions if you don't also add the range restriction on r.)
From the language report we can conclude that the operators and result of DIV and MOD (i.e. x, y, q and r) are (algebraic) integers.
We can also assume that in the equation 'x = q*y + r' the multiplication and addition are proper mathematical operators.
Since the given equation uses mathematical operators we can expect that rounding also follows proper mathematical rules. Therefore the rational number -1/16 is rounded to the algebraic integer 0, which would be the mathematically proper solution of q = x DIV y = ( x - r ) / y with x = -1 and y = 16.
But as mentioned: I have a viable solution which re-uses features of C to simulate the Oberon implementation.
Best
R.K.
--
Oberon@lists.inf.ethz.ch mailing list for ETH Oberon and related systems https://lists.inf.ethz.ch/mailman/listinfo/oberon -- Oberon@lists.inf.ethz.ch mailing list for ETH Oberon and related systems https://lists.inf.ethz.ch/mailman/listinfo/oberon
-- Aubrey McIntosh, PhD Teaching Specialist, Chemistry Department The University of Texas at Austin
participants (6)
-
Aubrey McIntosh -
Hellwig Geisse -
Joerg -
Jörg -
rochus.keller@bluewin.ch -
Skulski, Wojciech