diff options
author | Damien George <damien.p.george@gmail.com> | 2014-04-02 20:04:15 +0100 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2014-04-02 20:04:15 +0100 |
commit | c322c5f07f3a22e2c815bb9d4f3dcc5d6ace082a (patch) | |
tree | 52401b4841202e62f6b24dcbefeb32982ec41fb0 | |
parent | a05f5dd9528ba16df96d3ece581d5d0b2288b5ec (diff) | |
download | micropython-c322c5f07f3a22e2c815bb9d4f3dcc5d6ace082a.tar.gz micropython-c322c5f07f3a22e2c815bb9d4f3dcc5d6ace082a.zip |
py: Fix regress for printing of floats and #if.
Also change formating modifier in test script (it still passes with
original format though).
-rw-r--r-- | py/objstr.c | 8 | ||||
-rw-r--r-- | tests/basics/math-fun.py | 4 |
2 files changed, 6 insertions, 6 deletions
diff --git a/py/objstr.c b/py/objstr.c index f22c6b1bae..c27b19939d 100644 --- a/py/objstr.c +++ b/py/objstr.c @@ -788,9 +788,9 @@ mp_obj_t str_format(uint n_args, const mp_obj_t *args) { nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "Unknown format code '%c' for object of type '%s'", type, mp_obj_get_type_str(arg))); } + } -#if MICROPY_ENABLE_FLOAT - } else if (arg_looks_numeric(arg)) { + if (arg_looks_numeric(arg)) { if (!type) { // Even though the docs say that an unspecified type is the same @@ -828,6 +828,7 @@ mp_obj_t str_format(uint n_args, const mp_obj_t *args) { flags |= PF_FLAG_PAD_NAN_INF; // '{:06e}'.format(float('-inf')) should give '-00inf' switch (type) { +#if MICROPY_ENABLE_FLOAT case 'e': case 'E': case 'f': @@ -841,14 +842,13 @@ mp_obj_t str_format(uint n_args, const mp_obj_t *args) { flags |= PF_FLAG_ADD_PERCENT; pfenv_print_float(&pfenv_vstr, mp_obj_get_float(arg) * 100.0F, 'f', flags, fill, width, precision); break; +#endif default: nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "Unknown format code '%c' for object of type 'float'", type, mp_obj_get_type_str(arg))); } -#endif - } else { // arg doesn't look like a number diff --git a/tests/basics/math-fun.py b/tests/basics/math-fun.py index eb80ab0f54..7a37c58454 100644 --- a/tests/basics/math-fun.py +++ b/tests/basics/math-fun.py @@ -34,7 +34,7 @@ functions = [('sqrt', sqrt, p_test_values), for function_name, function, test_vals in functions: print(function_name) for value in test_vals: - print("{:8.7g}".format(function(value))) + print("{:.7g}".format(function(value))) binary_functions = [('copysign', copysign, [(23., 42.), (-23., 42.), (23., -42.), (-23., -42.), (1., 0.0), (1., -0.0)]) @@ -43,4 +43,4 @@ binary_functions = [('copysign', copysign, [(23., 42.), (-23., 42.), (23., -42.) for function_name, function, test_vals in binary_functions: print(function_name) for value1, value2 in test_vals: - print("{:8.7g}".format(function(value1, value2))) + print("{:.7g}".format(function(value1, value2))) |