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]

Re: /internet


Jeffrey A Law writes ...
> 
> You understand my suggestions correctly.
> 
> But I'm neither a language lawyer, nor an ieee/fp expert, so you have to take
> my suggestions with some care.  I certainly wouldn't actually make such changes
> without being 100% they're safe according to the language specs and don't
> violate the principle of least suprise too often.  For that I would have to
> lean on folks in on this list to guide me through the pitfalls of each
> language and ieee/fp.

I believe the example you were talking about yesterday violates IEEE,
since the reordering you suggested can change the value of the result
(by causing an intermediate (c*d) to overflow, when left to right
evaluation would not cause an overflow):

#include <math.h>

int main() {
    int z = 400;

    double a = scalb(1, -z);
    double b = scalb(1, -z);
    double c = scalb(1, z);
    double d = scalb(1, 2*z);

    double t1, t2, t3;

    t1 = a*b;
    t2 = t1*c;
    t3 = t2*d;

    printf("--> %g\n", t3);

    t1 = a * b;
    t2 = c * d;
    t3 = t1 * t2;

    printf("--> %g\n", t3);
}

---output---
--> 2.58225e+120
--> inf

---------------------------------------------------------------------------
Tim Hollebeek                           | "Everything above is a true
email: tim@wfn-shop.princeton.edu       |  statement, for sufficiently
URL: http://wfn-shop.princeton.edu/~tim |  false values of true."


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