8000 py/objfloat: Workaround non-constant NAN definition on Windows MSVC. · micropython/micropython@564ef28 · GitHub
[go: up one dir, main page]

Skip to content

Commit 564ef28

Browse files
projectgusdpgeorge
authored andcommitted
py/objfloat: Workaround non-constant NAN definition on Windows MSVC.
Recent MSVC versions have changed the definition of NAN to a non-constant expression! This is a bug, C standard says it should be a constant. Good explanation and workaround at: https://stackoverflow.com/a/79199887 This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
1 parent 7118942 commit 564ef28

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

py/objfloat.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,13 @@
4747
#define M_PI (3.14159265358979323846)
4848
#endif
4949

50+
// Workaround a bug in recent MSVC where NAN is no longer constant.
51+
// (By redefining back to the previous MSVC definition of NAN)
52+
#if defined(_MSC_VER) && _MSC_VER >= 1942
53+
#undef NAN
54+
#define NAN (-(float)(((float)(1e+300 * 1e+300)) * 0.0F))
55+
#endif
56+
5057
typedef struct _mp_obj_float_t {
5158
mp_obj_base_t base;
5259
mp_float_t value;

0 commit comments

Comments
 (0)
0