Make mp_float_t conversions explicit to silence warnings of converting floats to doubles.

This commit is contained in:
Scott Shawcroft 2017-02-14 10:55:54 +01:00
parent 9ed3e11aec
commit 18c299b13d
6 changed files with 8 additions and 8 deletions

View File

@ -338,7 +338,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((mp_float_t)((float*)p)[index]);
case FLOAT64:
return mp_obj_new_float(((double*)p)[index]);
#endif

View File

@ -138,7 +138,7 @@ mp_obj_t mp_binary_get_val_array(char typecode, void *p, mp_uint_t index) {
#endif
#if MICROPY_PY_BUILTINS_FLOAT
case 'f':
return mp_obj_new_float(((float*)p)[index]);
return mp_obj_new_float((mp_float_t)((float*)p)[index]);
case 'd':
return mp_obj_new_float(((double*)p)[index]);
#endif
@ -204,7 +204,7 @@ mp_obj_t mp_binary_get_val(char struct_type, char val_type, byte **ptr) {
#if MICROPY_PY_BUILTINS_FLOAT
} else if (val_type == 'f') {
union { uint32_t i; float f; } fpu = {val};
return mp_obj_new_float(fpu.f);
return mp_obj_new_float((mp_float_t) fpu.f);
} else if (val_type == 'd') {
union { uint64_t i; double f; } fpu = {val};
return mp_obj_new_float(fpu.f);

View File

@ -428,7 +428,7 @@ STATIC mp_obj_t array_subscr(mp_obj_t self_in, mp_obj_t index_in, mp_obj_t value
}
#endif
if (len_adj > 0) {
if (len_adj > o->free) {
if ((mp_uint_t) len_adj > o->free) {
// TODO: alloc policy; at the moment we go conservative
o->items = m_renew(byte, o->items, (o->len + o->free) * item_sz, (o->len + len_adj) * item_sz);
o->free = 0;

View File

@ -197,7 +197,7 @@ mp_obj_t mp_parse_num_decimal(const char *str, size_t len, bool allow_imag, bool
if (str + 2 < top && (str[1] | 0x20) == 'n' && (str[2] | 0x20) == 'f') {
// inf
str += 3;
dec_val = INFINITY;
dec_val = (mp_float_t) INFINITY;
if (str + 4 < top && (str[0] | 0x20) == 'i' && (str[1] | 0x20) == 'n' && (str[2] | 0x20) == 'i' && (str[3] | 0x20) == 't' && (str[4] | 0x20) == 'y') {
// infinity
str += 5;

View File

@ -153,7 +153,7 @@ STATIC mp_obj_t return_ffi_value(ffi_arg val, char type)
#if MICROPY_PY_BUILTINS_FLOAT
case 'f': {
union { ffi_arg ffi; float flt; } val_union = { .ffi = val };
return mp_obj_new_float(val_union.flt);
return mp_obj_new_float((mp_float_t) val_union.flt);
}
case 'd': {
double *p = (double*)&val;

View File

@ -60,7 +60,7 @@ static inline int msec_sleep_tv(struct timeval *tv) {
#endif
#if defined(MP_CLOCKS_PER_SEC)
#define CLOCK_DIV (MP_CLOCKS_PER_SEC / 1000.0F)
#define CLOCK_DIV (mp_float_t) (MP_CLOCKS_PER_SEC / 1000.0F)
#else
#error Unsupported clock() implementation
#endif
@ -83,7 +83,7 @@ STATIC mp_obj_t mod_time_clock(void) {
// float cannot represent full range of int32 precisely, so we pre-divide
// int to reduce resolution, and then actually do float division hoping
// to preserve integer part resolution.
return mp_obj_new_float((float)(clock() / 1000) / CLOCK_DIV);
return mp_obj_new_float((mp_float_t)(clock() / 1000) / CLOCK_DIV);
#else
return mp_obj_new_int((mp_int_t)clock());
#endif