| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -53,6 +53,8 @@ noted otherwise, all return values are floats. | |||
| 53 | 53 | :func:`frexp(x) <frexp>` Mantissa and exponent of *x* | |
| 54 | 54 | :func:`isclose(a, b, rel_tol, abs_tol) <isclose>` Check if the values *a* and *b* are close to each other | |
| 55 | 55 | :func:`isfinite(x) <isfinite>` Check if *x* is neither an infinity nor a NaN | |
| 56 | + :func:`isnormal(x) <isnormal>` Check if *x* is a normal number | ||
| 57 | + :func:`issubnormal(x) <issubnormal>` Check if *x* is a subnormal number | ||
| 56 | 58 | :func:`isinf(x) <isinf>` Check if *x* is a positive or negative infinity | |
| 57 | 59 | :func:`isnan(x) <isnan>` Check if *x* is a NaN (not a number) | |
| 58 | 60 | :func:`ldexp(x, i) <ldexp>` ``x * (2**i)``, inverse of function :func:`frexp` | |
@@ -373,6 +375,24 @@ Floating point manipulation functions | |||
| 373 | 375 | .. versionadded:: 3.2 | |
| 374 | 376 | ||
| 375 | 377 | ||
| 378 | + .. function:: isnormal(x) | ||
| 379 | + | ||
| 380 | + Return ``True`` if *x* is a normal number, that is a finite | ||
| 381 | + nonzero number that is not a subnormal (see :func:`issubnormal`). | ||
| 382 | + Return ``False`` otherwise. | ||
| 383 | + | ||
| 384 | + .. versionadded:: next | ||
| 385 | + | ||
| 386 | + | ||
| 387 | + .. function:: issubnormal(x) | ||
| 388 | + | ||
| 389 | + Return ``True`` if *x* is a subnormal number, that is a finite | ||
| 390 | + nonzero number with a magnitude smaller than the smallest positive normal | ||
| 391 | + number, see :data:`sys.float_info.min`. Return ``False`` otherwise. | ||
| 392 | + | ||
| 393 | + .. versionadded:: next | ||
| 394 | + | ||
| 395 | + | ||
| 376 | 396 | .. function:: isinf(x) | |
| 377 | 397 | ||
| 378 | 398 | Return ``True`` if *x* is a positive or negative infinity, and | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1454,7 +1454,7 @@ math | |||
| 1454 | 1454 | ---- | |
| 1455 | 1455 | ||
| 1456 | 1456 | * Added more detailed error messages for domain errors in the module. | |
| 1457 | - (Contributed by by Charlie Zhao and Sergey B Kirpichev in :gh:`101410`.) | ||
| 1457 | + (Contributed by Charlie Zhao and Sergey B Kirpichev in :gh:`101410`.) | ||
| 1458 | 1458 | ||
| 1459 | 1459 | ||
| 1460 | 1460 | mimetypes | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -105,6 +105,13 @@ difflib | |||
| 105 | 105 | (Contributed by Jiahao Li in :gh:`134580`.) | |
| 106 | 106 | ||
| 107 | 107 | ||
| 108 | + math | ||
| 109 | + ---- | ||
| 110 | + | ||
| 111 | + * Add :func:`math.isnormal` and :func:`math.issubnormal` functions. | ||
| 112 | + (Contributed by Sergey B Kirpichev in :gh:`132908`.) | ||
| 113 | + | ||
| 114 | + | ||
| 108 | 115 | shelve | |
| 109 | 116 | ------ | |
| 110 | 117 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1973,6 +1973,28 @@ def testIsfinite(self): | |||
| 1973 | 1973 | self.assertFalse(math.isfinite(float("inf"))) | |
| 1974 | 1974 | self.assertFalse(math.isfinite(float("-inf"))) | |
| 1975 | 1975 | ||
| 1976 | + def testIsnormal(self): | ||
| 1977 | + self.assertTrue(math.isnormal(1.25)) | ||
| 1978 | + self.assertTrue(math.isnormal(-1.0)) | ||
| 1979 | + self.assertFalse(math.isnormal(0.0)) | ||
| 1980 | + self.assertFalse(math.isnormal(-0.0)) | ||
| 1981 | + self.assertFalse(math.isnormal(INF)) | ||
| 1982 | + self.assertFalse(math.isnormal(NINF)) | ||
| 1983 | + self.assertFalse(math.isnormal(NAN)) | ||
| 1984 | + self.assertFalse(math.isnormal(FLOAT_MIN/2)) | ||
| 1985 | + self.assertFalse(math.isnormal(-FLOAT_MIN/2)) | ||
| 1986 | + | ||
| 1987 | + def testIssubnormal(self): | ||
| 1988 | + self.assertFalse(math.issubnormal(1.25)) | ||
| 1989 | + self.assertFalse(math.issubnormal(-1.0)) | ||
| 1990 | + self.assertFalse(math.issubnormal(0.0)) | ||
| 1991 | + self.assertFalse(math.issubnormal(-0.0)) | ||
| 1992 | + self.assertFalse(math.issubnormal(INF)) | ||
| 1993 | + self.assertFalse(math.issubnormal(NINF)) | ||
| 1994 | + self.assertFalse(math.issubnormal(NAN)) | ||
| 1995 | + self.assertTrue(math.issubnormal(FLOAT_MIN/2)) | ||
| 1996 | + self.assertTrue(math.issubnormal(-FLOAT_MIN/2)) | ||
| 1997 | + | ||
| 1976 | 1998 | def testIsnan(self): | |
| 1977 | 1999 | self.assertTrue(math.isnan(float("nan"))) | |
| 1978 | 2000 | self.assertTrue(math.isnan(float("-nan"))) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,2 @@ | |||
| 1 | + Add :func:`math.isnormal` and :func:`math.issubnormal` functions. Patch by | ||
| 2 | + Sergey B Kirpichev. | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3118,6 +3118,44 @@ math_isfinite_impl(PyObject *module, double x) | |||
| 3118 | 3118 | } | |
| 3119 | 3119 | ||
| 3120 | 3120 | ||
| 3121 | + /*[clinic input] | ||
| 3122 | + math.isnormal | ||
| 3123 | + | ||
| 3124 | + x: double | ||
| 3125 | + / | ||
| 3126 | + | ||
| 3127 | + Return True if x is normal, and False otherwise. | ||
| 3128 | + [clinic start generated code]*/ | ||
| 3129 | + | ||
| 3130 | + static PyObject * | ||
| 3131 | + math_isnormal_impl(PyObject *module, double x) | ||
| 3132 | + /*[clinic end generated code: output=c7b302b5b89c3541 input=fdaa00c58aa7bc17]*/ | ||
| 3133 | + { | ||
| 3134 | + return PyBool_FromLong(isnormal(x)); | ||
| 3135 | + } | ||
| 3136 | + | ||
| 3137 | + | ||
| 3138 | + /*[clinic input] | ||
| 3139 | + math.issubnormal | ||
| 3140 | + | ||
| 3141 | + x: double | ||
| 3142 | + / | ||
| 3143 | + | ||
| 3144 | + Return True if x is subnormal, and False otherwise. | ||
| 3145 | + [clinic start generated code]*/ | ||
| 3146 | + | ||
| 3147 | + static PyObject * | ||
| 3148 | + math_issubnormal_impl(PyObject *module, double x) | ||
| 3149 | + /*[clinic end generated code: output=4e76ac98ddcae761 input=9a20aba7107d0d95]*/ | ||
| 3150 | + { | ||
| 3151 | + #if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L | ||
| 3152 | + return PyBool_FromLong(issubnormal(x)); | ||
| 3153 | + #else | ||
| 3154 | + return PyBool_FromLong(isfinite(x) && x && !isnormal(x)); | ||
| 3155 | + #endif | ||
| 3156 | + } | ||
| 3157 | + | ||
| 3158 | + | ||
| 3121 | 3159 | /*[clinic input] | |
| 3122 | 3160 | math.isnan | |
| 3123 | 3161 | ||
@@ -4145,6 +4183,8 @@ static PyMethodDef math_methods[] = { | |||
| 4145 | 4183 | MATH_HYPOT_METHODDEF | |
| 4146 | 4184 | MATH_ISCLOSE_METHODDEF | |
| 4147 | 4185 | MATH_ISFINITE_METHODDEF | |
| 4186 | + MATH_ISNORMAL_METHODDEF | ||
| 4187 | + MATH_ISSUBNORMAL_METHODDEF | ||
| 4148 | 4188 | MATH_ISINF_METHODDEF | |
| 4149 | 4189 | MATH_ISNAN_METHODDEF | |
| 4150 | 4190 | MATH_ISQRT_METHODDEF | |
| Back | FazBrowse Home | New Git URL |
0 commit comments