Numworks Epsilon  1.4.1
Graphing Calculator Operating System
objint.c
Go to the documentation of this file.
1 /*
2  * This file is part of the MicroPython project, http://micropython.org/
3  *
4  * The MIT License (MIT)
5  *
6  * Copyright (c) 2013, 2014 Damien P. George
7  *
8  * Permission is hereby granted, free of charge, to any person obtaining a copy
9  * of this software and associated documentation files (the "Software"), to deal
10  * in the Software without restriction, including without limitation the rights
11  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12  * copies of the Software, and to permit persons to whom the Software is
13  * furnished to do so, subject to the following conditions:
14  *
15  * The above copyright notice and this permission notice shall be included in
16  * all copies or substantial portions of the Software.
17  *
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24  * THE SOFTWARE.
25  */
26 
27 #include <stdlib.h>
28 #include <assert.h>
29 #include <string.h>
30 
31 #include "py/parsenum.h"
32 #include "py/smallint.h"
33 #include "py/objint.h"
34 #include "py/objstr.h"
35 #include "py/runtime.h"
36 #include "py/binary.h"
37 
38 #if MICROPY_PY_BUILTINS_FLOAT
39 #include <math.h>
40 #endif
41 
42 // This dispatcher function is expected to be independent of the implementation of long int
43 STATIC mp_obj_t mp_obj_int_make_new(const mp_obj_type_t *type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) {
44  (void)type_in;
45  mp_arg_check_num(n_args, n_kw, 0, 2, false);
46 
47  switch (n_args) {
48  case 0:
49  return MP_OBJ_NEW_SMALL_INT(0);
50 
51  case 1:
52  if (MP_OBJ_IS_INT(args[0])) {
53  // already an int (small or long), just return it
54  return args[0];
55  } else if (MP_OBJ_IS_STR_OR_BYTES(args[0])) {
56  // a string, parse it
57  size_t l;
58  const char *s = mp_obj_str_get_data(args[0], &l);
59  return mp_parse_num_integer(s, l, 0, NULL);
60 #if MICROPY_PY_BUILTINS_FLOAT
61  } else if (mp_obj_is_float(args[0])) {
62  return mp_obj_new_int_from_float(mp_obj_float_get(args[0]));
63 #endif
64  } else {
65  // try to convert to small int (eg from bool)
67  }
68 
69  case 2:
70  default: {
71  // should be a string, parse it
72  // TODO proper error checking of argument types
73  size_t l;
74  const char *s = mp_obj_str_get_data(args[0], &l);
75  return mp_parse_num_integer(s, l, mp_obj_get_int(args[1]), NULL);
76  }
77  }
78 }
79 
80 #if MICROPY_PY_BUILTINS_FLOAT
81 
82 typedef enum {
83  MP_FP_CLASS_FIT_SMALLINT,
84  MP_FP_CLASS_FIT_LONGINT,
85  MP_FP_CLASS_OVERFLOW
86 } mp_fp_as_int_class_t;
87 
88 STATIC mp_fp_as_int_class_t mp_classify_fp_as_int(mp_float_t val) {
89  union {
90  mp_float_t f;
91 #if MICROPY_FLOAT_IMPL == MICROPY_FLOAT_IMPL_FLOAT
92  uint32_t i;
93 #elif MICROPY_FLOAT_IMPL == MICROPY_FLOAT_IMPL_DOUBLE
94  uint32_t i[2];
95 #endif
96  } u = {val};
97 
98  uint32_t e;
99 #if MICROPY_FLOAT_IMPL == MICROPY_FLOAT_IMPL_FLOAT
100  e = u.i;
101 #elif MICROPY_FLOAT_IMPL == MICROPY_FLOAT_IMPL_DOUBLE
102  e = u.i[MP_ENDIANNESS_LITTLE];
103 #endif
104 #define MP_FLOAT_SIGN_SHIFT_I32 ((MP_FLOAT_FRAC_BITS + MP_FLOAT_EXP_BITS) % 32)
105 #define MP_FLOAT_EXP_SHIFT_I32 (MP_FLOAT_FRAC_BITS % 32)
106 
107  if (e & (1U << MP_FLOAT_SIGN_SHIFT_I32)) {
108 #if MICROPY_FLOAT_IMPL == MICROPY_FLOAT_IMPL_DOUBLE
109  e |= u.i[MP_ENDIANNESS_BIG] != 0;
110 #endif
111  if ((e & ~(1 << MP_FLOAT_SIGN_SHIFT_I32)) == 0) {
112  // handle case of -0 (when sign is set but rest of bits are zero)
113  e = 0;
114  } else {
115  e += ((1 << MP_FLOAT_EXP_BITS) - 1) << MP_FLOAT_EXP_SHIFT_I32;
116  }
117  } else {
118  e &= ~((1 << MP_FLOAT_EXP_SHIFT_I32) - 1);
119  }
120  // 8 * sizeof(uintptr_t) counts the number of bits for a small int
121  // TODO provide a way to configure this properly
122  if (e <= ((8 * sizeof(uintptr_t) + MP_FLOAT_EXP_BIAS - 3) << MP_FLOAT_EXP_SHIFT_I32)) {
123  return MP_FP_CLASS_FIT_SMALLINT;
124  }
125 #if MICROPY_LONGINT_IMPL == MICROPY_LONGINT_IMPL_LONGLONG
126  if (e <= (((sizeof(long long) * BITS_PER_BYTE) + MP_FLOAT_EXP_BIAS - 2) << MP_FLOAT_EXP_SHIFT_I32)) {
127  return MP_FP_CLASS_FIT_LONGINT;
128  }
129 #endif
130 #if MICROPY_LONGINT_IMPL == MICROPY_LONGINT_IMPL_MPZ
131  return MP_FP_CLASS_FIT_LONGINT;
132 #else
133  return MP_FP_CLASS_OVERFLOW;
134 #endif
135 }
136 #undef MP_FLOAT_SIGN_SHIFT_I32
137 #undef MP_FLOAT_EXP_SHIFT_I32
138 
139 mp_obj_t mp_obj_new_int_from_float(mp_float_t val) {
140  int cl = fpclassify(val);
141  if (cl == FP_INFINITE) {
142  nlr_raise(mp_obj_new_exception_msg(&mp_type_OverflowError, "can't convert inf to int"));
143  } else if (cl == FP_NAN) {
144  mp_raise_ValueError("can't convert NaN to int");
145  } else {
146  mp_fp_as_int_class_t icl = mp_classify_fp_as_int(val);
147  if (icl == MP_FP_CLASS_FIT_SMALLINT) {
148  return MP_OBJ_NEW_SMALL_INT((mp_int_t)val);
149  #if MICROPY_LONGINT_IMPL == MICROPY_LONGINT_IMPL_MPZ
150  } else {
152  mpz_set_from_float(&o->mpz, val);
153  return MP_OBJ_FROM_PTR(o);
154  }
155  #else
156  #if MICROPY_LONGINT_IMPL == MICROPY_LONGINT_IMPL_LONGLONG
157  } else if (icl == MP_FP_CLASS_FIT_LONGINT) {
158  return mp_obj_new_int_from_ll((long long)val);
159  #endif
160  } else {
161  mp_raise_ValueError("float too big");
162  }
163  #endif
164  }
165 }
166 
167 #endif
168 
169 #if MICROPY_LONGINT_IMPL == MICROPY_LONGINT_IMPL_LONGLONG
170 typedef mp_longint_impl_t fmt_int_t;
171 typedef unsigned long long fmt_uint_t;
172 #else
173 typedef mp_int_t fmt_int_t;
174 typedef mp_uint_t fmt_uint_t;
175 #endif
176 
177 void mp_obj_int_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
178  (void)kind;
179  // The size of this buffer is rather arbitrary. If it's not large
180  // enough, a dynamic one will be allocated.
181  char stack_buf[sizeof(fmt_int_t) * 4];
182  char *buf = stack_buf;
183  size_t buf_size = sizeof(stack_buf);
184  size_t fmt_size;
185 
186  char *str = mp_obj_int_formatted(&buf, &buf_size, &fmt_size, self_in, 10, NULL, '\0', '\0');
187  mp_print_str(print, str);
188 
189  if (buf != stack_buf) {
190  m_del(char, buf, buf_size);
191  }
192 }
193 
195  0, 1, 1, 2,
196  2, 2, 2, 3,
197  3, 3, 3, 3,
198  3, 3, 3, 4,
199  /* if needed, these are the values for higher bases
200  4, 4, 4, 4,
201  4, 4, 4, 4,
202  4, 4, 4, 4,
203  4, 4, 4, 5
204  */
205 };
206 
207 size_t mp_int_format_size(size_t num_bits, int base, const char *prefix, char comma) {
208  assert(2 <= base && base <= 16);
209  size_t num_digits = num_bits / log_base2_floor[base - 1] + 1;
210  size_t num_commas = comma ? num_digits / 3 : 0;
211  size_t prefix_len = prefix ? strlen(prefix) : 0;
212  return num_digits + num_commas + prefix_len + 2; // +1 for sign, +1 for null byte
213 }
214 
215 // This routine expects you to pass in a buffer and size (in *buf and *buf_size).
216 // If, for some reason, this buffer is too small, then it will allocate a
217 // buffer and return the allocated buffer and size in *buf and *buf_size. It
218 // is the callers responsibility to free this allocated buffer.
219 //
220 // The resulting formatted string will be returned from this function and the
221 // formatted size will be in *fmt_size.
222 char *mp_obj_int_formatted(char **buf, size_t *buf_size, size_t *fmt_size, mp_const_obj_t self_in,
223  int base, const char *prefix, char base_char, char comma) {
224  fmt_int_t num;
225  if (MP_OBJ_IS_SMALL_INT(self_in)) {
226  // A small int; get the integer value to format.
227  num = MP_OBJ_SMALL_INT_VALUE(self_in);
228 #if MICROPY_LONGINT_IMPL != MICROPY_LONGINT_IMPL_NONE
229  } else if (MP_OBJ_IS_TYPE(self_in, &mp_type_int)) {
230  // Not a small int.
231 #if MICROPY_LONGINT_IMPL == MICROPY_LONGINT_IMPL_LONGLONG
232  const mp_obj_int_t *self = self_in;
233  // Get the value to format; mp_obj_get_int truncates to mp_int_t.
234  num = self->val;
235 #else
236  // Delegate to the implementation for the long int.
237  return mp_obj_int_formatted_impl(buf, buf_size, fmt_size, self_in, base, prefix, base_char, comma);
238 #endif
239 #endif
240  } else {
241  // Not an int.
242  **buf = '\0';
243  *fmt_size = 0;
244  return *buf;
245  }
246 
247  char sign = '\0';
248  if (num < 0) {
249  num = -num;
250  sign = '-';
251  }
252 
253  size_t needed_size = mp_int_format_size(sizeof(fmt_int_t) * 8, base, prefix, comma);
254  if (needed_size > *buf_size) {
255  *buf = m_new(char, needed_size);
256  *buf_size = needed_size;
257  }
258  char *str = *buf;
259 
260  char *b = str + needed_size;
261  *(--b) = '\0';
262  char *last_comma = b;
263 
264  if (num == 0) {
265  *(--b) = '0';
266  } else {
267  do {
268  // The cast to fmt_uint_t is because num is positive and we want unsigned arithmetic
269  int c = (fmt_uint_t)num % base;
270  num = (fmt_uint_t)num / base;
271  if (c >= 10) {
272  c += base_char - 10;
273  } else {
274  c += '0';
275  }
276  *(--b) = c;
277  if (comma && num != 0 && b > str && (last_comma - b) == 3) {
278  *(--b) = comma;
279  last_comma = b;
280  }
281  }
282  while (b > str && num != 0);
283  }
284  if (prefix) {
285  size_t prefix_len = strlen(prefix);
286  char *p = b - prefix_len;
287  if (p > str) {
288  b = p;
289  while (*prefix) {
290  *p++ = *prefix++;
291  }
292  }
293  }
294  if (sign && b > str) {
295  *(--b) = sign;
296  }
297  *fmt_size = *buf + needed_size - b - 1;
298 
299  return b;
300 }
301 
302 #if MICROPY_LONGINT_IMPL == MICROPY_LONGINT_IMPL_NONE
303 
304 int mp_obj_int_sign(mp_obj_t self_in) {
305  mp_int_t val = mp_obj_get_int(self_in);
306  if (val < 0) {
307  return -1;
308  } else if (val > 0) {
309  return 1;
310  } else {
311  return 0;
312  }
313 }
314 
315 // This is called for operations on SMALL_INT that are not handled by mp_unary_op
317  return MP_OBJ_NULL; // op not supported
318 }
319 
320 // This is called for operations on SMALL_INT that are not handled by mp_binary_op
322  return mp_obj_int_binary_op_extra_cases(op, lhs_in, rhs_in);
323 }
324 
325 // This is called only with strings whose value doesn't fit in SMALL_INT
326 mp_obj_t mp_obj_new_int_from_str_len(const char **str, size_t len, bool neg, unsigned int base) {
327  mp_raise_msg(&mp_type_OverflowError, "long int not supported in this build");
328  return mp_const_none;
329 }
330 
331 // This is called when an integer larger than a SMALL_INT is needed (although val might still fit in a SMALL_INT)
333  mp_raise_msg(&mp_type_OverflowError, "small int overflow");
334  return mp_const_none;
335 }
336 
337 // This is called when an integer larger than a SMALL_INT is needed (although val might still fit in a SMALL_INT)
338 mp_obj_t mp_obj_new_int_from_ull(unsigned long long val) {
339  mp_raise_msg(&mp_type_OverflowError, "small int overflow");
340  return mp_const_none;
341 }
342 
344  // SMALL_INT accepts only signed numbers, so make sure the input
345  // value fits completely in the small-int positive range.
346  if ((value & ~MP_SMALL_INT_POSITIVE_MASK) == 0) {
347  return MP_OBJ_NEW_SMALL_INT(value);
348  }
349  mp_raise_msg(&mp_type_OverflowError, "small int overflow");
350  return mp_const_none;
351 }
352 
354  if (MP_SMALL_INT_FITS(value)) {
355  return MP_OBJ_NEW_SMALL_INT(value);
356  }
357  mp_raise_msg(&mp_type_OverflowError, "small int overflow");
358  return mp_const_none;
359 }
360 
362  return MP_OBJ_SMALL_INT_VALUE(self_in);
363 }
364 
366  return MP_OBJ_SMALL_INT_VALUE(self_in);
367 }
368 
369 #endif // MICROPY_LONGINT_IMPL == MICROPY_LONGINT_IMPL_NONE
370 
371 // This dispatcher function is expected to be independent of the implementation of long int
372 // It handles the extra cases for integer-like arithmetic
374  if (rhs_in == mp_const_false) {
375  // false acts as 0
376  return mp_binary_op(op, lhs_in, MP_OBJ_NEW_SMALL_INT(0));
377  } else if (rhs_in == mp_const_true) {
378  // true acts as 0
379  return mp_binary_op(op, lhs_in, MP_OBJ_NEW_SMALL_INT(1));
380  } else if (op == MP_BINARY_OP_MULTIPLY) {
381  if (MP_OBJ_IS_STR(rhs_in) || MP_OBJ_IS_TYPE(rhs_in, &mp_type_bytes) || MP_OBJ_IS_TYPE(rhs_in, &mp_type_tuple) || MP_OBJ_IS_TYPE(rhs_in, &mp_type_list)) {
382  // multiply is commutative for these types, so delegate to them
383  return mp_binary_op(op, rhs_in, lhs_in);
384  }
385  }
386  return MP_OBJ_NULL; // op not supported
387 }
388 
389 // this is a classmethod
390 STATIC mp_obj_t int_from_bytes(size_t n_args, const mp_obj_t *args) {
391  // TODO: Support signed param (assumes signed=False at the moment)
392  (void)n_args;
393 
394  // get the buffer info
395  mp_buffer_info_t bufinfo;
396  mp_get_buffer_raise(args[1], &bufinfo, MP_BUFFER_READ);
397 
398  const byte* buf = (const byte*)bufinfo.buf;
399  int delta = 1;
400  if (args[2] == MP_OBJ_NEW_QSTR(MP_QSTR_little)) {
401  buf += bufinfo.len - 1;
402  delta = -1;
403  }
404 
405  mp_uint_t value = 0;
406  size_t len = bufinfo.len;
407  for (; len--; buf += delta) {
408  #if MICROPY_LONGINT_IMPL != MICROPY_LONGINT_IMPL_NONE
409  if (value > (MP_SMALL_INT_MAX >> 8)) {
410  // Result will overflow a small-int so construct a big-int
411  return mp_obj_int_from_bytes_impl(args[2] != MP_OBJ_NEW_QSTR(MP_QSTR_little), bufinfo.len, bufinfo.buf);
412  }
413  #endif
414  value = (value << 8) | *buf;
415  }
416  return mp_obj_new_int_from_uint(value);
417 }
418 
419 STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(int_from_bytes_fun_obj, 3, 4, int_from_bytes);
420 STATIC MP_DEFINE_CONST_CLASSMETHOD_OBJ(int_from_bytes_obj, MP_ROM_PTR(&int_from_bytes_fun_obj));
421 
422 STATIC mp_obj_t int_to_bytes(size_t n_args, const mp_obj_t *args) {
423  // TODO: Support signed param (assumes signed=False)
424  (void)n_args;
425 
426  mp_int_t len = mp_obj_get_int(args[1]);
427  if (len < 0) {
429  }
430  bool big_endian = args[2] != MP_OBJ_NEW_QSTR(MP_QSTR_little);
431 
432  vstr_t vstr;
433  vstr_init_len(&vstr, len);
434  byte *data = (byte*)vstr.buf;
435  memset(data, 0, len);
436 
437  #if MICROPY_LONGINT_IMPL != MICROPY_LONGINT_IMPL_NONE
438  if (!MP_OBJ_IS_SMALL_INT(args[0])) {
439  mp_obj_int_to_bytes_impl(args[0], big_endian, len, data);
440  } else
441  #endif
442  {
444  size_t l = MIN((size_t)len, sizeof(val));
445  mp_binary_set_int(l, big_endian, data + (big_endian ? (len - l) : 0), val);
446  }
447 
448  return mp_obj_new_str_from_vstr(&mp_type_bytes, &vstr);
449 }
451 
453  { MP_ROM_QSTR(MP_QSTR_from_bytes), MP_ROM_PTR(&int_from_bytes_obj) },
454  { MP_ROM_QSTR(MP_QSTR_to_bytes), MP_ROM_PTR(&int_to_bytes_obj) },
455 };
456 
458 
460  { &mp_type_type },
461  .name = MP_QSTR_int,
462  .print = mp_obj_int_print,
463  .make_new = mp_obj_int_make_new,
464  .unary_op = mp_obj_int_unary_op,
465  .binary_op = mp_obj_int_binary_op,
466  .locals_dict = (mp_obj_dict_t*)&int_locals_dict,
467 };
intptr_t mp_int_t
Definition: mpconfigport.h:73
STATIC const mp_rom_map_elem_t int_locals_dict_table[]
Definition: objint.c:452
uintptr_t mp_uint_t
Definition: mpconfigport.h:74
#define MP_SMALL_INT_MAX
Definition: smallint.h:62
NORETURN void mp_raise_msg(const mp_obj_type_t *exc_type, const char *msg)
Definition: runtime.c:1448
Definition: misc.h:142
#define MP_BUFFER_READ
Definition: obj.h:454
void * memset(void *b, int c, size_t len)
Definition: memset.c:3
#define assert(e)
Definition: assert.h:9
#define mp_const_none
Definition: obj.h:614
STATIC MP_DEFINE_CONST_CLASSMETHOD_OBJ(int_from_bytes_obj, MP_ROM_PTR(&int_from_bytes_fun_obj))
#define MIN(x, y)
Definition: table_view.cpp:8
STATIC mp_obj_t int_to_bytes(size_t n_args, const mp_obj_t *args)
Definition: objint.c:422
def data
Definition: i18n.py:176
mp_obj_t mp_obj_int_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs_in)
Definition: objint.c:321
#define MP_OBJ_IS_TYPE(o, t)
Definition: obj.h:254
#define m_del(type, ptr, num)
Definition: misc.h:77
#define FP_INFINITE
Definition: math.h:32
void vstr_init_len(vstr_t *vstr, size_t len)
Definition: vstr.c:52
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)
Definition: objint.c:373
char * buf
Definition: misc.h:145
#define U()
Definition: events.cpp:25
int mp_print_str(const mp_print_t *print, const char *str)
Definition: mpprint.c:53
mp_longint_impl_t val
Definition: objint.h:35
#define MP_ROM_QSTR(q)
Definition: obj.h:241
unsigned int uintptr_t
Definition: stdint.h:14
#define MP_OBJ_FROM_PTR(p)
Definition: obj.h:233
#define MP_OBJ_NEW_QSTR(qst)
Definition: obj.h:92
void mp_arg_check_num(size_t n_args, size_t n_kw, size_t n_args_min, size_t n_args_max, bool takes_kw)
Definition: argcheck.c:32
#define MP_ROM_PTR(p)
Definition: obj.h:242
mp_int_t mp_obj_int_get_checked(mp_const_obj_t self_in)
Definition: objint.c:365
#define mp_const_true
Definition: obj.h:616
const mp_obj_type_t mp_type_int
Definition: objint.c:459
const mp_obj_type_t mp_type_bytes
Definition: objstr.c:1964
size_t len
Definition: obj.h:447
STATIC mp_obj_t mp_obj_int_make_new(const mp_obj_type_t *type_in, size_t n_args, size_t n_kw, const mp_obj_t *args)
Definition: objint.c:43
unsigned char uint8_t
Definition: stdint.h:4
mp_unary_op_t
Definition: runtime0.h:45
mp_int_t mp_obj_get_int(mp_const_obj_t arg)
Definition: obj.c:225
#define STATIC
Definition: mpconfig.h:1178
mp_obj_t mp_obj_int_unary_op(mp_unary_op_t op, mp_obj_t o_in)
Definition: objint.c:316
#define MP_OBJ_SMALL_INT_VALUE(o)
Definition: obj.h:86
#define fpclassify(x)
Definition: math.h:38
mp_obj_t mp_obj_new_int_from_ull(unsigned long long val)
Definition: objint.c:338
#define mp_obj_is_float(o)
Definition: obj.h:745
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(int_from_bytes_fun_obj, 3, 4, int_from_bytes)
size_t mp_int_format_size(size_t num_bits, int base, const char *prefix, char comma)
Definition: objint.c:207
char * mp_obj_int_formatted(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)
Definition: objint.c:222
mp_obj_t mp_obj_new_exception_msg(const mp_obj_type_t *exc_type, const char *msg)
Definition: objexcept.c:343
c(generic_all_nodes)
mp_print_kind_t
Definition: obj.h:412
#define MP_OBJ_NEW_SMALL_INT(small_int)
Definition: obj.h:87
size_t strlen(const char *s)
Definition: strlen.c:3
STATIC mp_obj_t int_from_bytes(size_t n_args, const mp_obj_t *args)
Definition: objint.c:390
const char * mp_obj_str_get_data(mp_obj_t self_in, size_t *len)
Definition: objstr.c:2105
uint64_t mp_const_obj_t
Definition: obj.h:40
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)
Definition: objint_mpz.c:91
unsigned int uint32_t
Definition: stdint.h:6
#define NULL
Definition: stddef.h:4
#define MP_OBJ_NULL
Definition: obj.h:73
STATIC const uint8_t log_base2_floor[]
Definition: objint.c:194
mp_longint_impl_t fmt_int_t
Definition: objint.c:170
mp_obj_t mp_obj_new_int_from_str_len(const char **str, size_t len, bool neg, unsigned int base)
Definition: objint.c:326
#define MP_SMALL_INT_FITS(n)
Definition: smallint.h:40
mp_obj_t mp_obj_new_int_from_ll(long long val)
Definition: objint.c:332
mp_int_t mp_obj_int_get_truncated(mp_const_obj_t self_in)
Definition: objint.c:361
mp_obj_t mp_obj_new_int(mp_int_t value)
Definition: objint.c:353
mp_binary_op_t
Definition: runtime0.h:67
mp_obj_t mp_binary_op(mp_binary_op_t op, mp_obj_t lhs, mp_obj_t rhs)
Definition: runtime.c:277
int mp_obj_int_sign(mp_obj_t self_in)
Definition: objint.c:304
args
Definition: i18n.py:175
mp_obj_t mp_obj_new_int_from_uint(mp_uint_t value)
Definition: objint.c:343
mp_obj_t mp_obj_int_from_bytes_impl(bool big_endian, size_t len, const byte *buf)
#define MP_OBJ_IS_INT(o)
Definition: obj.h:255
unsigned char byte
Definition: misc.h:37
mp_obj_t mp_obj_new_str_from_vstr(const mp_obj_type_t *type, vstr_t *vstr)
Definition: objstr.c:1998
const mp_obj_type_t mp_type_type
Definition: objtype.c:969
unsigned long long fmt_uint_t
Definition: objint.c:171
NORETURN void mp_raise_ValueError(const char *msg)
Definition: runtime.c:1456
STATIC MP_DEFINE_CONST_DICT(int_locals_dict, int_locals_dict_table)
void mp_get_buffer_raise(mp_obj_t obj, mp_buffer_info_t *bufinfo, mp_uint_t flags)
Definition: obj.c:524
#define FP_NAN
Definition: math.h:33
const mp_obj_type_t mp_type_tuple
Definition: objtuple.c:220
#define MP_ENDIANNESS_BIG
Definition: mpconfig.h:1221
void mp_binary_set_int(mp_uint_t val_sz, bool big_endian, byte *dest, mp_uint_t val)
Definition: binary.c:233
mp_obj_int_t * mp_obj_int_new_mpz(void)
Definition: objint_mpz.c:75
#define nlr_raise(val)
Definition: nlr.h:89
mp_obj_t mp_parse_num_integer(const char *restrict str_, size_t len, int base, mp_lexer_t *lex)
Definition: parsenum.c:49
void mp_obj_int_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind)
Definition: objint.c:177
qstr name
Definition: obj.h:478
#define BITS_PER_BYTE
Definition: mpconfig.h:1186
uint64_t mp_obj_t
Definition: obj.h:39
#define MP_OBJ_IS_STR(o)
Definition: obj.h:256
void mp_obj_int_to_bytes_impl(mp_obj_t self_in, bool big_endian, size_t len, byte *buf)
#define MP_OBJ_IS_STR_OR_BYTES(o)
Definition: obj.h:257
#define MP_SMALL_INT_POSITIVE_MASK
Definition: smallint.h:42
const mp_obj_type_t mp_type_list
Definition: objlist.c:444
void * buf
Definition: obj.h:446
const mp_obj_type_t mp_type_OverflowError
#define m_new(type, num)
Definition: misc.h:57
#define mp_const_false
Definition: obj.h:615