This is the mail archive of the gcc-bugs@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]

Floating point


    Hi.

    I'm using gcc on Linux for x86 (I've tried different Linuxes and
compiler versions with the same results) and have strange error. If we
compile this source:
#include <stdio.h>

int main(int argc, char *argv[]) {
    double d1 = 1;
    double d2 = (double)((1L<<12) + 1)/(1L<<12)/(1LL<<53);
    double d3 = 1 + (double)((1L<<12) + 1)/(1L<<12)/(1LL<<53);
    d1 += d2;
    printf("%.70lf\n", d1);
    printf("%.70lf\n", d3);
    return 0;
}

    We will see that first (d1) value will be 1.0 but d3 is little bit more
than 1.0. And the d3 value is correct.
    If you will try this example on sparc-S2 (with SPARCompiler) or on Win32
with MSVC both results will be the same and correct.

    Is this gcc bug? Or I can tell some option and everything will be ok ;)

    SY, Alexei



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