Skip to content

Commit edbc28c

Browse files
committed
#21167: Fix definition of NAN when ICC used without -fp-model strict.
Patch from Chris Hogan of Intel, reviewed by Mark Dickinson.
1 parent 9632ea2 commit edbc28c

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

Include/pymath.h

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,29 @@ PyAPI_FUNC(void) _Py_set_387controlword(unsigned short);
150150
* doesn't support NaNs.
151151
*/
152152
#if !defined(Py_NAN) && !defined(Py_NO_NAN)
153-
#define Py_NAN (Py_HUGE_VAL * 0.)
153+
#if !defined(__INTEL_COMPILER)
154+
#define Py_NAN (Py_HUGE_VAL * 0.)
155+
#else /* __INTEL_COMPILER */
156+
#if defined(ICC_NAN_STRICT)
157+
#pragma float_control(push)
158+
#pragma float_control(precise, on)
159+
#pragma float_control(except, on)
160+
#if defined(_MSC_VER)
161+
__declspec(noinline)
162+
#else /* Linux */
163+
__attribute__((noinline))
164+
#endif /* _MSC_VER */
165+
static double __icc_nan()
166+
{
167+
return sqrt(-1.0);
168+
}
169+
#pragma float_control (pop)
170+
#define Py_NAN __icc_nan()
171+
#else /* ICC_NAN_RELAXED as default for Intel Compiler */
172+
static union { unsigned char buf[8]; double __icc_nan; } __nan_store = {0,0,0,0,0,0,0xf8,0x7f};
173+
#define Py_NAN (__nan_store.__icc_nan)
174+
#endif /* ICC_NAN_STRICT */
175+
#endif /* __INTEL_COMPILER */
154176
#endif
155177

156178
/* Py_OVERFLOWED(X)

Misc/ACKS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,7 @@ Gregor Hoffleit
583583
Chris Hoffman
584584
Stefan Hoffmeister
585585
Albert Hofkamp
586+
Chris Hogan
586587
Tomas Hoger
587588
Jonathan Hogg
588589
Kamilla Holanda

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ Release date: tba
1010
Core and Builtins
1111
-----------------
1212

13+
- Issue #21167: NAN operations are now handled correctly when python is
14+
compiled with ICC even if -fp-model strict is not specified.
15+
1316
- Issue #4395: Better testing and documentation of binary operators.
1417
Patch by Martin Panter.
1518

0 commit comments

Comments
 (0)