<div dir="ltr">I have not checked my number theory book lately, but I don't think (i.e., don't remember) that it is defined mathematically for negative divisors either.</div><div class="gmail_extra"><br><div class="gmail_quote">On Sat, May 13, 2017 at 3:12 AM, Peter Matthias <span dir="ltr"><<a href="mailto:PeterMatthias@web.de" target="_blank">PeterMatthias@web.de</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Agreed. However, -1 MOD -12 or 1 MOD -12 is not defined in Oberon.<span class=""><br>
<br>
<br>
Am 12.05.2017 um 22:43 schrieb Aubrey McIntosh:<br>
</span><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">
for -1 MOD 12, the mathematically correct answers which are consistent<br>
with the language report, are<br>
q=-1, r=11.<br>
<br>
This definition works very well, for example, to implement wrap around<br>
strip chart displays.<br>
<br>
<br>
On Fri, May 12, 2017 at 2:28 PM, Peter Matthias <<a href="mailto:PeterMatthias@web.de" target="_blank">PeterMatthias@web.de</a><br></span><div><div class="h5">
<mailto:<a href="mailto:PeterMatthias@web.de" target="_blank">PeterMatthias@web.de</a>>> wrote:<br>
<br>
    Warming up the thread to give supposedly correct answer:<br>
<br>
    Am 16.02.2017 um 00:00 schrieb Peter Matthias:<br>
<br>
<br>
<br>
        Am 15.02.2017 um 04:21 schrieb Srinivas Nayak:<br>
<br>
            Dear All,<br>
<br>
            Recently I come across modulus on a negative number.<br>
            Will it produce a negative number or positive?<br>
            Someone says both are correct!<br>
            <a href="http://stackoverflow.com/a/4403556" rel="noreferrer" target="_blank">http://stackoverflow.com/a/440<wbr>3556</a><br>
            <<a href="http://stackoverflow.com/a/4403556" rel="noreferrer" target="_blank">http://stackoverflow.com/a/44<wbr>03556</a>><br>
            Which one is mathematically correct?<br>
            Surprisingly different languages calculate it differently even!<br>
            What is Oberon's way?<br>
<br>
<br>
        The theory was already answered. In practice, all compiler<br>
        implementations I used (native X86, Shark, MIPS), give wrong<br>
        result when<br>
        both, divident and divisor are negative. I fixed it just<br>
        yesterday for<br>
        all non x86 versions.<br>
<br>
<br>
    I should have read the language report before making such claims.<br>
<br>
    Oberon Report says:<br>
<br>
    "The operators DIV and MOD apply to integer operands only. They are<br>
    related by the following formulas defined for any dividend x and<br>
    positive divisors y:<br>
    x = (x DIV y) * y + (x MOD y)<br>
    0 ≤ (x MOD y) < y"<br>
<br>
    Oberon07-Report says:<br>
<br>
    "The operators DIV and MOD apply to integer operands only. Let q = x<br>
    DIV y, and r = x MOD y.<br>
    Then quotient q and remainder r are defined by the equation<br>
    x = q*y + r              0 <= r < y"<br>
<br>
    Last statement obviously cannot be met if y is negative.<br>
<br>
    So in short: Don't use DIV/MOD for negative divisors as the result<br>
    is not defined.<br>
<br>
    >From the implemtation point of view this perfectly makes sense as<br>
    negative divisors are seldom used and correction for DIV of the<br>
    usually stupid hardware implementation only takes 3 additional<br>
    instructions compared to at least 6 for a complete definition.<br>
    Simple SHIFT/AND instructions for power of 2 divisors easily<br>
    outwight these 3 additional instructions.<br>
<br>
<br>
    Peter<br>
<br>
    --<br></div></div>
    <a href="mailto:Oberon@lists.inf.ethz.ch" target="_blank">Oberon@lists.inf.ethz.ch</a> <mailto:<a href="mailto:Oberon@lists.inf.ethz.ch" target="_blank">Oberon@lists.inf.ethz.<wbr>ch</a>> mailing<span class=""><br>
    list for ETH Oberon and related systems<br>
    <a href="https://lists.inf.ethz.ch/mailman/listinfo/oberon" rel="noreferrer" target="_blank">https://lists.inf.ethz.ch/mail<wbr>man/listinfo/oberon</a><br>
    <<a href="https://lists.inf.ethz.ch/mailman/listinfo/oberon" rel="noreferrer" target="_blank">https://lists.inf.ethz.ch/mai<wbr>lman/listinfo/oberon</a>><br>
<br>
<br>
<br>
<br>
--<br>
Aubrey McIntosh, Ph.D.<br>
1502 Devon Circle<br>
Austin TX 78723<br>
<a href="tel:%28512%29%20348-7401" value="+15123487401" target="_blank">(512) 348-7401</a><br>
<br>
<br>
<br>
--<br>
<a href="mailto:Oberon@lists.inf.ethz.ch" target="_blank">Oberon@lists.inf.ethz.ch</a> mailing list for ETH Oberon and related systems<br>
<a href="https://lists.inf.ethz.ch/mailman/listinfo/oberon" rel="noreferrer" target="_blank">https://lists.inf.ethz.ch/mail<wbr>man/listinfo/oberon</a><br>
<br>
</span></blockquote><div class="HOEnZb"><div class="h5">
--<br>
<a href="mailto:Oberon@lists.inf.ethz.ch" target="_blank">Oberon@lists.inf.ethz.ch</a> mailing list for ETH Oberon and related systems<br>
<a href="https://lists.inf.ethz.ch/mailman/listinfo/oberon" rel="noreferrer" target="_blank">https://lists.inf.ethz.ch/mail<wbr>man/listinfo/oberon</a><br>
</div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr">Aubrey McIntosh, Ph.D.<div>1502 Devon Circle</div><div>Austin TX 78723</div><div>(512) 348-7401</div><div><br></div></div></div>
</div>