35 #if MICROPY_PY_BUILTINS_FLOAT 50 const byte *restrict str = (
const byte *)str_;
51 const byte *restrict top = str + len;
56 if ((base != 0 && base < 2) || base > 36) {
69 }
else if (*str ==
'-') {
80 const byte *restrict str_val_start = str;
81 for (; str < top; str++) {
84 if (
'0' <= dig && dig <=
'9') {
88 if (
'a' <= dig && dig <=
'z') {
103 int_val = int_val * base + dig;
119 if (str == str_val_start) {
138 const char *s2 = (
const char*)str_val_start;
140 str = (
const byte*)s2;
147 "invalid syntax for integer");
151 "invalid syntax for integer with base %d", base);
157 mp_printf(&print,
"invalid syntax for integer with base %d: ", base);
172 #if MICROPY_PY_BUILTINS_FLOAT 173 const char *top = str + len;
174 mp_float_t dec_val = 0;
175 bool dec_neg =
false;
186 }
else if (*str ==
'-') {
192 const char *str_val_start = str;
195 if (str < top && (str[0] | 0x20) ==
'i') {
197 if (str + 2 < top && (str[1] | 0x20) ==
'n' && (str[2] | 0x20) ==
'f') {
201 if (str + 4 < top && (str[0] | 0x20) ==
'i' && (str[1] | 0x20) ==
'n' && (str[2] | 0x20) ==
'i' && (str[3] | 0x20) ==
't' && (str[4] | 0x20) ==
'y') {
206 }
else if (str < top && (str[0] | 0x20) ==
'n') {
208 if (str + 2 < top && (str[1] | 0x20) ==
'a' && (str[2] | 0x20) ==
'n') {
211 dec_val = MICROPY_FLOAT_C_FUN(
nan)(
"");
216 bool exp_neg =
false;
217 mp_float_t frac_mult = 0.1;
221 if (
'0' <= dig && dig <=
'9') {
224 exp_val = 10 * exp_val + dig;
227 dec_val += dig * frac_mult;
228 frac_mult *= MICROPY_FLOAT_CONST(0.1);
230 dec_val = 10 * dec_val + dig;
240 }
else if (str[0] ==
'-') {
248 }
else if (allow_imag && (dig | 0x20) ==
'j') {
264 dec_val *= MICROPY_FLOAT_C_FUN(
pow)(10, exp_val);
273 if (str == str_val_start) {
287 #if MICROPY_PY_BUILTINS_COMPLEX 289 return mp_obj_new_complex(0, dec_val);
290 }
else if (force_complex) {
291 return mp_obj_new_complex(dec_val, 0);
293 if (imag || force_complex) {
297 return mp_obj_new_float(dec_val);
#define MICROPY_ERROR_REPORTING_TERSE
mp_obj_t mp_obj_new_exception_msg_varg(const mp_obj_type_t *exc_type, const char *fmt,...)
void mp_str_print_quoted(const mp_print_t *print, const byte *str_data, size_t str_len, bool is_bytes)
bool mp_small_int_mul_overflow(mp_int_t x, mp_int_t y)
const mp_obj_type_t mp_type_SyntaxError
STATIC NORETURN void raise_exc(mp_obj_t exc, mp_lexer_t *lex)
mp_obj_t mp_obj_new_exception_msg(const mp_obj_type_t *exc_type, const char *msg)
#define MP_OBJ_NEW_SMALL_INT(small_int)
#define MICROPY_ERROR_REPORTING
bool unichar_isspace(unichar c)
#define MICROPY_ERROR_REPORTING_NORMAL
mp_obj_t mp_obj_new_exception_arg1(const mp_obj_type_t *exc_type, mp_obj_t arg)
#define MP_SMALL_INT_FITS(n)
const mp_obj_type_t mp_type_str
const mp_obj_type_t mp_type_ValueError
mp_obj_t mp_obj_new_int_from_str_len(const char **str, size_t len, bool neg, unsigned int base)
void mp_obj_exception_add_traceback(mp_obj_t self_in, qstr file, size_t line, qstr block)
mp_obj_t mp_obj_new_str_from_vstr(const mp_obj_type_t *type, vstr_t *vstr)
mp_obj_t mp_parse_num_decimal(const char *str, size_t len, bool allow_imag, bool force_complex, mp_lexer_t *lex)
NORETURN void mp_raise_ValueError(const char *msg)
mp_obj_t mp_parse_num_integer(const char *restrict str_, size_t len, int base, mp_lexer_t *lex)
int mp_printf(const mp_print_t *print, const char *fmt,...)
void vstr_init_print(vstr_t *vstr, size_t alloc, struct _mp_print_t *print)
size_t mp_parse_num_base(const char *str, size_t len, int *base)