Skip to content

Commit e4af712

Browse files
committed
py/objint: Rename mp_obj_int_as_float to mp_obj_int_as_float_impl.
And also simplify it to remove the check for small int. This can be done because this function is only ever called if the argument is not a small int.
1 parent 67f3edc commit e4af712

6 files changed

Lines changed: 15 additions & 25 deletions

File tree

py/obj.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,8 +271,10 @@ mp_float_t mp_obj_get_float(mp_obj_t arg) {
271271
return 1;
272272
} else if (MP_OBJ_IS_SMALL_INT(arg)) {
273273
return MP_OBJ_SMALL_INT_VALUE(arg);
274+
#if MICROPY_LONGINT_IMPL != MICROPY_LONGINT_IMPL_NONE
274275
} else if (MP_OBJ_IS_TYPE(arg, &mp_type_int)) {
275-
return mp_obj_int_as_float(arg);
276+
return mp_obj_int_as_float_impl(arg);
277+
#endif
276278
} else if (mp_obj_is_float(arg)) {
277279
return mp_obj_float_get(arg);
278280
} else {
@@ -296,9 +298,11 @@ void mp_obj_get_complex(mp_obj_t arg, mp_float_t *real, mp_float_t *imag) {
296298
} else if (MP_OBJ_IS_SMALL_INT(arg)) {
297299
*real = MP_OBJ_SMALL_INT_VALUE(arg);
298300
*imag = 0;
301+
#if MICROPY_LONGINT_IMPL != MICROPY_LONGINT_IMPL_NONE
299302
} else if (MP_OBJ_IS_TYPE(arg, &mp_type_int)) {
300-
*real = mp_obj_int_as_float(arg);
303+
*real = mp_obj_int_as_float_impl(arg);
301304
*imag = 0;
305+
#endif
302306
} else if (mp_obj_is_float(arg)) {
303307
*real = mp_obj_float_get(arg);
304308
*imag = 0;

py/obj.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -680,9 +680,6 @@ void mp_obj_cell_set(mp_obj_t self_in, mp_obj_t obj);
680680
mp_int_t mp_obj_int_get_truncated(mp_const_obj_t self_in);
681681
// Will raise exception if value doesn't fit into mp_int_t
682682
mp_int_t mp_obj_int_get_checked(mp_const_obj_t self_in);
683-
#if MICROPY_PY_BUILTINS_FLOAT
684-
mp_float_t mp_obj_int_as_float(mp_obj_t self_in);
685-
#endif
686683

687684
// exception
688685
#define mp_obj_is_native_exception_instance(o) (mp_obj_get_type(o)->make_new == mp_obj_exception_make_new)

py/objint.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -354,12 +354,6 @@ mp_int_t mp_obj_int_get_checked(mp_const_obj_t self_in) {
354354
return MP_OBJ_SMALL_INT_VALUE(self_in);
355355
}
356356

357-
#if MICROPY_PY_BUILTINS_FLOAT
358-
mp_float_t mp_obj_int_as_float(mp_obj_t self_in) {
359-
return MP_OBJ_SMALL_INT_VALUE(self_in);
360-
}
361-
#endif
362-
363357
#endif // MICROPY_LONGINT_IMPL == MICROPY_LONGINT_IMPL_NONE
364358

365359
// This dispatcher function is expected to be independent of the implementation of long int

py/objint.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ typedef enum {
4848
} mp_fp_as_int_class_t;
4949

5050
mp_fp_as_int_class_t mp_classify_fp_as_int(mp_float_t val);
51+
mp_float_t mp_obj_int_as_float_impl(mp_obj_t self_in);
5152
#endif // MICROPY_PY_BUILTINS_FLOAT
5253

5354
size_t mp_int_format_size(size_t num_bits, int base, const char *prefix, char comma);

py/objint_longlong.c

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -295,13 +295,10 @@ mp_int_t mp_obj_int_get_checked(mp_const_obj_t self_in) {
295295
}
296296

297297
#if MICROPY_PY_BUILTINS_FLOAT
298-
mp_float_t mp_obj_int_as_float(mp_obj_t self_in) {
299-
if (MP_OBJ_IS_SMALL_INT(self_in)) {
300-
return MP_OBJ_SMALL_INT_VALUE(self_in);
301-
} else {
302-
mp_obj_int_t *self = self_in;
303-
return self->val;
304-
}
298+
mp_float_t mp_obj_int_as_float_impl(mp_obj_t self_in) {
299+
assert(MP_OBJ_IS_TYPE(self_in, &mp_type_int));
300+
mp_obj_int_t *self = self_in;
301+
return self->val;
305302
}
306303
#endif
307304

py/objint_mpz.c

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -403,13 +403,10 @@ mp_int_t mp_obj_int_get_checked(mp_const_obj_t self_in) {
403403
}
404404

405405
#if MICROPY_PY_BUILTINS_FLOAT
406-
mp_float_t mp_obj_int_as_float(mp_obj_t self_in) {
407-
if (MP_OBJ_IS_SMALL_INT(self_in)) {
408-
return MP_OBJ_SMALL_INT_VALUE(self_in);
409-
} else {
410-
mp_obj_int_t *self = MP_OBJ_TO_PTR(self_in);
411-
return mpz_as_float(&self->mpz);
412-
}
406+
mp_float_t mp_obj_int_as_float_impl(mp_obj_t self_in) {
407+
assert(MP_OBJ_IS_TYPE(self_in, &mp_type_int));
408+
mp_obj_int_t *self = MP_OBJ_TO_PTR(self_in);
409+
return mpz_as_float(&self->mpz);
413410
}
414411
#endif
415412

0 commit comments

Comments
 (0)