summaryrefslogtreecommitdiffstatshomepage
path: root/py/dynruntime.h
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2019-11-30 23:03:09 +1100
committerDamien George <damien.p.george@gmail.com>2019-12-12 20:15:28 +1100
commitabc642973db46fbce7494d34ea0ef2539b339be0 (patch)
treefbf026f0dc669ec38a0c447eb1de1cbfb6820e28 /py/dynruntime.h
parentff58961944f4f2380e9610a4d18c53c08f68060e (diff)
downloadmicropython-abc642973db46fbce7494d34ea0ef2539b339be0.tar.gz
micropython-abc642973db46fbce7494d34ea0ef2539b339be0.zip
py/dynruntime: Add support for float API to make/get floats.
We don't want to add a feature flag to .mpy files that indicate float support because it will get complex and difficult to use. Instead the .mpy is built using whatever precision it chooses (float or double) and the native glue API will convert between this choice and what the host runtime actually uses.
Diffstat (limited to 'py/dynruntime.h')
-rw-r--r--py/dynruntime.h16
1 files changed, 16 insertions, 0 deletions
diff --git a/py/dynruntime.h b/py/dynruntime.h
index 34cf6010c4..a83aa905c1 100644
--- a/py/dynruntime.h
+++ b/py/dynruntime.h
@@ -190,4 +190,20 @@ static inline void mp_raise_OSError_dyn(int er) {
nlr_raise(mp_call_function_n_kw(mp_load_global(MP_QSTR_OSError), 1, 0, &args[0]));
}
+/******************************************************************************/
+// Floating point
+
+#define mp_obj_new_float_from_f(f) (mp_fun_table.obj_new_float_from_f((f)))
+#define mp_obj_new_float_from_d(d) (mp_fun_table.obj_new_float_from_d((d)))
+#define mp_obj_get_float_to_f(o) (mp_fun_table.obj_get_float_to_f((o)))
+#define mp_obj_get_float_to_d(o) (mp_fun_table.obj_get_float_to_d((o)))
+
+#if MICROPY_FLOAT_IMPL == MICROPY_FLOAT_IMPL_FLOAT
+#define mp_obj_new_float(f) (mp_obj_new_float_from_f((f)))
+#define mp_obj_get_float(o) (mp_obj_get_float_to_f((o)))
+#elif MICROPY_FLOAT_IMPL == MICROPY_FLOAT_IMPL_DOUBLE
+#define mp_obj_new_float(f) (mp_obj_new_float_from_d((f)))
+#define mp_obj_get_float(o) (mp_obj_get_float_to_d((o)))
+#endif
+
#endif // MICROPY_INCLUDED_PY_DYNRUNTIME_H