blob: 757efd363d088bed1606ba6573e86e863522116f [file] [log] [blame]
Georg Brandl54a3faa2008-01-20 09:30:57 +00001.. highlightlang:: c
2
3.. _floatobjects:
4
5Floating Point Objects
6----------------------
7
8.. index:: object: floating point
9
10
Georg Brandl60203b42010-10-06 10:11:56 +000011.. c:type:: PyFloatObject
Georg Brandl54a3faa2008-01-20 09:30:57 +000012
Georg Brandl60203b42010-10-06 10:11:56 +000013 This subtype of :c:type:`PyObject` represents a Python floating point object.
Georg Brandl54a3faa2008-01-20 09:30:57 +000014
15
Georg Brandl60203b42010-10-06 10:11:56 +000016.. c:var:: PyTypeObject PyFloat_Type
Georg Brandl54a3faa2008-01-20 09:30:57 +000017
Georg Brandl60203b42010-10-06 10:11:56 +000018 This instance of :c:type:`PyTypeObject` represents the Python floating point
Georg Brandl2aff3352010-10-17 10:59:41 +000019 type. This is the same object as :class:`float` in the Python layer.
Georg Brandl54a3faa2008-01-20 09:30:57 +000020
21
Georg Brandl60203b42010-10-06 10:11:56 +000022.. c:function:: int PyFloat_Check(PyObject *p)
Georg Brandl54a3faa2008-01-20 09:30:57 +000023
Georg Brandl60203b42010-10-06 10:11:56 +000024 Return true if its argument is a :c:type:`PyFloatObject` or a subtype of
25 :c:type:`PyFloatObject`.
Georg Brandl54a3faa2008-01-20 09:30:57 +000026
27
Georg Brandl60203b42010-10-06 10:11:56 +000028.. c:function:: int PyFloat_CheckExact(PyObject *p)
Georg Brandl54a3faa2008-01-20 09:30:57 +000029
Georg Brandl60203b42010-10-06 10:11:56 +000030 Return true if its argument is a :c:type:`PyFloatObject`, but not a subtype of
31 :c:type:`PyFloatObject`.
Georg Brandl54a3faa2008-01-20 09:30:57 +000032
33
Georg Brandl60203b42010-10-06 10:11:56 +000034.. c:function:: PyObject* PyFloat_FromString(PyObject *str)
Georg Brandl54a3faa2008-01-20 09:30:57 +000035
Georg Brandl60203b42010-10-06 10:11:56 +000036 Create a :c:type:`PyFloatObject` object based on the string value in *str*, or
Georg Brandl54a3faa2008-01-20 09:30:57 +000037 *NULL* on failure.
38
39
Georg Brandl60203b42010-10-06 10:11:56 +000040.. c:function:: PyObject* PyFloat_FromDouble(double v)
Georg Brandl54a3faa2008-01-20 09:30:57 +000041
Georg Brandl60203b42010-10-06 10:11:56 +000042 Create a :c:type:`PyFloatObject` object from *v*, or *NULL* on failure.
Georg Brandl54a3faa2008-01-20 09:30:57 +000043
44
Georg Brandl60203b42010-10-06 10:11:56 +000045.. c:function:: double PyFloat_AsDouble(PyObject *pyfloat)
Georg Brandl54a3faa2008-01-20 09:30:57 +000046
Georg Brandl60203b42010-10-06 10:11:56 +000047 Return a C :c:type:`double` representation of the contents of *pyfloat*. If
Georg Brandl54a3faa2008-01-20 09:30:57 +000048 *pyfloat* is not a Python floating point object but has a :meth:`__float__`
49 method, this method will first be called to convert *pyfloat* into a float.
50
51
Georg Brandl60203b42010-10-06 10:11:56 +000052.. c:function:: double PyFloat_AS_DOUBLE(PyObject *pyfloat)
Georg Brandl54a3faa2008-01-20 09:30:57 +000053
Georg Brandl60203b42010-10-06 10:11:56 +000054 Return a C :c:type:`double` representation of the contents of *pyfloat*, but
Georg Brandl54a3faa2008-01-20 09:30:57 +000055 without error checking.
56
57
Georg Brandl60203b42010-10-06 10:11:56 +000058.. c:function:: PyObject* PyFloat_GetInfo(void)
Georg Brandl54a3faa2008-01-20 09:30:57 +000059
60 Return a structseq instance which contains information about the
61 precision, minimum and maximum values of a float. It's a thin wrapper
62 around the header file :file:`float.h`.
63
64
Georg Brandl60203b42010-10-06 10:11:56 +000065.. c:function:: double PyFloat_GetMax()
Georg Brandl54a3faa2008-01-20 09:30:57 +000066
Georg Brandl60203b42010-10-06 10:11:56 +000067 Return the maximum representable finite float *DBL_MAX* as C :c:type:`double`.
Georg Brandl54a3faa2008-01-20 09:30:57 +000068
69
Georg Brandl60203b42010-10-06 10:11:56 +000070.. c:function:: double PyFloat_GetMin()
Georg Brandl54a3faa2008-01-20 09:30:57 +000071
Georg Brandl60203b42010-10-06 10:11:56 +000072 Return the minimum normalized positive float *DBL_MIN* as C :c:type:`double`.
Christian Heimes15ebc882008-02-04 18:48:49 +000073
Georg Brandl60203b42010-10-06 10:11:56 +000074.. c:function:: int PyFloat_ClearFreeList()
Christian Heimes15ebc882008-02-04 18:48:49 +000075
Georg Brandl2ee470f2008-07-16 12:55:28 +000076 Clear the float free list. Return the number of items that could not
77 be freed.