gh-132908: Add math.isnormal/issubnormal() functions (GH132935)

This commit is contained in:
Sergey B Kirpichev 2025-06-02 13:38:05 +03:00 committed by GitHub
parent 128195e12e
commit 5f61cde80a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 161 additions and 2 deletions

View file

@ -3118,6 +3118,44 @@ math_isfinite_impl(PyObject *module, double x)
}
/*[clinic input]
math.isnormal
x: double
/
Return True if x is normal, and False otherwise.
[clinic start generated code]*/
static PyObject *
math_isnormal_impl(PyObject *module, double x)
/*[clinic end generated code: output=c7b302b5b89c3541 input=fdaa00c58aa7bc17]*/
{
return PyBool_FromLong(isnormal(x));
}
/*[clinic input]
math.issubnormal
x: double
/
Return True if x is subnormal, and False otherwise.
[clinic start generated code]*/
static PyObject *
math_issubnormal_impl(PyObject *module, double x)
/*[clinic end generated code: output=4e76ac98ddcae761 input=9a20aba7107d0d95]*/
{
#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L
return PyBool_FromLong(issubnormal(x));
#else
return PyBool_FromLong(isfinite(x) && x && !isnormal(x));
#endif
}
/*[clinic input]
math.isnan
@ -4145,6 +4183,8 @@ static PyMethodDef math_methods[] = {
MATH_HYPOT_METHODDEF
MATH_ISCLOSE_METHODDEF
MATH_ISFINITE_METHODDEF
MATH_ISNORMAL_METHODDEF
MATH_ISSUBNORMAL_METHODDEF
MATH_ISINF_METHODDEF
MATH_ISNAN_METHODDEF
MATH_ISQRT_METHODDEF