Skip to content

Commit e58d368

Browse files
committed
py/formatfloat: Fix 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. Signed-off-by: David Lechner <david@pybricks.com>
1 parent bb77c1d commit e58d368

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
@@ -84,6 +84,15 @@ ifneq ($(FROZEN_MANIFEST),)
8484
CFLAGS += -DMICROPY_QSTR_EXTRA_POOL=mp_qstr_frozen_const_pool -DMICROPY_MODULE_FROZEN_MPY=1 -DMPZ_DIG_SIZE=16
8585
endif
8686

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

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

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy