https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114050
Bug ID: 114050 Summary: Inconsistency in double/float constant evaluation between 32 and 64 bit Product: gcc Version: 13.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: sjh at schilling dot dk Target Milestone: --- Created attachment 57491 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=57491&action=edit The test application In GCC version 13 and later, we've found some inconsistency in the way the compiler calculates double constants in our code. We originally discovered this in a rounding unit test in our code, and have extracted the specific inconsistency in attached double-test.cpp. When compiling in default 64-bit mode on the x86 platform, we get the consistent result of previous GCC versions (the output from the test code is the same constant double value calculated in three different ways, and dumped as hex as well): g++ -std=c++23 -m64 -o double-test double-test.cpp ./double-test Output: GCC version: 13.2.0 a = -5.42101e-20 ( 00 00 00 00 00 00 f0 bb ) b = -5.42101e-20 ( 00 00 00 00 00 00 f0 bb ) c = -5.42101e-20 ( 00 00 00 00 00 00 f0 bb ) However, compiling the same application in 32-bit mode yields a different result: g++ -std=c++23 -m32 -o double-test double-test.cpp ./double-test Output: GCC version: 13.2.0 a = -4.06576e-20 ( 00 00 00 00 00 00 e8 bb ) b = 0 ( 00 00 00 00 00 00 00 00 ) c = -4.06576e-20 ( 00 00 00 00 00 00 e8 bb ) If using gnu extensions as the selected standard, we're back to the old, consistent behavior, also for 32 bits: g++ -std=gnu++23 -m32 -o double-test double-test.cpp ./double-test Output: GCC version: 13.2.0 a = -5.42101e-20 ( 00 00 00 00 00 00 f0 bb ) b = -5.42101e-20 ( 00 00 00 00 00 00 f0 bb ) c = -5.42101e-20 ( 00 00 00 00 00 00 f0 bb ) We have only seen the problem in 32 bit mode with one of the strict c++ standards selected (-std=c++*), not with gnu extensions (-std=gnu++*). Testing various versions on the Compiler Explorer site, the problem seems to occur as of version 13 of GCC. g++ -v output: Using built-in specs. COLLECT_GCC=g++ COLLECT_LTO_WRAPPER=/usr/local/schilling/gcc-13.2.0/libexec/gcc/x86_64-pc-linux-gnu/13.2.0/lto-wrapper Target: x86_64-pc-linux-gnu Configured with: ../gcc-13.2.0/configure --prefix=/usr/local/schilling/gcc-13.2.0 --enable-shared --enable-threads=posix --enable-__cxa_atexit --enable-clocale=gnu --enable-languages=c,c++ --enable-multilib --disable-bootstrap --with-system-zlib Thread model: posix Supported LTO compression algorithms: zlib gcc version 13.2.0 (GCC)