Skip to content

Commit 5260810

Browse files
committed
py: Wrap mpz float functions in MICROPY_ENABLE_FLOAT.
1 parent fdf0da5 commit 5260810

3 files changed

Lines changed: 13 additions & 6 deletions

File tree

py/mpz.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1001,8 +1001,9 @@ machine_int_t mpz_as_int(const mpz_t *i) {
10011001
return val;
10021002
}
10031003

1004-
machine_float_t mpz_as_float(const mpz_t *i) {
1005-
machine_float_t val = 0;
1004+
#if MICROPY_ENABLE_FLOAT
1005+
mp_float_t mpz_as_float(const mpz_t *i) {
1006+
mp_float_t val = 0;
10061007
mpz_dig_t *d = i->dig + i->len;
10071008

10081009
while (--d >= i->dig) {
@@ -1015,6 +1016,7 @@ machine_float_t mpz_as_float(const mpz_t *i) {
10151016

10161017
return val;
10171018
}
1019+
#endif
10181020

10191021
uint mpz_as_str_size(const mpz_t *i, uint base) {
10201022
if (base < 2 || base > 32) {

py/mpz.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,9 @@ mpz_t *mpz_div(const mpz_t *lhs, const mpz_t *rhs);
6565
mpz_t *mpz_mod(const mpz_t *lhs, const mpz_t *rhs);
6666

6767
machine_int_t mpz_as_int(const mpz_t *z);
68-
machine_float_t mpz_as_float(const mpz_t *z);
68+
#if MICROPY_ENABLE_FLOAT
69+
mp_float_t mpz_as_float(const mpz_t *z);
70+
#endif
6971
uint mpz_as_str_size(const mpz_t *z, uint base);
7072
char *mpz_as_str(const mpz_t *z, uint base);
7173
uint mpz_as_str_inpl(const mpz_t *z, uint base, char *str);

py/objint_mpz.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,13 @@ mp_obj_t int_binary_op(int op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
6060
return MP_OBJ_NULL;
6161
}
6262

63-
if (op == RT_BINARY_OP_TRUE_DIVIDE || op == RT_BINARY_OP_INPLACE_TRUE_DIVIDE) {
64-
machine_float_t flhs = mpz_as_float(zlhs);
65-
machine_float_t frhs = mpz_as_float(zrhs);
63+
if (0) {
64+
#if MICROPY_ENABLE_FLOAT
65+
} else if (op == RT_BINARY_OP_TRUE_DIVIDE || op == RT_BINARY_OP_INPLACE_TRUE_DIVIDE) {
66+
mp_float_t flhs = mpz_as_float(zlhs);
67+
mp_float_t frhs = mpz_as_float(zrhs);
6668
return mp_obj_new_float(flhs / frhs);
69+
#endif
6770

6871
} else if (op <= RT_BINARY_OP_POWER) {
6972
mp_obj_int_t *res = mp_obj_int_new_mpz();

0 commit comments

Comments
 (0)