diff options
author | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2014-12-31 02:20:57 +0200 |
---|---|---|
committer | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2014-12-31 02:21:19 +0200 |
commit | 2c75665445b555d0bf712566e7d8874e57c5ad81 (patch) | |
tree | ee9c4193b35cd6909af7b5414909e2ae5862aa49 | |
parent | 8a2cc1c7e4c08aa83dc05a3b472caf1e71972d22 (diff) | |
download | micropython-2c75665445b555d0bf712566e7d8874e57c5ad81.tar.gz micropython-2c75665445b555d0bf712566e7d8874e57c5ad81.zip |
objstr: Fix %d-formatting of floats.
-rw-r--r-- | py/objstr.c | 6 | ||||
-rw-r--r-- | tests/float/float2int.py | 5 |
2 files changed, 6 insertions, 5 deletions
diff --git a/py/objstr.c b/py/objstr.c index 16ee2ea1dd..3d9fd6f5e8 100644 --- a/py/objstr.c +++ b/py/objstr.c @@ -827,11 +827,7 @@ static bool arg_looks_numeric(mp_obj_t arg) { static mp_obj_t arg_as_int(mp_obj_t arg) { #if MICROPY_PY_BUILTINS_FLOAT if (MP_OBJ_IS_TYPE(arg, &mp_type_float)) { - - // TODO: Needs a way to construct an mpz integer from a float - - mp_int_t num = mp_obj_get_float(arg); - return MP_OBJ_NEW_SMALL_INT(num); + return mp_obj_new_int_from_float(mp_obj_get_float(arg)); } #endif return arg; diff --git a/tests/float/float2int.py b/tests/float/float2int.py index 59d904e58a..ca2914c01a 100644 --- a/tests/float/float2int.py +++ b/tests/float/float2int.py @@ -3,3 +3,8 @@ print(int(1418774543.)) # TODO: General case with large exponent #print(int(2.**100)) + +print("%d" % 1418774543.) + +# TODO: General case with large exponent +#print("%d" % 2.**100) |