Skip to content

Commit c322c5f

Browse files
committed
py: Fix regress for printing of floats and #if.
Also change formating modifier in test script (it still passes with original format though).
1 parent a05f5dd commit c322c5f

2 files changed

Lines changed: 6 additions & 6 deletions

File tree

py/objstr.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -788,9 +788,9 @@ mp_obj_t str_format(uint n_args, const mp_obj_t *args) {
788788
nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_ValueError,
789789
"Unknown format code '%c' for object of type '%s'", type, mp_obj_get_type_str(arg)));
790790
}
791+
}
791792

792-
#if MICROPY_ENABLE_FLOAT
793-
} else if (arg_looks_numeric(arg)) {
793+
if (arg_looks_numeric(arg)) {
794794
if (!type) {
795795

796796
// 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) {
828828

829829
flags |= PF_FLAG_PAD_NAN_INF; // '{:06e}'.format(float('-inf')) should give '-00inf'
830830
switch (type) {
831+
#if MICROPY_ENABLE_FLOAT
831832
case 'e':
832833
case 'E':
833834
case 'f':
@@ -841,14 +842,13 @@ mp_obj_t str_format(uint n_args, const mp_obj_t *args) {
841842
flags |= PF_FLAG_ADD_PERCENT;
842843
pfenv_print_float(&pfenv_vstr, mp_obj_get_float(arg) * 100.0F, 'f', flags, fill, width, precision);
843844
break;
845+
#endif
844846

845847
default:
846848
nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_ValueError,
847849
"Unknown format code '%c' for object of type 'float'",
848850
type, mp_obj_get_type_str(arg)));
849851
}
850-
#endif
851-
852852
} else {
853853
// arg doesn't look like a number
854854

tests/basics/math-fun.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
for function_name, function, test_vals in functions:
3535
print(function_name)
3636
for value in test_vals:
37-
print("{:8.7g}".format(function(value)))
37+
print("{:.7g}".format(function(value)))
3838

3939
binary_functions = [('copysign', copysign, [(23., 42.), (-23., 42.), (23., -42.),
4040
(-23., -42.), (1., 0.0), (1., -0.0)])
@@ -43,4 +43,4 @@
4343
for function_name, function, test_vals in binary_functions:
4444
print(function_name)
4545
for value1, value2 in test_vals:
46-
print("{:8.7g}".format(function(value1, value2)))
46+
print("{:.7g}".format(function(value1, value2)))

0 commit comments

Comments
 (0)