Skip to content

Commit 2fbf141

Browse files
committed
fix Py_NAN on Solaris systems
1 parent 6c81e8c commit 2fbf141

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

Include/pymath.h

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,24 @@
5757

5858
/* Py_NAN: Value that evaluates to a quiet Not-a-Number (NaN). The sign is
5959
* undefined and normally not relevant, but e.g. fixed for float("nan").
60+
*
61+
* Note: On Solaris, NAN is a function address, hence arithmetic is impossible.
62+
* For that reason, we instead use the built-in call if available or fallback
63+
* to a generic NaN computed from strtod() as a last resort.
64+
*
65+
* See https://github.com/python/cpython/issues/136006 for details.
6066
*/
6167
#if !defined(Py_NAN)
62-
# define Py_NAN ((double)NAN)
68+
# if defined(__sun)
69+
# if _Py__has_builtin(__builtin_nanf)
70+
# define Py_NAN ((double)__builtin_nanf(""))
71+
# else
72+
# include <stdlib.h>
73+
# define Py_NAN (strtod("NAN", NULL))
74+
# endif
75+
# else
76+
# define Py_NAN ((double)NAN)
77+
# endif
6378
#endif
6479

6580
#endif /* Py_PYMATH_H */
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
On Solaris, the :c:macro:`Py_NAN` macro now expands to a :c:type:`double`
2+
instead of a function address. Patch by Bénédikt Tran.

0 commit comments

Comments
 (0)