blob: 5fb8a1cc5be160bdf94180a5b825f722e91b6d21 [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
18 .. index:: single: FloatType (in modules types)
19
Georg Brandl60203b42010-10-06 10:11:56 +000020 This instance of :c:type:`PyTypeObject` represents the Python floating point
Georg Brandl54a3faa2008-01-20 09:30:57 +000021 type. This is the same object as ``float`` and ``types.FloatType``.
22
23
Georg Brandl60203b42010-10-06 10:11:56 +000024.. c:function:: int PyFloat_Check(PyObject *p)
Georg Brandl54a3faa2008-01-20 09:30:57 +000025
Georg Brandl60203b42010-10-06 10:11:56 +000026 Return true if its argument is a :c:type:`PyFloatObject` or a subtype of
27 :c:type:`PyFloatObject`.
Georg Brandl54a3faa2008-01-20 09:30:57 +000028
29
Georg Brandl60203b42010-10-06 10:11:56 +000030.. c:function:: int PyFloat_CheckExact(PyObject *p)
Georg Brandl54a3faa2008-01-20 09:30:57 +000031
Georg Brandl60203b42010-10-06 10:11:56 +000032 Return true if its argument is a :c:type:`PyFloatObject`, but not a subtype of
33 :c:type:`PyFloatObject`.
Georg Brandl54a3faa2008-01-20 09:30:57 +000034
35
Georg Brandl60203b42010-10-06 10:11:56 +000036.. c:function:: PyObject* PyFloat_FromString(PyObject *str)
Georg Brandl54a3faa2008-01-20 09:30:57 +000037
Georg Brandl60203b42010-10-06 10:11:56 +000038 Create a :c:type:`PyFloatObject` object based on the string value in *str*, or
Georg Brandl54a3faa2008-01-20 09:30:57 +000039 *NULL* on failure.
40
41
Georg Brandl60203b42010-10-06 10:11:56 +000042.. c:function:: PyObject* PyFloat_FromDouble(double v)
Georg Brandl54a3faa2008-01-20 09:30:57 +000043
Georg Brandl60203b42010-10-06 10:11:56 +000044 Create a :c:type:`PyFloatObject` object from *v*, or *NULL* on failure.
Georg Brandl54a3faa2008-01-20 09:30:57 +000045
46
Georg Brandl60203b42010-10-06 10:11:56 +000047.. c:function:: double PyFloat_AsDouble(PyObject *pyfloat)
Georg Brandl54a3faa2008-01-20 09:30:57 +000048
Georg Brandl60203b42010-10-06 10:11:56 +000049 Return a C :c:type:`double` representation of the contents of *pyfloat*. If
Georg Brandl54a3faa2008-01-20 09:30:57 +000050 *pyfloat* is not a Python floating point object but has a :meth:`__float__`
51 method, this method will first be called to convert *pyfloat* into a float.
52
53
Georg Brandl60203b42010-10-06 10:11:56 +000054.. c:function:: double PyFloat_AS_DOUBLE(PyObject *pyfloat)
Georg Brandl54a3faa2008-01-20 09:30:57 +000055
Georg Brandl60203b42010-10-06 10:11:56 +000056 Return a C :c:type:`double` representation of the contents of *pyfloat*, but
Georg Brandl54a3faa2008-01-20 09:30:57 +000057 without error checking.
58
59
Georg Brandl60203b42010-10-06 10:11:56 +000060.. c:function:: PyObject* PyFloat_GetInfo(void)
Georg Brandl54a3faa2008-01-20 09:30:57 +000061
62 Return a structseq instance which contains information about the
63 precision, minimum and maximum values of a float. It's a thin wrapper
64 around the header file :file:`float.h`.
65
66
Georg Brandl60203b42010-10-06 10:11:56 +000067.. c:function:: double PyFloat_GetMax()
Georg Brandl54a3faa2008-01-20 09:30:57 +000068
Georg Brandl60203b42010-10-06 10:11:56 +000069 Return the maximum representable finite float *DBL_MAX* as C :c:type:`double`.
Georg Brandl54a3faa2008-01-20 09:30:57 +000070
71
Georg Brandl60203b42010-10-06 10:11:56 +000072.. c:function:: double PyFloat_GetMin()
Georg Brandl54a3faa2008-01-20 09:30:57 +000073
Georg Brandl60203b42010-10-06 10:11:56 +000074 Return the minimum normalized positive float *DBL_MIN* as C :c:type:`double`.
Christian Heimes15ebc882008-02-04 18:48:49 +000075
Georg Brandl60203b42010-10-06 10:11:56 +000076.. c:function:: int PyFloat_ClearFreeList()
Christian Heimes15ebc882008-02-04 18:48:49 +000077
Georg Brandl2ee470f2008-07-16 12:55:28 +000078 Clear the float free list. Return the number of items that could not
79 be freed.