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.
This commit is contained in:
stijn
2020-04-09 09:05:48 +02:00
committed by Damien George
parent b909e8b2dd
commit 0ba68f8a1d
11 changed files with 70 additions and 54 deletions

View File

@@ -360,7 +360,7 @@ STATIC mp_obj_t get_aligned(uint val_type, void *p, mp_int_t index) {
return mp_obj_new_int_from_ll(((int64_t *)p)[index]);
#if MICROPY_PY_BUILTINS_FLOAT
case FLOAT32:
return mp_obj_new_float(((float *)p)[index]);
return mp_obj_new_float_from_f(((float *)p)[index]);
case FLOAT64:
return mp_obj_new_float(((double *)p)[index]);
#endif
@@ -373,11 +373,10 @@ STATIC mp_obj_t get_aligned(uint val_type, void *p, mp_int_t index) {
STATIC void set_aligned(uint val_type, void *p, mp_int_t index, mp_obj_t val) {
#if MICROPY_PY_BUILTINS_FLOAT
if (val_type == FLOAT32 || val_type == FLOAT64) {
mp_float_t v = mp_obj_get_float(val);
if (val_type == FLOAT32) {
((float *)p)[index] = v;
((float *)p)[index] = mp_obj_get_float_to_f(val);
} else {
((double *)p)[index] = v;
((double *)p)[index] = mp_obj_get_float_to_d(val);
}
return;
}