https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109359
Bug ID: 109359
Summary: Compile-time rounding of double literal to float is
incorrect with -frounding-math
Product: gcc
Version: 13.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: rcopley at gmail dot com
Target Milestone: ---
The following program should print:
0.001914
0.630538
With "g++ -frounding-math", it prints instead:
-8023756970655744.000000
0.872496
This bug is present in trunk, and since gcc 12.1, and does not appear to be
platform specific.
Compiler explorer link: https://godbolt.org/z/aMhcYcY66
#include <cstdio>
float xs[] = {0.001914, 0.630539};
int main() {
std::size_t size = sizeof xs / sizeof xs[0];
for (std::size_t i = 0; i != size; ++i) {
std::printf("%f\n", xs[i]);
}
}