summaryrefslogtreecommitdiffstats
path: root/Include/cpython/floatobject.h
diff options
context:
space:
mode:
Diffstat (limited to 'Include/cpython/floatobject.h')
-rw-r--r--Include/cpython/floatobject.h10
1 files changed, 8 insertions, 2 deletions
diff --git a/Include/cpython/floatobject.h b/Include/cpython/floatobject.h
index 7795d9f..1270930 100644
--- a/Include/cpython/floatobject.h
+++ b/Include/cpython/floatobject.h
@@ -7,9 +7,15 @@ typedef struct {
double ob_fval;
} PyFloatObject;
-// Macro version of PyFloat_AsDouble() trading safety for speed.
+#define _PyFloat_CAST(op) \
+ (assert(PyFloat_Check(op)), _Py_CAST(PyFloatObject*, op))
+
+// Static inline version of PyFloat_AsDouble() trading safety for speed.
// It doesn't check if op is a double object.
-#define PyFloat_AS_DOUBLE(op) (((PyFloatObject *)(op))->ob_fval)
+static inline double PyFloat_AS_DOUBLE(PyObject *op) {
+ return _PyFloat_CAST(op)->ob_fval;
+}
+#define PyFloat_AS_DOUBLE(op) PyFloat_AS_DOUBLE(_PyObject_CAST(op))
PyAPI_FUNC(int) PyFloat_Pack2(double x, char *p, int le);