mirror of
https://github.com/python/cpython.git
synced 2026-01-06 15:32:22 +00:00
gh-132908: Add math.isnormal/issubnormal() functions (GH132935)
This commit is contained in:
parent
128195e12e
commit
5f61cde80a
7 changed files with 161 additions and 2 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue