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

            Bug ID: 103962
           Summary: 'long double' to 'int' cast modifies rounding bits
           Product: gcc
           Version: 9.4.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: master_szumi at o2 dot pl
  Target Milestone: ---
            Target: powerpc

Following code:

$ cat main2.c
#include <stdio.h>

// #define FIX

int main() {
    double a=54;
    double b=10;
    long double g=3;
    int i = 0;
    printf("%f\n", a/b);
    i=g;
#ifdef FIX
    __asm__("mtfsb0  31\n\t");
#endif
    printf("%f\n", a/b);
    return 0;
}

Compiled with:

/usr/bin/powerpc-e500v2-linux-gnu-gcc main2.c

Prints:

# ./a.out
5.400000
5.399999

IMO Rounding bit should be restored after 'cast' operation but they are not.

Reply via email to