py: Wrap mpz float functions in MICROPY_ENABLE_FLOAT.

This commit is contained in:
Damien George 2014-03-08 15:04:54 +00:00
parent fdf0da5436
commit 5260810d70
3 changed files with 13 additions and 6 deletions

View File

@ -1001,8 +1001,9 @@ machine_int_t mpz_as_int(const mpz_t *i) {
return val;
}
machine_float_t mpz_as_float(const mpz_t *i) {
machine_float_t val = 0;
#if MICROPY_ENABLE_FLOAT
mp_float_t mpz_as_float(const mpz_t *i) {
mp_float_t val = 0;
mpz_dig_t *d = i->dig + i->len;
while (--d >= i->dig) {
@ -1015,6 +1016,7 @@ machine_float_t mpz_as_float(const mpz_t *i) {
return val;
}
#endif
uint mpz_as_str_size(const mpz_t *i, uint base) {
if (base < 2 || base > 32) {

View File

@ -65,7 +65,9 @@ mpz_t *mpz_div(const mpz_t *lhs, const mpz_t *rhs);
mpz_t *mpz_mod(const mpz_t *lhs, const mpz_t *rhs);
machine_int_t mpz_as_int(const mpz_t *z);
machine_float_t mpz_as_float(const mpz_t *z);
#if MICROPY_ENABLE_FLOAT
mp_float_t mpz_as_float(const mpz_t *z);
#endif
uint mpz_as_str_size(const mpz_t *z, uint base);
char *mpz_as_str(const mpz_t *z, uint base);
uint mpz_as_str_inpl(const mpz_t *z, uint base, char *str);

View File

@ -60,10 +60,13 @@ mp_obj_t int_binary_op(int op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
return MP_OBJ_NULL;
}
if (op == RT_BINARY_OP_TRUE_DIVIDE || op == RT_BINARY_OP_INPLACE_TRUE_DIVIDE) {
machine_float_t flhs = mpz_as_float(zlhs);
machine_float_t frhs = mpz_as_float(zrhs);
if (0) {
#if MICROPY_ENABLE_FLOAT
} else if (op == RT_BINARY_OP_TRUE_DIVIDE || op == RT_BINARY_OP_INPLACE_TRUE_DIVIDE) {
mp_float_t flhs = mpz_as_float(zlhs);
mp_float_t frhs = mpz_as_float(zrhs);
return mp_obj_new_float(flhs / frhs);
#endif
} else if (op <= RT_BINARY_OP_POWER) {
mp_obj_int_t *res = mp_obj_int_new_mpz();