Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use C99+ math.h functions instead of Py_IS_NAN/INFINITY/FINITE #485

Merged
merged 1 commit into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading