From 85cffe268e2c4d7585e589ddb4e38bf7f61f5fb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A9n=C3=A9dikt=20Tran?= <10796600+picnixz@users.noreply.github.com> Date: Tue, 8 Jul 2025 22:06:25 +0200 Subject: [PATCH] fix `Py_NAN` on Solaris systems --- Include/pymath.h | 17 ++++++++++++++++- ...25-07-08-22-07-54.gh-issue-136006.XRU5w4.rst | 2 ++ 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 Misc/NEWS.d/next/C_API/2025-07-08-22-07-54.gh-issue-136006.XRU5w4.rst diff --git a/Include/pymath.h b/Include/pymath.h index 0ead1f95670fde..e2919c7b527267 100644 --- a/Include/pymath.h +++ b/Include/pymath.h @@ -57,9 +57,24 @@ /* Py_NAN: Value that evaluates to a quiet Not-a-Number (NaN). The sign is * undefined and normally not relevant, but e.g. fixed for float("nan"). + * + * Note: On Solaris, NAN is a function address, hence arithmetic is impossible. + * For that reason, we instead use the built-in call if available or fallback + * to a generic NaN computed from strtod() as a last resort. + * + * See https://github.com/python/cpython/issues/136006 for details. */ #if !defined(Py_NAN) -# define Py_NAN ((double)NAN) +# if defined(__sun) +# if _Py__has_builtin(__builtin_nanf) +# define Py_NAN ((double)__builtin_nanf("")) +# else +# include +# define Py_NAN (strtod("NAN", NULL)) +# endif +# else +# define Py_NAN ((double)NAN) +# endif #endif #endif /* Py_PYMATH_H */ diff --git a/Misc/NEWS.d/next/C_API/2025-07-08-22-07-54.gh-issue-136006.XRU5w4.rst b/Misc/NEWS.d/next/C_API/2025-07-08-22-07-54.gh-issue-136006.XRU5w4.rst new file mode 100644 index 00000000000000..2165e535b12245 --- /dev/null +++ b/Misc/NEWS.d/next/C_API/2025-07-08-22-07-54.gh-issue-136006.XRU5w4.rst @@ -0,0 +1,2 @@ +On Solaris, the :c:macro:`!Py_NAN` macro now expands to a :c:type:`!double` +instead of a function address. Patch by Bénédikt Tran.