Guido van Rossum | f70e43a | 1991-02-19 12:39:46 +0000 | [diff] [blame] | 1 | |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 2 | /* Float object interface */ |
| 3 | |
| 4 | /* |
Guido van Rossum | caa6380 | 1995-01-12 11:45:45 +0000 | [diff] [blame] | 5 | PyFloatObject represents a (double precision) floating point number. |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
Fred Drake | ea9cb5a | 2000-07-09 00:20:36 +0000 | [diff] [blame] | 8 | #ifndef Py_FLOATOBJECT_H |
| 9 | #define Py_FLOATOBJECT_H |
| 10 | #ifdef __cplusplus |
| 11 | extern "C" { |
| 12 | #endif |
| 13 | |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 14 | typedef struct { |
Fred Drake | ea9cb5a | 2000-07-09 00:20:36 +0000 | [diff] [blame] | 15 | PyObject_HEAD |
| 16 | double ob_fval; |
Guido van Rossum | caa6380 | 1995-01-12 11:45:45 +0000 | [diff] [blame] | 17 | } PyFloatObject; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 18 | |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 19 | PyAPI_DATA(PyTypeObject) PyFloat_Type; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 20 | |
Guido van Rossum | c16fcdf | 2001-08-29 15:45:32 +0000 | [diff] [blame] | 21 | #define PyFloat_Check(op) PyObject_TypeCheck(op, &PyFloat_Type) |
Tim Peters | 7a50f25 | 2001-09-10 21:28:20 +0000 | [diff] [blame] | 22 | #define PyFloat_CheckExact(op) ((op)->ob_type == &PyFloat_Type) |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 23 | |
Tim Peters | 72f98e9 | 2001-05-08 15:19:57 +0000 | [diff] [blame] | 24 | /* Return Python float from string PyObject. Second argument ignored on |
| 25 | input, and, if non-NULL, NULL is stored into *junk (this tried to serve a |
| 26 | purpose once but can't be made to work as intended). */ |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 27 | PyAPI_FUNC(PyObject *) PyFloat_FromString(PyObject*, char** junk); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 28 | |
Tim Peters | 72f98e9 | 2001-05-08 15:19:57 +0000 | [diff] [blame] | 29 | /* Return Python float from C double. */ |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 30 | PyAPI_FUNC(PyObject *) PyFloat_FromDouble(double); |
Tim Peters | 72f98e9 | 2001-05-08 15:19:57 +0000 | [diff] [blame] | 31 | |
| 32 | /* Extract C double from Python float. The macro version trades safety for |
| 33 | speed. */ |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 34 | PyAPI_FUNC(double) PyFloat_AsDouble(PyObject *); |
Guido van Rossum | 2981bc7 | 1997-08-02 02:40:58 +0000 | [diff] [blame] | 35 | #define PyFloat_AS_DOUBLE(op) (((PyFloatObject *)(op))->ob_fval) |
Guido van Rossum | a330996 | 1993-07-28 09:05:47 +0000 | [diff] [blame] | 36 | |
Tim Peters | 72f98e9 | 2001-05-08 15:19:57 +0000 | [diff] [blame] | 37 | /* Write repr(v) into the char buffer argument, followed by null byte. The |
| 38 | buffer must be "big enough"; >= 100 is very safe. |
| 39 | PyFloat_AsReprString(buf, x) strives to print enough digits so that |
| 40 | PyFloat_FromString(buf) then reproduces x exactly. */ |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 41 | PyAPI_FUNC(void) PyFloat_AsReprString(char*, PyFloatObject *v); |
Tim Peters | 72f98e9 | 2001-05-08 15:19:57 +0000 | [diff] [blame] | 42 | |
| 43 | /* Write str(v) into the char buffer argument, followed by null byte. The |
| 44 | buffer must be "big enough"; >= 100 is very safe. Note that it's |
| 45 | unusual to be able to get back the float you started with from |
| 46 | PyFloat_AsString's result -- use PyFloat_AsReprString() if you want to |
| 47 | preserve precision across conversions. */ |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 48 | PyAPI_FUNC(void) PyFloat_AsString(char*, PyFloatObject *v); |
Tim Peters | 72f98e9 | 2001-05-08 15:19:57 +0000 | [diff] [blame] | 49 | |
Guido van Rossum | a330996 | 1993-07-28 09:05:47 +0000 | [diff] [blame] | 50 | #ifdef __cplusplus |
| 51 | } |
| 52 | #endif |
| 53 | #endif /* !Py_FLOATOBJECT_H */ |