This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Question about precise definition FLOOR_MOD_EXPR


kenner@vlsi1.ultra.nyu.edu (Richard Kenner) writes:

> What should the result of <FLOOR_MOD_EXPR 11 -5> be?
> 
> There is recent code added to fold that says that the negation can be ignored
> so this should be 1.
> 
> However, if the "-5" is a variable and you let it be evaluated at runtime,
> the result is -4.
> 
> I think it's a bad idea that folding produces a different result than
> executing the computation at run-time.
> 
> Moreover, what *is* the result supposed to be?  The Ada standard is clear
> that it should be -4.  From looking at the online version of the C
> standard, I can't tell whether 1, -4 or choosing either at random is
> a valid result.  Does anybody know?  How about C++?  Java?  Does this
> come up in Fortran?

I believe that FLOOR_MOD_EXPR has the property that 

x == (x FLOOR_DIV_EXPR y) * y + (x FLOOR_MOD_EXPR y)

just as TRUNC_MOD corresponds to TRUNC_DIV.

So, in this case, the result of the divide is -3, and so the result of
the modulo is -4, and fold() is wrong.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]