summaryrefslogtreecommitdiff
path: root/py/objfloat.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2014-02-22 18:12:43 +0000
committerDamien George <damien.p.george@gmail.com>2014-02-22 18:12:43 +0000
commit20773971186151b53426bd607908546598036a16 (patch)
treec74ee3ac2f07061a820355bac0bea075e0177fa8 /py/objfloat.c
parent2613ffde431594f3fe0562042c32105623fbe4dc (diff)
py: Put number parsing code together in parsenum.c.
Diffstat (limited to 'py/objfloat.c')
-rw-r--r--py/objfloat.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/py/objfloat.c b/py/objfloat.c
index 9d7b79689..268bc2bde 100644
--- a/py/objfloat.c
+++ b/py/objfloat.c
@@ -8,6 +8,7 @@
#include "mpconfig.h"
#include "qstr.h"
#include "obj.h"
+#include "parsenum.h"
#include "runtime0.h"
#if MICROPY_ENABLE_FLOAT
@@ -32,8 +33,12 @@ STATIC mp_obj_t float_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const m
return mp_obj_new_float(0);
case 1:
- // TODO allow string as arg and parse it
- if (MP_OBJ_IS_TYPE(args[0], &float_type)) {
+ if (MP_OBJ_IS_STR(args[0])) {
+ // a string, parse it
+ uint l;
+ const char *s = mp_obj_str_get_data(args[0], &l);
+ return mp_parse_num_decimal(s, l);
+ } else if (MP_OBJ_IS_TYPE(args[0], &float_type)) {
return args[0];
} else {
return mp_obj_new_float(mp_obj_get_float(args[0]));