Skip to content

Commit 23342ef

Browse files
dlechdpgeorge
authored andcommitted
windows/Makefile: Fix float exact int formatting on 32-bit mingw.
When compiler optimizations are enabled on the mingw version of gcc, we are getting failing tests because of rounding issues, for example: print(float("1e24")) would print 9.999999999999999e+23 instead of 1e+24 It turns out special compiler options are needed to get GCC to use the SSE instruction set instead of the 387 coprocessor (which uses 80-bit precision internall). Signed-off-by: David Lechner <[email protected]>
1 parent ac8e7f7 commit 23342ef

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

ports/windows/Makefile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,15 @@ ifneq ($(FROZEN_MANIFEST),)
8686
CFLAGS += -DMPZ_DIG_SIZE=16
8787
endif
8888

89+
ifeq ($(shell $(CC) -dumpmachine),i686-w64-mingw32)
90+
# GCC disables the SSE instruction set by default on i366 targets and we have
91+
# to specify all three of these options to enable it.
92+
# https://gcc.gnu.org/onlinedocs/gcc/x86-Options.html (see -mfpmath=unit section)
93+
# Enabling the SSE instruction set is necessary to get correct rounding of floating points.
94+
# https://lemire.me/blog/2020/06/26/gcc-not-nearest
95+
CFLAGS += -msse -mfpmath=sse -march=pentium4
96+
endif
97+
8998
CXXFLAGS += $(filter-out -std=gnu99,$(CFLAGS))
9099

91100
include $(TOP)/py/mkrules.mk

0 commit comments

Comments
 (0)