https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114347
Bug ID: 114347 Summary: wrong constant folding when casting __bf16 to int Product: gcc Version: 13.2.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: eggert at cs dot ucla.edu Target Milestone: --- This is gcc (GCC) 13.2.1 20231205 (Red Hat 13.2.1-6) on Fedora 39. I found this bug when looking into a GNU coreutils report <https://bugs.gnu.org/69770> originally reported against Clang (Clang has a different bug). Compile and run this program: __bf16 x = 257.0bf16; int main (void) { return (int) x != (int) 257.0bf16; } with "gcc -O2 v.c; ./a.out; echo $?". This prints "1"; it should print "0". The problem is that GCC constant-folds '(int) 257.0bf16' to 257. This is incorrect, as 257.0bf16 is exactly equal to 256.0bf16, due to rounding when the constant is parsed. The expression '(int) x' correctly yields 256 at runtime, and 256 is not equal to the 257 incorrectly yielded by the constant folding.