Skip to content

Commit

Permalink
Merge pull request #485 from skirpichev/no-py-is
Browse files Browse the repository at this point in the history
Use C99+ math.h functions instead of Py_IS_NAN/INFINITY/FINITE
  • Loading branch information
casevh authored May 28, 2024
2 parents 26cea63 + c145b23 commit 5fc1b24
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
16 changes: 8 additions & 8 deletions src/gmpy2_convert_gmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,12 @@ GMPy_MPZ_From_PyFloat(PyObject *obj, CTXT_Object *context)
if ((result = GMPy_MPZ_New(context))) {
double d = PyFloat_AsDouble(obj);

if (Py_IS_NAN(d)) {
if (isnan(d)) {
Py_DECREF((PyObject*)result);
VALUE_ERROR("'mpz' does not support NaN");
return NULL;
}
if (Py_IS_INFINITY(d)) {
if (isinf(d)) {
Py_DECREF((PyObject*)result);
OVERFLOW_ERROR("'mpz' does not support Infinity");
return NULL;
Expand Down Expand Up @@ -168,7 +168,7 @@ GMPy_PyFloat_From_MPZ(MPZ_Object *obj, CTXT_Object *context)

res = mpz_get_d(obj->z);

if (Py_IS_INFINITY(res)) {
if (isinf(res)) {
OVERFLOW_ERROR("'mpz' too large to convert to float");
return NULL;
}
Expand Down Expand Up @@ -393,12 +393,12 @@ GMPy_XMPZ_From_PyFloat(PyObject *obj, CTXT_Object *context)
if ((result = GMPy_XMPZ_New(context))) {
double d = PyFloat_AsDouble(obj);

if (Py_IS_NAN(d)) {
if (isnan(d)) {
Py_DECREF((PyObject*)result);
VALUE_ERROR("'xmpz' does not support NaN");
return NULL;
}
if (Py_IS_INFINITY(d)) {
if (isinf(d)) {
Py_DECREF((PyObject*)result);
OVERFLOW_ERROR("'xmpz' does not support Infinity");
return NULL;
Expand Down Expand Up @@ -647,12 +647,12 @@ GMPy_MPQ_From_PyFloat(PyObject *obj, CTXT_Object *context)
if ((result = GMPy_MPQ_New(context))) {
double d = PyFloat_AsDouble(obj);

if (Py_IS_NAN(d)) {
if (isnan(d)) {
Py_DECREF((PyObject*)result);
VALUE_ERROR("'mpq' does not support NaN");
return NULL;
}
if (Py_IS_INFINITY(d)) {
if (isinf(d)) {
Py_DECREF((PyObject*)result);
OVERFLOW_ERROR("'mpq' does not support Infinity");
return NULL;
Expand Down Expand Up @@ -793,7 +793,7 @@ GMPy_PyFloat_From_MPQ(MPQ_Object *obj, CTXT_Object *context)

res = mpq_get_d(obj->q);

if (Py_IS_INFINITY(res)) {
if (isinf(res)) {
OVERFLOW_ERROR("'mpq' too large to convert to float");
return NULL;
}
Expand Down
8 changes: 4 additions & 4 deletions src/gmpy2_richcompare.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,12 @@ GMPy_RichCompare_Slot(PyObject *a, PyObject *b, int op)

if (IS_TYPE_PyFloat(btype)) {
double d = PyFloat_AS_DOUBLE(b);
if (Py_IS_NAN(d)) {
if (isnan(d)) {
result = (op == Py_NE) ? Py_True : Py_False;
Py_INCREF(result);
return result;
}
else if (Py_IS_INFINITY(d)) {
else if (isinf(d)) {
if (d < 0.0)
return _cmp_to_object(1, op);
else
Expand Down Expand Up @@ -133,12 +133,12 @@ GMPy_RichCompare_Slot(PyObject *a, PyObject *b, int op)

if (IS_TYPE_PyFloat(btype)) {
double d = PyFloat_AS_DOUBLE(b);
if (Py_IS_NAN(d)) {
if (isnan(d)) {
result = (op == Py_NE) ? Py_True : Py_False;
Py_INCREF(result);
return result;
}
else if (Py_IS_INFINITY(d)) {
else if (isinf(d)) {
if (d < 0.0)
return _cmp_to_object(1, op);
else
Expand Down

0 comments on commit 5fc1b24

Please sign in to comment.