Stéphane Wirtel | cbb6484 | 2019-05-17 11:55:34 +0200 | [diff] [blame] | 1 | .. highlight:: c |
Georg Brandl | 54a3faa | 2008-01-20 09:30:57 +0000 | [diff] [blame] | 2 | |
| 3 | .. _floatobjects: |
| 4 | |
| 5 | Floating Point Objects |
| 6 | ---------------------- |
| 7 | |
| 8 | .. index:: object: floating point |
| 9 | |
| 10 | |
Georg Brandl | 60203b4 | 2010-10-06 10:11:56 +0000 | [diff] [blame] | 11 | .. c:type:: PyFloatObject |
Georg Brandl | 54a3faa | 2008-01-20 09:30:57 +0000 | [diff] [blame] | 12 | |
Georg Brandl | 60203b4 | 2010-10-06 10:11:56 +0000 | [diff] [blame] | 13 | This subtype of :c:type:`PyObject` represents a Python floating point object. |
Georg Brandl | 54a3faa | 2008-01-20 09:30:57 +0000 | [diff] [blame] | 14 | |
| 15 | |
Georg Brandl | 60203b4 | 2010-10-06 10:11:56 +0000 | [diff] [blame] | 16 | .. c:var:: PyTypeObject PyFloat_Type |
Georg Brandl | 54a3faa | 2008-01-20 09:30:57 +0000 | [diff] [blame] | 17 | |
Georg Brandl | 60203b4 | 2010-10-06 10:11:56 +0000 | [diff] [blame] | 18 | This instance of :c:type:`PyTypeObject` represents the Python floating point |
Georg Brandl | 2aff335 | 2010-10-17 10:59:41 +0000 | [diff] [blame] | 19 | type. This is the same object as :class:`float` in the Python layer. |
Georg Brandl | 54a3faa | 2008-01-20 09:30:57 +0000 | [diff] [blame] | 20 | |
| 21 | |
Georg Brandl | 60203b4 | 2010-10-06 10:11:56 +0000 | [diff] [blame] | 22 | .. c:function:: int PyFloat_Check(PyObject *p) |
Georg Brandl | 54a3faa | 2008-01-20 09:30:57 +0000 | [diff] [blame] | 23 | |
Georg Brandl | 60203b4 | 2010-10-06 10:11:56 +0000 | [diff] [blame] | 24 | Return true if its argument is a :c:type:`PyFloatObject` or a subtype of |
| 25 | :c:type:`PyFloatObject`. |
Georg Brandl | 54a3faa | 2008-01-20 09:30:57 +0000 | [diff] [blame] | 26 | |
| 27 | |
Georg Brandl | 60203b4 | 2010-10-06 10:11:56 +0000 | [diff] [blame] | 28 | .. c:function:: int PyFloat_CheckExact(PyObject *p) |
Georg Brandl | 54a3faa | 2008-01-20 09:30:57 +0000 | [diff] [blame] | 29 | |
Georg Brandl | 60203b4 | 2010-10-06 10:11:56 +0000 | [diff] [blame] | 30 | Return true if its argument is a :c:type:`PyFloatObject`, but not a subtype of |
| 31 | :c:type:`PyFloatObject`. |
Georg Brandl | 54a3faa | 2008-01-20 09:30:57 +0000 | [diff] [blame] | 32 | |
| 33 | |
Georg Brandl | 60203b4 | 2010-10-06 10:11:56 +0000 | [diff] [blame] | 34 | .. c:function:: PyObject* PyFloat_FromString(PyObject *str) |
Georg Brandl | 54a3faa | 2008-01-20 09:30:57 +0000 | [diff] [blame] | 35 | |
Georg Brandl | 60203b4 | 2010-10-06 10:11:56 +0000 | [diff] [blame] | 36 | Create a :c:type:`PyFloatObject` object based on the string value in *str*, or |
Georg Brandl | 54a3faa | 2008-01-20 09:30:57 +0000 | [diff] [blame] | 37 | *NULL* on failure. |
| 38 | |
| 39 | |
Georg Brandl | 60203b4 | 2010-10-06 10:11:56 +0000 | [diff] [blame] | 40 | .. c:function:: PyObject* PyFloat_FromDouble(double v) |
Georg Brandl | 54a3faa | 2008-01-20 09:30:57 +0000 | [diff] [blame] | 41 | |
Georg Brandl | 60203b4 | 2010-10-06 10:11:56 +0000 | [diff] [blame] | 42 | Create a :c:type:`PyFloatObject` object from *v*, or *NULL* on failure. |
Georg Brandl | 54a3faa | 2008-01-20 09:30:57 +0000 | [diff] [blame] | 43 | |
| 44 | |
Georg Brandl | 60203b4 | 2010-10-06 10:11:56 +0000 | [diff] [blame] | 45 | .. c:function:: double PyFloat_AsDouble(PyObject *pyfloat) |
Georg Brandl | 54a3faa | 2008-01-20 09:30:57 +0000 | [diff] [blame] | 46 | |
Georg Brandl | 60203b4 | 2010-10-06 10:11:56 +0000 | [diff] [blame] | 47 | Return a C :c:type:`double` representation of the contents of *pyfloat*. If |
Georg Brandl | 54a3faa | 2008-01-20 09:30:57 +0000 | [diff] [blame] | 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. |
Serhiy Storchaka | bdbad71 | 2019-06-02 00:05:48 +0300 | [diff] [blame] | 50 | If ``__float__()`` is not defined then it falls back to :meth:`__index__`. |
Antoine Pitrou | 07b1c87 | 2011-12-18 01:25:27 +0100 | [diff] [blame] | 51 | This method returns ``-1.0`` upon failure, so one should call |
| 52 | :c:func:`PyErr_Occurred` to check for errors. |
Georg Brandl | 54a3faa | 2008-01-20 09:30:57 +0000 | [diff] [blame] | 53 | |
Serhiy Storchaka | bdbad71 | 2019-06-02 00:05:48 +0300 | [diff] [blame] | 54 | .. versionchanged:: 3.8 |
| 55 | Use :meth:`__index__` if available. |
| 56 | |
Georg Brandl | 54a3faa | 2008-01-20 09:30:57 +0000 | [diff] [blame] | 57 | |
Georg Brandl | 60203b4 | 2010-10-06 10:11:56 +0000 | [diff] [blame] | 58 | .. c:function:: double PyFloat_AS_DOUBLE(PyObject *pyfloat) |
Georg Brandl | 54a3faa | 2008-01-20 09:30:57 +0000 | [diff] [blame] | 59 | |
Georg Brandl | 60203b4 | 2010-10-06 10:11:56 +0000 | [diff] [blame] | 60 | Return a C :c:type:`double` representation of the contents of *pyfloat*, but |
Georg Brandl | 54a3faa | 2008-01-20 09:30:57 +0000 | [diff] [blame] | 61 | without error checking. |
| 62 | |
| 63 | |
Georg Brandl | 60203b4 | 2010-10-06 10:11:56 +0000 | [diff] [blame] | 64 | .. c:function:: PyObject* PyFloat_GetInfo(void) |
Georg Brandl | 54a3faa | 2008-01-20 09:30:57 +0000 | [diff] [blame] | 65 | |
| 66 | Return a structseq instance which contains information about the |
| 67 | precision, minimum and maximum values of a float. It's a thin wrapper |
| 68 | around the header file :file:`float.h`. |
| 69 | |
| 70 | |
Georg Brandl | 60203b4 | 2010-10-06 10:11:56 +0000 | [diff] [blame] | 71 | .. c:function:: double PyFloat_GetMax() |
Georg Brandl | 54a3faa | 2008-01-20 09:30:57 +0000 | [diff] [blame] | 72 | |
Georg Brandl | 60203b4 | 2010-10-06 10:11:56 +0000 | [diff] [blame] | 73 | Return the maximum representable finite float *DBL_MAX* as C :c:type:`double`. |
Georg Brandl | 54a3faa | 2008-01-20 09:30:57 +0000 | [diff] [blame] | 74 | |
| 75 | |
Georg Brandl | 60203b4 | 2010-10-06 10:11:56 +0000 | [diff] [blame] | 76 | .. c:function:: double PyFloat_GetMin() |
Georg Brandl | 54a3faa | 2008-01-20 09:30:57 +0000 | [diff] [blame] | 77 | |
Georg Brandl | 60203b4 | 2010-10-06 10:11:56 +0000 | [diff] [blame] | 78 | Return the minimum normalized positive float *DBL_MIN* as C :c:type:`double`. |
Christian Heimes | 15ebc88 | 2008-02-04 18:48:49 +0000 | [diff] [blame] | 79 | |
Georg Brandl | 60203b4 | 2010-10-06 10:11:56 +0000 | [diff] [blame] | 80 | .. c:function:: int PyFloat_ClearFreeList() |
Christian Heimes | 15ebc88 | 2008-02-04 18:48:49 +0000 | [diff] [blame] | 81 | |
Georg Brandl | 2ee470f | 2008-07-16 12:55:28 +0000 | [diff] [blame] | 82 | Clear the float free list. Return the number of items that could not |
| 83 | be freed. |