https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103406

            Bug ID: 103406
           Summary: gcc -O0 behaves differently on "DBL_MAX related
                    operations" than gcc -O1 and above
           Product: gcc
           Version: 11.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: shaohua.li at inf dot ethz.ch
  Target Milestone: ---

Hi there,

I found that for a piece of code, gcc would give out different results when
compiled with different opt flags.

- gcc version: 11.1.0

- Platform: Ubuntu 20.04, x86_64

$gcc a.c -O0; ./a.out
nan
$
$
$gcc a.c -O1; ./a.out
-nan
$
$
$cat a.c

#include <stdio.h>
#include <float.h>

#define INFINITY (DBL_MAX+DBL_MAX)
#define NAN (INFINITY-INFINITY)

void main() {
  double x = -NAN;
  double y = NAN;
  double z = x + y;
  printf("%lf\n", z);
}

Reply via email to