36 #if MICROPY_PY_BUILTINS_FLOAT 40 #if MICROPY_LONGINT_IMPL == MICROPY_LONGINT_IMPL_MPZ 42 #if MICROPY_PY_SYS_MAXSIZE 44 #define DIG_MASK ((MPZ_LONG_1 << MPZ_DIG_SIZE) - 1) 61 #error cannot encode MP_SSIZE_MAX as mpz 69 {.fixed_dig = 1, .len = NUM_DIG, .alloc = NUM_DIG, .dig = (
mpz_dig_t*)maxsize_dig}
92 int base,
const char *prefix,
char base_char,
char comma) {
96 size_t needed_size =
mp_int_format_size(mpz_max_num_bits(&self->mpz), base, prefix, comma);
97 if (needed_size > *buf_size) {
98 *buf =
m_new(
char, needed_size);
99 *buf_size = needed_size;
103 *fmt_size =
mpz_as_str_inpl(&self->mpz, base, prefix, base_char, comma, str);
122 if (MP_OBJ_IS_SMALL_INT(self_in)) {
126 }
else if (val > 0) {
133 if (self->mpz.len == 0) {
135 }
else if (self->mpz.neg == 0) {
152 if (self->mpz.neg == 0) {
170 if (MP_OBJ_IS_SMALL_INT(lhs_in)) {
181 if (MP_OBJ_IS_SMALL_INT(rhs_in)) {
186 #if MICROPY_PY_BUILTINS_FLOAT 188 return mp_obj_float_binary_op(op, mpz_as_float(zlhs), rhs_in);
189 #if MICROPY_PY_BUILTINS_COMPLEX 191 return mp_obj_complex_binary_op(op, mpz_as_float(zlhs), 0, rhs_in);
200 #if MICROPY_PY_BUILTINS_FLOAT 202 if (mpz_is_zero(zrhs)) {
203 goto zero_division_error;
205 mp_float_t flhs = mpz_as_float(zlhs);
206 mp_float_t frhs = mpz_as_float(zrhs);
207 return mp_obj_new_float(flhs / frhs);
228 if (mpz_is_zero(zrhs)) {
239 if (mpz_is_zero(zrhs)) {
240 goto zero_division_error;
279 if (mpz_is_neg(zrhs)) {
280 #if MICROPY_PY_BUILTINS_FLOAT 281 return mp_obj_float_binary_op(op, mpz_as_float(zlhs), rhs_in);
291 if (mpz_is_zero(zrhs)) {
292 goto zero_division_error;
307 return mp_obj_new_bool(cmp < 0);
309 return mp_obj_new_bool(cmp > 0);
311 return mp_obj_new_bool(cmp <= 0);
313 return mp_obj_new_bool(cmp >= 0);
315 return mp_obj_new_bool(cmp == 0);
323 #if MICROPY_PY_BUILTINS_POW3 325 if (MP_OBJ_IS_SMALL_INT(arg)) {
330 return &(arp_p->mpz);
341 mpz_t l_temp, r_temp, m_temp;
342 mpz_t *lhs = mp_mpz_for_int(base, &l_temp);
343 mpz_t *rhs = mp_mpz_for_int(exponent, &r_temp);
344 mpz_t *mod = mp_mpz_for_int(modulus, &m_temp);
392 if (MP_OBJ_IS_SMALL_INT(self_in)) {
402 if (MP_OBJ_IS_SMALL_INT(self_in)) {
416 #if MICROPY_PY_BUILTINS_FLOAT 417 mp_float_t mp_obj_int_as_float_impl(
mp_obj_t self_in) {
420 return mpz_as_float(&self->mpz);
void mpz_deinit(mpz_t *z)
void mpz_init_zero(mpz_t *z)
void mpz_xor_inpl(mpz_t *dest, const mpz_t *lhs, const mpz_t *rhs)
NORETURN void mp_raise_msg(const mp_obj_type_t *exc_type, const char *msg)
void * memset(void *b, int c, size_t len)
int mp_obj_int_sign(mp_obj_t self_in)
mp_obj_t mp_obj_new_tuple(size_t n, const mp_obj_t *items)
mp_obj_t mp_obj_new_int_from_uint(mp_uint_t value)
const mp_obj_type_t mp_type_ZeroDivisionError
void mpz_set_from_ll(mpz_t *z, long long val, bool is_signed)
#define MP_OBJ_IS_TYPE(o, t)
void mpz_set_from_bytes(mpz_t *z, bool big_endian, size_t len, const byte *buf)
void mpz_mul_inpl(mpz_t *dest, const mpz_t *lhs, const mpz_t *rhs)
mp_obj_t mp_obj_int_binary_op_extra_cases(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs_in)
size_t mpz_set_from_str(mpz_t *z, const char *str, size_t len, bool neg, unsigned int base)
void mpz_add_inpl(mpz_t *dest, const mpz_t *lhs, const mpz_t *rhs)
#define MP_OBJ_FROM_PTR(p)
void mpz_pow3_inpl(mpz_t *dest, const mpz_t *lhs, const mpz_t *rhs, const mpz_t *mod)
mp_obj_t mp_obj_int_unary_op(mp_unary_op_t op, mp_obj_t o_in)
mp_obj_t mp_obj_new_int(mp_int_t value)
#define MP_OBJ_SMALL_INT_VALUE(o)
#define mp_obj_is_float(o)
size_t mp_int_format_size(size_t num_bits, int base, const char *prefix, char comma)
mp_int_t mpz_hash(const mpz_t *z)
void mpz_as_bytes(const mpz_t *z, bool big_endian, size_t len, byte *buf)
void mpz_init_from_int(mpz_t *z, mp_int_t val)
const mp_obj_type_t mp_type_complex
#define MP_OBJ_NEW_SMALL_INT(small_int)
void mpz_shr_inpl(mpz_t *dest, const mpz_t *lhs, mp_uint_t rhs)
mp_int_t mp_obj_int_get_truncated(mp_const_obj_t self_in)
void mpz_and_inpl(mpz_t *dest, const mpz_t *lhs, const mpz_t *rhs)
#define MP_SMALL_INT_FITS(n)
void mpz_neg_inpl(mpz_t *dest, const mpz_t *z)
mp_obj_t mp_obj_int_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs_in)
void mpz_sub_inpl(mpz_t *dest, const mpz_t *lhs, const mpz_t *rhs)
mp_obj_t mp_obj_new_int_from_ull(unsigned long long val)
void mpz_pow_inpl(mpz_t *dest, const mpz_t *lhs, const mpz_t *rhs)
void mpz_abs_inpl(mpz_t *dest, const mpz_t *z)
mp_int_t mp_obj_int_get_checked(mp_const_obj_t self_in)
char * mp_obj_int_formatted_impl(char **buf, size_t *buf_size, size_t *fmt_size, mp_const_obj_t self_in, int base, const char *prefix, char base_char, char comma)
int mpz_cmp(const mpz_t *z1, const mpz_t *z2)
NORETURN void mp_raise_ValueError(const char *msg)
mp_obj_int_t * mp_obj_int_new_mpz(void)
mp_obj_t mp_obj_new_int_from_str_len(const char **str, size_t len, bool neg, unsigned int base)
mp_obj_t mp_obj_int_from_bytes_impl(bool big_endian, size_t len, const byte *buf)
void mpz_shl_inpl(mpz_t *dest, const mpz_t *lhs, mp_uint_t rhs)
void mpz_or_inpl(mpz_t *dest, const mpz_t *lhs, const mpz_t *rhs)
void mpz_init_fixed_from_int(mpz_t *z, mpz_dig_t *dig, size_t alloc, mp_int_t val)
bool mpz_as_int_checked(const mpz_t *i, mp_int_t *value)
const mp_obj_int_t mp_maxsize_obj
mp_obj_t mp_obj_new_int_from_ll(long long val)
#define MPZ_NUM_DIG_FOR_INT
void mp_obj_int_to_bytes_impl(mp_obj_t self_in, bool big_endian, size_t len, byte *buf)
const mp_obj_type_t mp_type_int
NORETURN void mp_raise_TypeError(const char *msg)
#define MP_SMALL_INT_POSITIVE_MASK
size_t mpz_as_str_inpl(const mpz_t *i, unsigned int base, const char *prefix, char base_char, char comma, char *str)
const mp_obj_type_t mp_type_OverflowError
void mpz_not_inpl(mpz_t *dest, const mpz_t *z)
void mpz_divmod_inpl(mpz_t *dest_quo, mpz_t *dest_rem, const mpz_t *lhs, const mpz_t *rhs)
mp_obj_t mp_obj_int_pow3(mp_obj_t base, mp_obj_t exponent, mp_obj_t modulus)