Documentation Index
Fetch the complete documentation index at: https://mintlify.com/python/cpython/llms.txt
Use this file to discover all available pages before exploring further.
Overview
Python floats are implemented as C double precision floating-point numbers.
Type Object
PyTypeObject PyFloat_Type
Type Checking
int PyFloat_Check(PyObject *p)
int PyFloat_CheckExact(PyObject *p)
Creating Floats
PyObject* PyFloat_FromDouble(double v)
PyObject* PyFloat_FromString(PyObject *str)
Example:
PyObject *pi = PyFloat_FromDouble(3.14159);
return pi;
Converting to C double
double PyFloat_AsDouble(PyObject *pyfloat)
Example:
double value = PyFloat_AsDouble(obj);
if (value == -1.0 && PyErr_Occurred())
return NULL;
Special Values
Py_RETURN_NAN // Return NaN
Py_RETURN_INF(sign) // Return infinity
Example:
if (is_invalid(x))
Py_RETURN_NAN;
See Also