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

--- Comment #43 from Vincent Lefèvre <vincent-gcc at vinc17 dot net> ---
Note that the effect of changing the rounding mode after a computation, whether
-frounding-math is used or not, is not just that the change of rounding mode
may not be honored. If can yield inconsistencies in a block where the rounding
mode is not changed.

#include <stdio.h>
#include <stdlib.h>
#include <fenv.h>

#pragma STDC FENV_ACCESS ON

#define CST 0x1p-200

int main (void)
{
  volatile double a = CST;
  double b = a, c = a, d;
  printf ("%a\n", 1.0 - b);
  fesetround (FE_DOWNWARD);
  printf ("%a\n", 1.0 - c);

  if (b == c && b == CST && c == CST)
    {
      printf ("%d\n", 1.0 - b == 1.0 - c);
      printf ("1: %a\n", 1.0 - b);
      printf ("2: %a\n", 1.0 - c);
      d = b == CST ? b : (abort (), 1.0);
      printf ("3: %a\n", 1.0 - d);
      d = b == CST ? b : 1.0;
      printf ("4: %a\n", 1.0 - d);
    }

  return 0;
}

With -std=c17 -frounding-math -O3 -lm, I get:

0x1p+0
0x1.fffffffffffffp-1
0
1: 0x1p+0
2: 0x1.fffffffffffffp-1
3: 0x1p+0
4: 0x1.fffffffffffffp-1

Reply via email to