blob: 93769aa1f4c464c73edc86be830b0945dfe1936b [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
11.. ctype:: PyFloatObject
12
13 This subtype of :ctype:`PyObject` represents a Python floating point object.
14
15
16.. cvar:: PyTypeObject PyFloat_Type
17
Georg Brandl54a3faa2008-01-20 09:30:57 +000018 This instance of :ctype:`PyTypeObject` represents the Python floating point
Georg Brandlab32fec2010-11-26 08:49:15 +000019 type. This is the same object as :class:`float` in the Python layer.
Georg Brandl54a3faa2008-01-20 09:30:57 +000020
21
22.. cfunction:: int PyFloat_Check(PyObject *p)
23
24 Return true if its argument is a :ctype:`PyFloatObject` or a subtype of
25 :ctype:`PyFloatObject`.
26
27
28.. cfunction:: int PyFloat_CheckExact(PyObject *p)
29
30 Return true if its argument is a :ctype:`PyFloatObject`, but not a subtype of
31 :ctype:`PyFloatObject`.
32
33
34.. cfunction:: PyObject* PyFloat_FromString(PyObject *str)
35
36 Create a :ctype:`PyFloatObject` object based on the string value in *str*, or
37 *NULL* on failure.
38
39
40.. cfunction:: PyObject* PyFloat_FromDouble(double v)
41
42 Create a :ctype:`PyFloatObject` object from *v*, or *NULL* on failure.
43
44
45.. cfunction:: double PyFloat_AsDouble(PyObject *pyfloat)
46
47 Return a C :ctype:`double` representation of the contents of *pyfloat*. If
48 *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
52.. cfunction:: double PyFloat_AS_DOUBLE(PyObject *pyfloat)
53
54 Return a C :ctype:`double` representation of the contents of *pyfloat*, but
55 without error checking.
56
57
58.. cfunction:: PyObject* PyFloat_GetInfo(void)
59
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 Brandlc5605df2009-08-13 08:26:44 +000065.. cfunction:: double PyFloat_GetMax()
Georg Brandl54a3faa2008-01-20 09:30:57 +000066
67 Return the maximum representable finite float *DBL_MAX* as C :ctype:`double`.
68
69
Georg Brandlc5605df2009-08-13 08:26:44 +000070.. cfunction:: double PyFloat_GetMin()
Georg Brandl54a3faa2008-01-20 09:30:57 +000071
72 Return the minimum normalized positive float *DBL_MIN* as C :ctype:`double`.
Christian Heimes15ebc882008-02-04 18:48:49 +000073
Georg Brandlc5605df2009-08-13 08:26:44 +000074.. cfunction:: 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.