From 654f3135281a567edea31178aab204725ed544a2 Mon Sep 17 00:00:00 2001 From: Mark Wiebe Date: Thu, 2 Dec 2010 23:20:47 -0800 Subject: [PATCH 1/2] BUG: core: Some fixes and clean up of floating point exception code --- numpy/core/include/numpy/npy_math.h | 10 +++ numpy/core/include/numpy/ufuncobject.h | 80 +++-------------- numpy/core/src/npymath/halffloat.c | 31 ++++--- numpy/core/src/npymath/ieee754.c.src | 119 +++++++++++++++++++++++++ numpy/core/src/scalarmathmodule.c.src | 20 ++--- numpy/core/src/umath/loops.c.src | 12 +-- numpy/core/tests/test_errstate.py | 4 +- numpy/core/tests/test_half.py | 45 +++++----- numpy/core/tests/test_numeric.py | 6 +- 9 files changed, 205 insertions(+), 122 deletions(-) diff --git a/numpy/core/include/numpy/npy_math.h b/numpy/core/include/numpy/npy_math.h index abdb34d21997..ba1c50ddef54 100644 --- a/numpy/core/include/numpy/npy_math.h +++ b/numpy/core/include/numpy/npy_math.h @@ -422,4 +422,14 @@ npy_clongdouble npy_csqrtl(npy_clongdouble z); npy_clongdouble npy_ccosl(npy_clongdouble z); npy_clongdouble npy_csinl(npy_clongdouble z); +/* + * Functions that set the floating point error + * status word. + */ + +void npy_set_floatstatus_divbyzero(void); +void npy_set_floatstatus_overflow(void); +void npy_set_floatstatus_underflow(void); +void npy_set_floatstatus_invalid(void); + #endif diff --git a/numpy/core/include/numpy/ufuncobject.h b/numpy/core/include/numpy/ufuncobject.h index 35d173cda42a..544669e7d40d 100644 --- a/numpy/core/include/numpy/ufuncobject.h +++ b/numpy/core/include/numpy/ufuncobject.h @@ -1,5 +1,8 @@ #ifndef Py_UFUNCOBJECT_H #define Py_UFUNCOBJECT_H + +#include + #ifdef __cplusplus extern "C" { #endif @@ -322,11 +325,6 @@ typedef struct _loop1d_info { FE_UNDERFLOW | FE_INVALID); \ } -#define generate_divbyzero_error() feraiseexcept(FE_DIVBYZERO) -#define generate_overflow_error() feraiseexcept(FE_OVERFLOW) -#define generate_underflow_error() feraiseexcept(FE_UNDERFLOW) -#define generate_invalid_error() feraiseexcept(FE_INVALID) - #elif defined(_AIX) #include @@ -334,7 +332,7 @@ typedef struct _loop1d_info { #define UFUNC_CHECK_STATUS(ret) { \ fpflag_t fpstatus; \ - \ + \ fpstatus = fp_read_flag(); \ ret = ((FP_DIV_BY_ZERO & fpstatus) ? UFUNC_FPE_DIVIDEBYZERO : 0) \ | ((FP_OVERFLOW & fpstatus) ? UFUNC_FPE_OVERFLOW : 0) \ @@ -343,77 +341,21 @@ typedef struct _loop1d_info { fp_swap_flag(0); \ } -#define generate_divbyzero_error() fp_raise_xcp(FP_DIV_BY_ZERO) -#define generate_overflow_error() fp_raise_xcp(FP_OVERFLOW) -#define generate_underflow_error() fp_raise_xcp(FP_UNDERFLOW) -#define generate_invalid_error() fp_raise_xcp(FP_INVALID) - #else #define NO_FLOATING_POINT_SUPPORT #define UFUNC_CHECK_STATUS(ret) { \ - ret = 0; \ + ret = 0; \ } #endif -/* These should really be altered to just set the corresponding bit - in the floating point status flag. Need to figure out how to do that - on all the platforms... -*/ - -#if !defined(generate_divbyzero_error) -static int numeric_zero2 = 0; -static void generate_divbyzero_error(void) { - double dummy; - dummy = 1./numeric_zero2; - if (dummy) /* to prevent optimizer from eliminating expression */ - return; - else /* should never be called */ - numeric_zero2 += 1; - return; -} -#endif - -#if !defined(generate_overflow_error) -static double numeric_two = 2.0; -static void generate_overflow_error(void) { - double dummy; - dummy = pow(numeric_two,1000); - if (dummy) - return; - else - numeric_two += 0.1; - return; - return; -} -#endif - -#if !defined(generate_underflow_error) -static double numeric_small = 1e-300; -static void generate_underflow_error(void) { - double dummy; - dummy = numeric_small * 1e-300; - if (!dummy) - return; - else - numeric_small += 1e-300; - return; -} -#endif - -#if !defined(generate_invalid_error) -static double numeric_inv_inf = NPY_INF; -static void generate_invalid_error(void) { - double dummy; - dummy = numeric_inv_inf - NPY_INF; - if (!dummy) - return; - else - numeric_inv_inf += 1.0; - return; -} -#endif +/* + * THESE MACROS ARE DEPRECATED. + * Use npy_set_floatstatus_* in the npymath library. + */ +#define generate_divbyzero_error() npy_set_floatstatus_dividebyzero() +#define generate_overflow_error() npy_set_floatstatus_overflow() /* Make sure it gets defined if it isn't already */ #ifndef UFUNC_NOFPE diff --git a/numpy/core/src/npymath/halffloat.c b/numpy/core/src/npymath/halffloat.c index da92d3e128b6..79f77197bc12 100644 --- a/numpy/core/src/npymath/halffloat.c +++ b/numpy/core/src/npymath/halffloat.c @@ -77,11 +77,16 @@ npy_half npy_half_spacing(npy_half h) npy_half ret; npy_uint16 h_exp = h&0x7c00u; npy_uint16 h_sig = h&0x03ffu; - if (h_exp == 0x7c00u || h == 0x7bffu) { + if (h_exp == 0x7c00u) { #if NPY_HALF_GENERATE_INVALID - generate_invalid_error(); + npy_set_floatstatus_invalid(); #endif ret = NPY_HALF_NAN; + } else if (h == 0x7bffu) { +#if NPY_HALF_GENERATE_OVERFLOW + npy_set_floatstatus_overflow(); +#endif + ret = NPY_HALF_PINF; } else if ((h&0x8000u) && h_sig == 0) { /* Negative boundary case */ if (h_exp > 0x2c00u) { /* If result is normalized */ ret = h_exp - 0x2c00u; @@ -112,7 +117,7 @@ npy_half npy_half_nextafter(npy_half x, npy_half y) if (!npy_half_isfinite(x) || npy_half_isnan(y)) { #if NPY_HALF_GENERATE_INVALID - generate_invalid_error(); + npy_set_floatstatus_invalid(); #endif ret = NPY_HALF_NAN; } else if (npy_half_eq_nonan(x, y)) { @@ -134,7 +139,7 @@ npy_half npy_half_nextafter(npy_half x, npy_half y) } #ifdef NPY_HALF_GENERATE_OVERFLOW if (npy_half_isinf(ret)) { - generate_overflow_error(); + npy_set_floatstatus_overflow(); } #endif @@ -255,7 +260,7 @@ npy_uint16 npy_floatbits_to_halfbits(npy_uint32 f) } else { /* overflow to signed inf */ #if NPY_HALF_GENERATE_OVERFLOW - generate_overflow_error(); + npy_set_floatstatus_overflow(); #endif return (npy_uint16) (h_sgn + 0x7c00u); } @@ -271,7 +276,7 @@ npy_uint16 npy_floatbits_to_halfbits(npy_uint32 f) #if NPY_HALF_GENERATE_UNDERFLOW /* If f != 0, it underflowed to 0 */ if ((f&0x7fffffff) != 0) { - generate_underflow_error(); + npy_set_floatstatus_underflow(); } #endif return h_sgn; @@ -282,7 +287,7 @@ npy_uint16 npy_floatbits_to_halfbits(npy_uint32 f) #if NPY_HALF_GENERATE_UNDERFLOW /* If it's not exactly represented, it underflowed */ if ((f_sig&(((npy_uint32)1 << (126 - f_exp)) - 1)) != 0) { - generate_underflow_error(); + npy_set_floatstatus_underflow(); } #endif f_sig >>= (113 - f_exp); @@ -334,7 +339,7 @@ npy_uint16 npy_floatbits_to_halfbits(npy_uint32 f) #if NPY_HALF_GENERATE_OVERFLOW h_sig += h_exp; if (h_sig == 0x7c00u) { - generate_overflow_error(); + npy_set_floatstatus_overflow(); } return h_sgn + h_sig; #else @@ -370,7 +375,7 @@ npy_uint16 npy_doublebits_to_halfbits(npy_uint64 d) } else { /* overflow to signed inf */ #if NPY_HALF_GENERATE_OVERFLOW - generate_overflow_error(); + npy_set_floatstatus_overflow(); #endif return h_sgn + 0x7c00u; } @@ -385,8 +390,8 @@ npy_uint16 npy_doublebits_to_halfbits(npy_uint64 d) if (d_exp < 0x3e60000000000000u) { #if NPY_HALF_GENERATE_UNDERFLOW /* If d != 0, it underflowed to 0 */ - if ((d&0x7fffffffffffffff) != 0) { - generate_underflow_error(); + if ((d&0x7fffffffffffffffu) != 0) { + npy_set_floatstatus_underflow(); } #endif return h_sgn; @@ -397,7 +402,7 @@ npy_uint16 npy_doublebits_to_halfbits(npy_uint64 d) #if NPY_HALF_GENERATE_UNDERFLOW /* If it's not exactly represented, it underflowed */ if ((d_sig&(((npy_uint64)1 << (1051 - d_exp)) - 1)) != 0) { - generate_underflow_error(); + npy_set_floatstatus_underflow(); } #endif d_sig >>= (1009 - d_exp); @@ -450,7 +455,7 @@ npy_uint16 npy_doublebits_to_halfbits(npy_uint64 d) #if NPY_HALF_GENERATE_OVERFLOW h_sig += h_exp; if (h_sig == 0x7c00u) { - generate_overflow_error(); + npy_set_floatstatus_overflow(); } return h_sgn + h_sig; #else diff --git a/numpy/core/src/npymath/ieee754.c.src b/numpy/core/src/npymath/ieee754.c.src index 8df903b2bcf5..14d3f4a90b55 100644 --- a/numpy/core/src/npymath/ieee754.c.src +++ b/numpy/core/src/npymath/ieee754.c.src @@ -548,3 +548,122 @@ npy_longdouble npy_nextafterl(npy_longdouble x, npy_longdouble y) return nextafterl(x, y); } #endif + +/* + * Functions to set the floating point status word. + */ + +#if defined(sun) || defined(__BSD__) || defined(__OpenBSD__) || (defined(__FreeBSD__) && (__FreeBSD_version < 502114)) || defined(__NetBSD__) +#include + +void npy_set_floatstatus_divbyzero(void) +{ + fpsetsticky(FP_X_DZ); +} + +void npy_set_floatstatus_overflow(void) +{ + fpsetsticky(FP_X_OFL); +} + +void npy_set_floatstatus_underflow(void) +{ + fpsetsticky(FP_X_UFL); +} + +void npy_set_floatstatus_invalid(void) +{ + fpsetsticky(FP_X_INV); +} + + +#elif defined(__GLIBC__) || defined(__APPLE__) || defined(__CYGWIN__) || defined(__MINGW32__) || (defined(__FreeBSD__) && (__FreeBSD_version >= 502114)) + +# if defined(__GLIBC__) || defined(__APPLE__) || defined(__MINGW32__) || defined(__FreeBSD__) +# include +# elif defined(__CYGWIN__) +# include "fenv/fenv.c" +# endif + +void npy_set_floatstatus_divbyzero(void) +{ + feraiseexcept(FE_DIVBYZERO); +} + +void npy_set_floatstatus_overflow(void) +{ + feraiseexcept(FE_OVERFLOW); +} + +void npy_set_floatstatus_underflow(void) +{ + feraiseexcept(FE_UNDERFLOW); +} + +void npy_set_floatstatus_invalid(void) +{ + feraiseexcept(FE_INVALID); +} + +#elif defined(_AIX) +#include +#include + +void npy_set_floatstatus_divbyzero(void) +{ + fp_raise_xcp(FP_DIV_BY_ZERO); +} + +void npy_set_floatstatus_overflow(void) +{ + fp_raise_xcp(FP_OVERFLOW); +} + +void npy_set_floatstatus_underflow(void) +{ + fp_raise_xcp(FP_UNDERFLOW); +} + +void npy_set_floatstatus_invalid(void) +{ + fp_raise_xcp(FP_INVALID); +} + +#else + +/* + * By using a volatile floating point value, + * the compiler is forced to actually do the requested + * operations because of potential concurrency. + * + * We shouldn't write multiple values to a single + * global here, because that would cause + * a race condition. + */ +static volatile double _npy_floatstatus_x, + _npy_floatstatus_zero = 0.0, _npy_floatstatus_big = 1e300, + _npy_floatstatus_small = 1e-300, _npy_floatstatus_inf; + +void npy_set_floatstatus_divbyzero(void) +{ + _npy_floatstatus_x = 1.0 / _npy_floatstatus_zero; +} + +void npy_set_floatstatus_overflow(void) +{ + _npy_floatstatus_x = _npy_floatstatus_big * 1e300; +} + +void npy_set_floatstatus_underflow(void) +{ + _npy_floatstatus_x = _npy_floatstatus_small * 1e-300; +} + +void npy_set_floatstatus_invalid(void) +{ + _npy_floatstatus_inf = NPY_INFINITY; + _npy_floatstatus_x = _npy_floatstatus_inf - NPY_INFINITY; +} + +#endif + diff --git a/numpy/core/src/scalarmathmodule.c.src b/numpy/core/src/scalarmathmodule.c.src index 712932958b41..d1a66e101e8f 100644 --- a/numpy/core/src/scalarmathmodule.c.src +++ b/numpy/core/src/scalarmathmodule.c.src @@ -145,7 +145,7 @@ static void if ((*out^a) >= 0 || (*out^b) >= 0) { return; } - generate_overflow_error(); + npy_set_floatstatus_overflow(); return; } static void @@ -154,7 +154,7 @@ static void if ((*out^a) >= 0 || (*out^~b) >= 0) { return; } - generate_overflow_error(); + npy_set_floatstatus_overflow(); return; } /**end repeat**/ @@ -168,7 +168,7 @@ static void if (*out >= a && *out >= b) { return; } - generate_overflow_error(); + npy_set_floatstatus_overflow(); return; } static void @@ -177,7 +177,7 @@ static void if (a >= b) { return; } - generate_overflow_error(); + npy_set_floatstatus_overflow(); return; } /**end repeat**/ @@ -206,7 +206,7 @@ static void #else if (temp > MAX_@NAME@) #endif - generate_overflow_error(); + npy_set_floatstatus_overflow(); return; } #endif @@ -223,7 +223,7 @@ static void @name@_ctype_multiply(@name@ a, @name@ b, @name@ *out) { *out = a * b; if (@char@longlong_overflow(a, b)) { - generate_overflow_error(); + npy_set_floatstatus_overflow(); } return; } @@ -239,12 +239,12 @@ static void static void @name@_ctype_divide(@name@ a, @name@ b, @name@ *out) { if (b == 0) { - generate_divbyzero_error(); + npy_set_floatstatus_divbyzero(); *out = 0; } #if @neg@ else if (b == -1 && a < 0 && a == -a) { - generate_overflow_error(); + npy_set_floatstatus_overflow(); *out = a / b; } #endif @@ -266,7 +266,7 @@ static void static void @name@_ctype_remainder(@name@ a, @name@ b, @name@ *out) { if (a == 0 || b == 0) { - if (b == 0) generate_divbyzero_error(); + if (b == 0) npy_set_floatstatus_divbyzero(); *out = 0; return; } @@ -450,7 +450,7 @@ static void @name@_ctype_negative(npy_@name@ a, npy_@name@ *out) { #if @uns@ - generate_overflow_error(); + npy_set_floatstatus_overflow(); #endif *out = -a; } diff --git a/numpy/core/src/umath/loops.c.src b/numpy/core/src/umath/loops.c.src index 0c777e464a99..8c98db6b7385 100644 --- a/numpy/core/src/umath/loops.c.src +++ b/numpy/core/src/umath/loops.c.src @@ -795,7 +795,7 @@ NPY_NO_EXPORT void const @s@@type@ in1 = *(@s@@type@ *)ip1; const @s@@type@ in2 = *(@s@@type@ *)ip2; if (in2 == 0) { - generate_divbyzero_error(); + npy_set_floatstatus_divbyzero(); *((@s@@type@ *)op1) = 0; } else { @@ -854,10 +854,10 @@ NPY_NO_EXPORT void * by -1 causes a SIFGPE (division overflow). We treat this case here * (to avoid a SIGFPE crash at python level), but a good solution would * be to treat integer division problems separately from FPU exceptions - * (i.e. fixing generate_divbyzero_error()). + * (i.e. a different approach than npy_set_floatstatus_divbyzero()). */ if (in2 == 0 || (in1 == NPY_MIN_@TYPE@ && in2 == -1)) { - generate_divbyzero_error(); + npy_set_floatstatus_divbyzero(); *((@type@ *)op1) = 0; } else if (((in1 > 0) != (in2 > 0)) && (in1 % in2 != 0)) { @@ -876,7 +876,7 @@ U@TYPE@_divide(char **args, intp *dimensions, intp *steps, void *NPY_UNUSED(func const u@type@ in1 = *(u@type@ *)ip1; const u@type@ in2 = *(u@type@ *)ip2; if (in2 == 0) { - generate_divbyzero_error(); + npy_set_floatstatus_divbyzero(); *((u@type@ *)op1) = 0; } else { @@ -892,7 +892,7 @@ NPY_NO_EXPORT void const @type@ in1 = *(@type@ *)ip1; const @type@ in2 = *(@type@ *)ip2; if (in2 == 0) { - generate_divbyzero_error(); + npy_set_floatstatus_divbyzero(); *((@type@ *)op1) = 0; } else { @@ -915,7 +915,7 @@ U@TYPE@_remainder(char **args, intp *dimensions, intp *steps, void *NPY_UNUSED(f const u@type@ in1 = *(u@type@ *)ip1; const u@type@ in2 = *(u@type@ *)ip2; if (in2 == 0) { - generate_divbyzero_error(); + npy_set_floatstatus_divbyzero(); *((@type@ *)op1) = 0; } else { diff --git a/numpy/core/tests/test_errstate.py b/numpy/core/tests/test_errstate.py index c8e2b708f8ed..732bb3e93bff 100644 --- a/numpy/core/tests/test_errstate.py +++ b/numpy/core/tests/test_errstate.py @@ -25,7 +25,7 @@ def test_invalid(self): except FloatingPointError: pass else: - self.fail() + self.fail("Did not raise an invalid error") def test_divide(self): with errstate(all='raise', under='ignore'): @@ -39,7 +39,7 @@ def test_divide(self): except FloatingPointError: pass else: - self.fail() + self.fail("Did not raise divide by zero error") def test_errcall(self): def foo(*args): diff --git a/numpy/core/tests/test_half.py b/numpy/core/tests/test_half.py index 409e50e92089..37fce64602e2 100644 --- a/numpy/core/tests/test_half.py +++ b/numpy/core/tests/test_half.py @@ -67,32 +67,37 @@ def test_half_conversions(self): assert_equal(i_int,j) def test_nans_infs(self): - # Check some of the ufuncs - assert_equal(np.isnan(self.all_f16), np.isnan(self.all_f32)) - assert_equal(np.isinf(self.all_f16), np.isinf(self.all_f32)) - assert_equal(np.isfinite(self.all_f16), np.isfinite(self.all_f32)) - assert_equal(np.signbit(self.all_f16), np.signbit(self.all_f32)) + oldsettings = np.seterr(all='ignore') + try: + # Check some of the ufuncs + assert_equal(np.isnan(self.all_f16), np.isnan(self.all_f32)) + assert_equal(np.isinf(self.all_f16), np.isinf(self.all_f32)) + assert_equal(np.isfinite(self.all_f16), np.isfinite(self.all_f32)) + assert_equal(np.signbit(self.all_f16), np.signbit(self.all_f32)) + assert_equal(np.spacing(float16(65504)), np.inf) - # Check comparisons of all values with NaN - nan = float16(np.nan) + # Check comparisons of all values with NaN + nan = float16(np.nan) - assert_(not (self.all_f16 == nan).any()) - assert_(not (nan == self.all_f16).any()) + assert_(not (self.all_f16 == nan).any()) + assert_(not (nan == self.all_f16).any()) - assert_((self.all_f16 != nan).all()) - assert_((nan != self.all_f16).all()) + assert_((self.all_f16 != nan).all()) + assert_((nan != self.all_f16).all()) - assert_(not (self.all_f16 < nan).any()) - assert_(not (nan < self.all_f16).any()) + assert_(not (self.all_f16 < nan).any()) + assert_(not (nan < self.all_f16).any()) - assert_(not (self.all_f16 <= nan).any()) - assert_(not (nan <= self.all_f16).any()) + assert_(not (self.all_f16 <= nan).any()) + assert_(not (nan <= self.all_f16).any()) - assert_(not (self.all_f16 > nan).any()) - assert_(not (nan > self.all_f16).any()) + assert_(not (self.all_f16 > nan).any()) + assert_(not (nan > self.all_f16).any()) - assert_(not (self.all_f16 >= nan).any()) - assert_(not (nan >= self.all_f16).any()) + assert_(not (self.all_f16 >= nan).any()) + assert_(not (nan >= self.all_f16).any()) + finally: + np.seterr(**oldsettings) def test_half_values(self): @@ -396,10 +401,10 @@ def test_half_fpe(self): float16(-65504), float16(17)) assert_raises_fpe('overflow', np.nextafter, float16(65504), float16(np.inf)) assert_raises_fpe('overflow', np.nextafter, float16(-65504), float16(-np.inf)) + assert_raises_fpe('overflow', np.spacing, float16(65504)) # Invalid value errors assert_raises_fpe('invalid', np.divide, float16(np.inf), float16(np.inf)) - assert_raises_fpe('invalid', np.spacing, float16(65504)) assert_raises_fpe('invalid', np.spacing, float16(np.inf)) assert_raises_fpe('invalid', np.spacing, float16(np.nan)) assert_raises_fpe('invalid', np.nextafter, float16(np.inf), float16(0)) diff --git a/numpy/core/tests/test_numeric.py b/numpy/core/tests/test_numeric.py index d8f179454398..f3ca44404d65 100644 --- a/numpy/core/tests/test_numeric.py +++ b/numpy/core/tests/test_numeric.py @@ -315,8 +315,12 @@ def test_floating_exceptions(self): lambda a,b:a+b, ft_max, ft_max*ft_eps) self.assert_raises_fpe(overflow, lambda a,b:a-b, -ft_max, ft_max*ft_eps) + self.assert_raises_fpe(overflow, + np.power, ftype(2), ftype(2**fi.nexp)) self.assert_raises_fpe(divbyzero, lambda a,b:a/b, ftype(1), ftype(0)) + self.assert_raises_fpe(invalid, + lambda a,b:a/b, ftype(np.inf), ftype(np.inf)) self.assert_raises_fpe(invalid, lambda a,b:a/b, ftype(0), ftype(0)) self.assert_raises_fpe(invalid, @@ -325,8 +329,6 @@ def test_floating_exceptions(self): lambda a,b:a+b, ftype(np.inf), ftype(-np.inf)) self.assert_raises_fpe(invalid, lambda a,b:a*b, ftype(0), ftype(np.inf)) - self.assert_raises_fpe(overflow, - np.power, ftype(2), ftype(2**fi.nexp)) finally: np.seterr(**oldsettings) From 283566450251fc0e0334eccbb6d0c18bcac4f2c5 Mon Sep 17 00:00:00 2001 From: Mark Wiebe Date: Fri, 3 Dec 2010 09:49:17 -0800 Subject: [PATCH 2/2] STY: Break some long lines --- numpy/core/include/numpy/ufuncobject.h | 11 ++++++++--- numpy/core/src/npymath/ieee754.c.src | 11 ++++++++--- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/numpy/core/include/numpy/ufuncobject.h b/numpy/core/include/numpy/ufuncobject.h index 544669e7d40d..2a5413ef1dfe 100644 --- a/numpy/core/include/numpy/ufuncobject.h +++ b/numpy/core/include/numpy/ufuncobject.h @@ -292,7 +292,9 @@ typedef struct _loop1d_info { /* Solaris --------------------------------------------------------*/ /* --------ignoring SunOS ieee_flags approach, someone else can ** deal with that! */ -#elif defined(sun) || defined(__BSD__) || defined(__OpenBSD__) || (defined(__FreeBSD__) && (__FreeBSD_version < 502114)) || defined(__NetBSD__) +#elif defined(sun) || defined(__BSD__) || defined(__OpenBSD__) || \ + (defined(__FreeBSD__) && (__FreeBSD_version < 502114)) || \ + defined(__NetBSD__) #include #define UFUNC_CHECK_STATUS(ret) { \ @@ -306,9 +308,12 @@ typedef struct _loop1d_info { (void) fpsetsticky(0); \ } -#elif defined(__GLIBC__) || defined(__APPLE__) || defined(__CYGWIN__) || defined(__MINGW32__) || (defined(__FreeBSD__) && (__FreeBSD_version >= 502114)) +#elif defined(__GLIBC__) || defined(__APPLE__) || \ + defined(__CYGWIN__) || defined(__MINGW32__) || \ + (defined(__FreeBSD__) && (__FreeBSD_version >= 502114)) -#if defined(__GLIBC__) || defined(__APPLE__) || defined(__MINGW32__) || defined(__FreeBSD__) +#if defined(__GLIBC__) || defined(__APPLE__) || \ + defined(__MINGW32__) || defined(__FreeBSD__) #include #elif defined(__CYGWIN__) #include "fenv/fenv.c" diff --git a/numpy/core/src/npymath/ieee754.c.src b/numpy/core/src/npymath/ieee754.c.src index 14d3f4a90b55..71be7b8cecd4 100644 --- a/numpy/core/src/npymath/ieee754.c.src +++ b/numpy/core/src/npymath/ieee754.c.src @@ -553,7 +553,9 @@ npy_longdouble npy_nextafterl(npy_longdouble x, npy_longdouble y) * Functions to set the floating point status word. */ -#if defined(sun) || defined(__BSD__) || defined(__OpenBSD__) || (defined(__FreeBSD__) && (__FreeBSD_version < 502114)) || defined(__NetBSD__) +#if defined(sun) || defined(__BSD__) || defined(__OpenBSD__) || \ + (defined(__FreeBSD__) && (__FreeBSD_version < 502114)) || \ + defined(__NetBSD__) #include void npy_set_floatstatus_divbyzero(void) @@ -577,9 +579,12 @@ void npy_set_floatstatus_invalid(void) } -#elif defined(__GLIBC__) || defined(__APPLE__) || defined(__CYGWIN__) || defined(__MINGW32__) || (defined(__FreeBSD__) && (__FreeBSD_version >= 502114)) +#elif defined(__GLIBC__) || defined(__APPLE__) || \ + defined(__CYGWIN__) || defined(__MINGW32__) || \ + (defined(__FreeBSD__) && (__FreeBSD_version >= 502114)) -# if defined(__GLIBC__) || defined(__APPLE__) || defined(__MINGW32__) || defined(__FreeBSD__) +# if defined(__GLIBC__) || defined(__APPLE__) || \ + defined(__MINGW32__) || defined(__FreeBSD__) # include # elif defined(__CYGWIN__) # include "fenv/fenv.c"