all: Fix implicit conversion from double to float.

These are found when building with -Wfloat-conversion.
This commit is contained in:
stijn
2020-03-31 14:48:08 +02:00
committed by Damien George
parent dc4d119d3d
commit bcf01d1686
23 changed files with 266 additions and 265 deletions

View File

@@ -178,7 +178,7 @@ mp_obj_t mp_binary_get_val_array(char typecode, void *p, size_t index) {
case 'f':
return mp_obj_new_float_from_f(((float *)p)[index]);
case 'd':
return mp_obj_new_float(((double *)p)[index]);
return mp_obj_new_float_from_d(((double *)p)[index]);
#endif
// Extension to CPython: array of objects
case 'O':
@@ -249,7 +249,7 @@ mp_obj_t mp_binary_get_val(char struct_type, char val_type, byte *p_base, byte *
union { uint64_t i;
double f;
} fpu = {val};
return mp_obj_new_float(fpu.f);
return mp_obj_new_float_from_d(fpu.f);
#endif
} else if (is_signed(val_type)) {
if ((long long)MP_SMALL_INT_MIN <= val && val <= (long long)MP_SMALL_INT_MAX) {
@@ -311,7 +311,7 @@ void mp_binary_set_val(char struct_type, char val_type, mp_obj_t val_in, byte *p
union { uint32_t i;
float f;
} fp_sp;
fp_sp.f = mp_obj_get_float(val_in);
fp_sp.f = mp_obj_get_float_to_f(val_in);
val = fp_sp.i;
break;
}
@@ -359,7 +359,7 @@ void mp_binary_set_val_array(char typecode, void *p, size_t index, mp_obj_t val_
switch (typecode) {
#if MICROPY_PY_BUILTINS_FLOAT
case 'f':
((float *)p)[index] = mp_obj_get_float(val_in);
((float *)p)[index] = mp_obj_get_float_to_f(val_in);
break;
case 'd':
((double *)p)[index] = mp_obj_get_float_to_d(val_in);

View File

@@ -100,15 +100,15 @@ static inline int fp_isless1(float x) {
static const FPTYPE g_pos_pow[] = {
#if FPDECEXP > 32
1e256, 1e128, 1e64,
MICROPY_FLOAT_CONST(1e256), MICROPY_FLOAT_CONST(1e128), MICROPY_FLOAT_CONST(1e64),
#endif
1e32, 1e16, 1e8, 1e4, 1e2, 1e1
MICROPY_FLOAT_CONST(1e32), MICROPY_FLOAT_CONST(1e16), MICROPY_FLOAT_CONST(1e8), MICROPY_FLOAT_CONST(1e4), MICROPY_FLOAT_CONST(1e2), MICROPY_FLOAT_CONST(1e1)
};
static const FPTYPE g_neg_pow[] = {
#if FPDECEXP > 32
1e-256, 1e-128, 1e-64,
MICROPY_FLOAT_CONST(1e-256), MICROPY_FLOAT_CONST(1e-128), MICROPY_FLOAT_CONST(1e-64),
#endif
1e-32, 1e-16, 1e-8, 1e-4, 1e-2, 1e-1
MICROPY_FLOAT_CONST(1e-32), MICROPY_FLOAT_CONST(1e-16), MICROPY_FLOAT_CONST(1e-8), MICROPY_FLOAT_CONST(1e-4), MICROPY_FLOAT_CONST(1e-2), MICROPY_FLOAT_CONST(1e-1)
};
int mp_format_float(FPTYPE f, char *buf, size_t buf_size, char fmt, int prec, char sign) {

View File

@@ -542,7 +542,7 @@ int mp_vprintf(const mp_print_t *print, const char *fmt, va_list args) {
case 'g':
case 'G': {
#if ((MICROPY_FLOAT_IMPL == MICROPY_FLOAT_IMPL_FLOAT) || (MICROPY_FLOAT_IMPL == MICROPY_FLOAT_IMPL_DOUBLE))
mp_float_t f = va_arg(args, double);
mp_float_t f = (mp_float_t)va_arg(args, double);
chrs += mp_print_float(print, f, *fmt, flags, fill, width, prec);
#else
#error Unknown MICROPY FLOAT IMPL