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]

C9X reassociation rules



These quoted remarks explain that reassociation must not be
carried further than Jeff proposed (as it is in some existing
compilers).  They do not prohibit the reassociation which Jeff
proposed, which is in the category of what has been expected in
Fortran, and was specifically allowed according to my copy of
C9X, which I quoted earlier.

Each example is a case where a syntax barrier has been set
against reassociation (usually parentheses or an assignment
operator).

I suppose that the C9X people are striving to avoid leaving things
unsaid which need to be said, without falling in the trap of having
to explain explanations.  If the programmer wishes to allow
some of the reassociations which are prohibited in these cases,
it's simple enough to change the source code, as follows:

               x = x * y * z;  // may be interpreted as x *= y * z;
               z = x - y + y ; // may be interpreted as z = x;
               y = x / (1/5.0);      // may be interpreted as y = x * 0.2;

The other example
               z = x + x * y;    // not equivalent to z = x * (1.0 + y);
is an interesting case, where the prohibited transformation
almost certainly will lose accuracy, and is unlikely to gain speed.
It's typical of the way series approximations of math functions
should be written.

Here is the quoted original:

      In  the  following  fragment,  rearrangements  suggested  by
       mathematical rules for real numbers are often not valid (see
       F.8).

               double x, y, z;
               /* ... */
               x = (x * y) * z;  // not equivalent to x *= y * z;
               z = (x - y) + y ; // not equivalent to z = x;
               z = x + x * y;    // not equivalent to z = x * (1.0 + y);
               y = x / 5.0;      // not equivalent to y = x * 0.2;

 >>>
Date: Wed, 16 Dec 1998 14:45:23 -0500 (EST)
From: Stephen L Moshier <>
T
> Does IEEE require left-to-right evaluation of y = a * b * c * d;
> when there are no parentheses present?

I think that IEEE does not actually say anything about it.  C9X,
however,
does contain some remarks such as the following, which might
have come
from NCEG.


Dr. Timothy C. Prince
Consulting Engineer
Solar Turbines, a Caterpillar Company
alternate e-mail: tprince@computer.org

           To:                                              INTERNET - IBMMAIL
                                                            N4409435 - IBMMAIL


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