gm2
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Gm2] Behaviour of DIV and MOD in PIM4


From: Gaius Mulley
Subject: Re: [Gm2] Behaviour of DIV and MOD in PIM4
Date: Wed, 23 Mar 2016 10:32:39 +0000
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux)

Benjamin Kowarsch <address@hidden> writes:

> It looks like you are just handing these operations off to the C back
> end of GCC. M2 uses Euclidean DIV/MOD but C uses truncated DIV/MOD
> They produce identical results for positive arguments, but different
> results for negative arguments. I have the same issue in M2C and need
> to supply my own DIV/MOD instead of translating 1:1 from AST to C.

Hi Benjamin,

yes indeed currently gm2 uses the GCC internal routines floor_mod,
floor_div for pim4 which is wrong.  I need to test the right hand
operand >=0 and then use floor_mod, floor_div else use ceil_mod,
ceil_div!

I was thinking of adding an optional -fwhatever runtime check for
negative values given that this might appear quite dangerous,

regards,
Gaius


> On 23 March 2016 at 00:38, Gaius Mulley
> <address@hidden> wrote:
>
>     Xin Wang <address@hidden> writes:
>     
>     > Hi,
>     >
>     > Behaviour of DIV and MOD in PIM4 seems to be not consistant with
>     document[1].
>     >
>     > When compiling with gcc-4.7.4+gm2-1.1.5:
>     >
>     > 31 DIV (-10) = -4
>     > 31 MOD (-10) = -9
>     > (-31) DIV (-10) = +3
>     > (-31) MOD (-10) = -1
>     >
>     > Which is different from document:
>     >
>     > lval rval DIV MOD
>     > 31 -10 -3 1
>     > -31 -10 4 9
>     >
>     > [1] http://www.nongnu.org/gm2/dialect.html
>     
>     Hi Xin,
>     
>     many thanks for the bug report - indeed you are correct. I've
>     checked
>     the examples and documentation and can confirm the documentation
>     is
>     correct. I've written more test code and will produce a fix
>     shortly,
>     
>     regards,
>     Gaius
>     
>     
>     
>     _______________________________________________
>     gm2 mailing list
>     address@hidden
>     https://lists.nongnu.org/mailman/listinfo/gm2
>     



reply via email to

[Prev in Thread] Current Thread [Next in Thread]