diff options
author | Hye-Shik Chang <hyeshik@gmail.com> | 2004-03-22 08:43:55 (GMT) |
---|---|---|
committer | Hye-Shik Chang <hyeshik@gmail.com> | 2004-03-22 08:43:55 (GMT) |
commit | 77d9a3effa21b8987ceac26d67ad676e1c5afb49 (patch) | |
tree | f302896991076d2d6b39ea6bd6a790762b40cf5e /Include | |
parent | 39a0f044210b82f3352b9824c1f1625c7bdb9f29 (diff) | |
download | cpython-77d9a3effa21b8987ceac26d67ad676e1c5afb49.zip cpython-77d9a3effa21b8987ceac26d67ad676e1c5afb49.tar.gz cpython-77d9a3effa21b8987ceac26d67ad676e1c5afb49.tar.bz2 |
Patch #871657: Set EDOM for `nan' return values on FreeBSD and OpenBSD.
This fixes a problem that math.sqrt(-1) doesn't raise math.error.
Diffstat (limited to 'Include')
-rw-r--r-- | Include/pyport.h | 27 |
1 files changed, 20 insertions, 7 deletions
diff --git a/Include/pyport.h b/Include/pyport.h index 79b92c3..7477f07 100644 --- a/Include/pyport.h +++ b/Include/pyport.h @@ -273,21 +273,34 @@ extern "C" { (X) == -Py_HUGE_VAL)) #endif -/* Py_SET_ERANGE_ON_OVERFLOW(x) +/* Py_SET_ERRNO_ON_MATH_ERROR(x) * If a libm function did not set errno, but it looks like the result - * overflowed, set errno to ERANGE. Set errno to 0 before calling a libm - * function, and invoke this macro after, passing the function result. + * overflowed or not-a-number, set errno to ERANGE or EDOM. Set errno + * to 0 before calling a libm function, and invoke this macro after, + * passing the function result. * Caution: * This isn't reliable. See Py_OVERFLOWED comments. * X is evaluated more than once. */ -#define Py_SET_ERANGE_IF_OVERFLOW(X) \ +#if defined(__FreeBSD__) || defined(__OpenBSD__) +#define _Py_SET_EDOM_FOR_NAN(X) if (isnan(X)) errno = EDOM; +#else +#define _Py_SET_EDOM_FOR_NAN(X) ; +#endif +#define Py_SET_ERRNO_ON_MATH_ERROR(X) \ do { \ - if (errno == 0 && ((X) == Py_HUGE_VAL || \ - (X) == -Py_HUGE_VAL)) \ - errno = ERANGE; \ + if (errno == 0) { \ + if ((X) == Py_HUGE_VAL || (X) == -Py_HUGE_VAL) \ + errno = ERANGE; \ + else _Py_SET_EDOM_FOR_NAN(X) \ + } \ } while(0) +/* Py_SET_ERANGE_ON_OVERFLOW(x) + * An alias of Py_SET_ERRNO_ON_MATH_ERROR for backward-compatibility. + */ +#define Py_SET_ERANGE_IF_OVERFLOW(X) Py_SET_ERRNO_ON_MATH_ERROR(X) + /* Py_ADJUST_ERANGE1(x) * Py_ADJUST_ERANGE2(x, y) * Set errno to 0 before calling a libm function, and invoke one of these |