diff --git a/Modules/mathmodule.c b/Modules/mathmodule.c index fa607e3f1ea1..4c820c584881 100644 --- a/Modules/mathmodule.c +++ b/Modules/mathmodule.c @@ -82,12 +82,17 @@ is_error(double x) * should return a zero on underflow, and +- HUGE_VAL on * overflow, so testing the result for zero suffices to * distinguish the cases). + * + * On some platforms (Ubuntu/ia64) it seems that errno can be + * set to ERANGE for subnormal results that do *not* underflow + * to zero. So to be safe, we'll ignore ERANGE whenever the + * function result is less than one in absolute value. */ - if (x) + if (fabs(x) < 1.0) + result = 0; + else PyErr_SetString(PyExc_OverflowError, "math range error"); - else - result = 0; } else /* Unexpected math error */