aboutsummaryrefslogtreecommitdiff
path: root/py/binary.c
diff options
context:
space:
mode:
authorstijn <stijn@ignitron.net>2020-04-09 09:05:48 +0200
committerDamien George <damien.p.george@gmail.com>2020-04-18 22:36:14 +1000
commit0ba68f8a1dae84de950420aebf8ad46582a38e66 (patch)
treec996a9b3d26f58b286ef6f9deb508de141b66574 /py/binary.c
parentb909e8b2dd007d8e7d61547768518b29bb4f833c (diff)
all: Fix implicit floating point promotion.
Initially some of these were found building the unix coverage variant on MacOS because that build uses clang and has -Wdouble-promotion enabled, and clang performs more vigorous promotion checks than gcc. Additionally the codebase has been compiled with clang and msvc (the latter with warning level 3), and with MICROPY_FLOAT_IMPL_FLOAT to find the rest of the conversions. Fixes are implemented either as explicit casts, or by using the correct type, or by using one of the utility functions to handle floating point casting; these have been moved from nativeglue.c to the public API.
Diffstat (limited to 'py/binary.c')
-rw-r--r--py/binary.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/py/binary.c b/py/binary.c
index b29438770..33515e880 100644
--- a/py/binary.c
+++ b/py/binary.c
@@ -176,7 +176,7 @@ mp_obj_t mp_binary_get_val_array(char typecode, void *p, size_t index) {
#endif
#if MICROPY_PY_BUILTINS_FLOAT
case 'f':
- return mp_obj_new_float(((float *)p)[index]);
+ return mp_obj_new_float_from_f(((float *)p)[index]);
case 'd':
return mp_obj_new_float(((double *)p)[index]);
#endif
@@ -244,7 +244,7 @@ mp_obj_t mp_binary_get_val(char struct_type, char val_type, byte *p_base, byte *
union { uint32_t i;
float f;
} fpu = {val};
- return mp_obj_new_float(fpu.f);
+ return mp_obj_new_float_from_f(fpu.f);
} else if (val_type == 'd') {
union { uint64_t i;
double f;
@@ -320,7 +320,7 @@ void mp_binary_set_val(char struct_type, char val_type, mp_obj_t val_in, byte *p
uint32_t i32[2];
double f;
} fp_dp;
- fp_dp.f = mp_obj_get_float(val_in);
+ fp_dp.f = mp_obj_get_float_to_d(val_in);
if (BYTES_PER_WORD == 8) {
val = fp_dp.i64;
} else {
@@ -362,7 +362,7 @@ void mp_binary_set_val_array(char typecode, void *p, size_t index, mp_obj_t val_
((float *)p)[index] = mp_obj_get_float(val_in);
break;
case 'd':
- ((double *)p)[index] = mp_obj_get_float(val_in);
+ ((double *)p)[index] = mp_obj_get_float_to_d(val_in);
break;
#endif
// Extension to CPython: array of objects