8000 py/formatfloat: Calculate reference values with pow(). · dpwe/micropython@701f3ba · GitHub
[go: up one dir, main page]

Skip to content

Commit 701f3ba

Browse files
committed
py/formatfloat: Calculate reference values with pow().
Formerly, ```formatfloat``` struggled with formatting exact powers of 10 as created by ```parsenum``` because of small differences in how those powers of 10 were calculated: ```formatfloat``` multiplied together a few values of 10^(2^Y) from a lookup table, but ```parsenum``` used ```pow(10, X)```. This was mitigated in micropython#8905 by adding 2eps of extra margin when comparing values ("aggressive rounding up"). This patch instead removes the discrepency by using ```pow()``` in ```formatfloat``` also. This eliminates the need for the 2eps margin, as well as the lookup tables. It is likely slower to run, however. In addition, this patch directly estimates the power-of-10 exponent from the power-of-2 exponent in the floating-point representation. This change surfaced a previously-noted problem with parsing numbers including trailing zeros. The fix to that problem, micropython#8980, is included in this PR to make the tests pass. Signed-off-by: Dan Ellis <dan.ellis@gmail.com>
1 parent e3c6bc1 commit 701f3ba

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

py/parsenum.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,8 @@ mp_obj_t mp_parse_num_float(const char *str, size_t len, bool allow_imag, mp_lex
309309
}
310310
accept_digit(&dec_val, dig, &exp_extra, in);
311311
}
312+
//DEBUG_printf("dec_val %f exp_extra %d trail_z_i %d trail_z_f %d\n",
313+
// (double)dec_val, exp_extra, trailing_zeros_intg, trailing_zeros_frac); 47BF
312314
}
313315
} else if (in == PARSE_DEC_IN_INTG && dig == '.') {
314316
in = PARSE_DEC_IN_FRAC;

0 commit comments

Comments
 (0)
0