Raymond Hettinger wrote: > Was some thought given to possibly adding these as > float methods instead of as separate functions? > > float.isinf() > float.isnan() > > Also, it would be useful to have a new method, float.is_integer(). This would be better than the current approach where we make the > test: if x == floor(x). No, I haven't thought about it. I could add isinf (or better is_inf?) to the float type but the methods in the math and cmath module should stay as well. They can also deal with complex and integer numbers. +1 for is_integer static PyObject * float_is_integer(PyObject *v) { double x = PyFloat_AsDouble(v); PyObject *o; if (x == -1.0 && PyErr_Occurred()) return NULL; if (!Py_IS_FINITE(x)) Py_RETURN_FALSE; PyFPE_START_PROTECT("is_integer", return 0) o = (floor(x) == x) ? Py_True : Py_False; PyFPE_END_PROTECT(x) if (errno != 0) { PyErr_SetFromErrno(errno == ERANGE ? PyExc_OverflowError : PyExc_ValueError); return NULL; } Py_INCREF(o); return o; } Christian
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4