diff options
author | stijn <stijn@ignitron.net> | 2020-04-13 20:56:31 +0200 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2020-04-18 22:42:24 +1000 |
commit | 70affd9ba22e7f62666a9a2fafc2a3c0be9ef95a (patch) | |
tree | 068485d00339bf0b89a5b8ea328396ffa21a0b14 /py | |
parent | bcf01d1686a8fa6d257daea25ce0d7df6e4ad839 (diff) |
all: Fix implicit floating point to integer conversions.
These are found when building with -Wfloat-conversion.
Diffstat (limited to 'py')
-rw-r--r-- | py/binary.c | 4 | ||||
-rw-r--r-- | py/modbuiltins.c | 2 | ||||
-rw-r--r-- | py/obj.c | 4 | ||||
-rw-r--r-- | py/runtime.c | 6 |
4 files changed, 8 insertions, 8 deletions
diff --git a/py/binary.c b/py/binary.c index a53b8847c..d0f72ec23 100644 --- a/py/binary.c +++ b/py/binary.c @@ -419,10 +419,10 @@ void mp_binary_set_val_array_from_int(char typecode, void *p, size_t index, mp_i #endif #if MICROPY_PY_BUILTINS_FLOAT case 'f': - ((float *)p)[index] = val; + ((float *)p)[index] = (float)val; break; case 'd': - ((double *)p)[index] = val; + ((double *)p)[index] = (double)val; break; #endif // Extension to CPython: array of pointers diff --git a/py/modbuiltins.c b/py/modbuiltins.c index c1f3f771f..85d30ab66 100644 --- a/py/modbuiltins.c +++ b/py/modbuiltins.c @@ -509,7 +509,7 @@ STATIC mp_obj_t mp_builtin_round(size_t n_args, const mp_obj_t *args) { mp_float_t val = mp_obj_get_float(o_in); if (n_args > 1) { mp_int_t num_dig = mp_obj_get_int(args[1]); - mp_float_t mult = MICROPY_FLOAT_C_FUN(pow)(10, num_dig); + mp_float_t mult = MICROPY_FLOAT_C_FUN(pow)(10, (mp_float_t)num_dig); // TODO may lead to overflow mp_float_t rounded = MICROPY_FLOAT_C_FUN(nearbyint)(val * mult) / mult; return mp_obj_new_float(rounded); @@ -340,7 +340,7 @@ bool mp_obj_get_float_maybe(mp_obj_t arg, mp_float_t *value) { } else if (arg == mp_const_true) { val = 1; } else if (mp_obj_is_small_int(arg)) { - val = MP_OBJ_SMALL_INT_VALUE(arg); + val = (mp_float_t)MP_OBJ_SMALL_INT_VALUE(arg); #if MICROPY_LONGINT_IMPL != MICROPY_LONGINT_IMPL_NONE } else if (mp_obj_is_type(arg, &mp_type_int)) { val = mp_obj_int_as_float_impl(arg); @@ -379,7 +379,7 @@ void mp_obj_get_complex(mp_obj_t arg, mp_float_t *real, mp_float_t *imag) { *real = 1; *imag = 0; } else if (mp_obj_is_small_int(arg)) { - *real = MP_OBJ_SMALL_INT_VALUE(arg); + *real = (mp_float_t)MP_OBJ_SMALL_INT_VALUE(arg); *imag = 0; #if MICROPY_LONGINT_IMPL != MICROPY_LONGINT_IMPL_NONE } else if (mp_obj_is_type(arg, &mp_type_int)) { diff --git a/py/runtime.c b/py/runtime.c index 1fa9e73f2..79ca45fb1 100644 --- a/py/runtime.c +++ b/py/runtime.c @@ -473,7 +473,7 @@ mp_obj_t mp_binary_op(mp_binary_op_t op, mp_obj_t lhs, mp_obj_t rhs) { case MP_BINARY_OP_INPLACE_POWER: if (rhs_val < 0) { #if MICROPY_PY_BUILTINS_FLOAT - return mp_obj_float_binary_op(op, lhs_val, rhs); + return mp_obj_float_binary_op(op, (mp_float_t)lhs_val, rhs); #else mp_raise_ValueError(MP_ERROR_TEXT("negative power with no float support")); #endif @@ -535,7 +535,7 @@ mp_obj_t mp_binary_op(mp_binary_op_t op, mp_obj_t lhs, mp_obj_t rhs) { } #if MICROPY_PY_BUILTINS_FLOAT } else if (mp_obj_is_float(rhs)) { - mp_obj_t res = mp_obj_float_binary_op(op, lhs_val, rhs); + mp_obj_t res = mp_obj_float_binary_op(op, (mp_float_t)lhs_val, rhs); if (res == MP_OBJ_NULL) { goto unsupported_op; } else { @@ -544,7 +544,7 @@ mp_obj_t mp_binary_op(mp_binary_op_t op, mp_obj_t lhs, mp_obj_t rhs) { #endif #if MICROPY_PY_BUILTINS_COMPLEX } else if (mp_obj_is_type(rhs, &mp_type_complex)) { - mp_obj_t res = mp_obj_complex_binary_op(op, lhs_val, 0, rhs); + mp_obj_t res = mp_obj_complex_binary_op(op, (mp_float_t)lhs_val, 0, rhs); if (res == MP_OBJ_NULL) { goto unsupported_op; } else { |