Commit 516c28c
committed
Substantial rewrite to eliminate the loop.
Compared to the previous version:
The helper function `need_to_round_up` is replaced with
`rounding_direction`, which has three rather than two return values:
it can distinguish 'round down' from 'already exact, no rounding at
all'.
The method `DyadicFloat::as_mantissa_type_rounded` no longer returns
an overflow indication, because we now avoid overflowing in the first
place by early detection of wildly out-of-range exponents. But it does
return a rounding direction indicating whether the mantissa was
rounded up, down, or was exact.
I had to fix `BigInt::decrement()`, which turned out to be
accidentally an exact copy of `increment()`.
Then `decimal_digits` is rewritten essentially as suggested in the
review comments:
- there's no loop
- the initial estimated exponent is used to detect the need to shift
from F to E mode in advance rather than spotting it after the fact
by overflow
- so now the initial decimal exponent is always either correct or one
too small
- and if it's one too small, we handle it by truncating a digit off
the output decimal mantissa, re-rounding carefully to avoid a
double-rounding error.1 parent 797da34 commit 516c28c
File tree
3 files changed
+242
-147
lines changed- libc/src
- __support
- FPUtil
- stdio/printf_core
3 files changed
+242
-147
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
29 | | - | |
30 | | - | |
31 | | - | |
32 | | - | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
38 | 41 | | |
39 | | - | |
40 | | - | |
41 | | - | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
42 | 50 | | |
43 | 51 | | |
44 | 52 | | |
45 | 53 | | |
46 | 54 | | |
47 | 55 | | |
48 | | - | |
| 56 | + | |
49 | 57 | | |
50 | | - | |
| 58 | + | |
51 | 59 | | |
52 | 60 | | |
53 | | - | |
| 61 | + | |
54 | 62 | | |
55 | | - | |
| 63 | + | |
56 | 64 | | |
57 | | - | |
| 65 | + | |
58 | 66 | | |
59 | 67 | | |
60 | 68 | | |
| |||
143 | 151 | | |
144 | 152 | | |
145 | 153 | | |
146 | | - | |
| 154 | + | |
147 | 155 | | |
148 | 156 | | |
149 | 157 | | |
| |||
431 | 439 | | |
432 | 440 | | |
433 | 441 | | |
434 | | - | |
435 | | - | |
436 | | - | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
437 | 460 | | |
438 | | - | |
439 | | - | |
440 | | - | |
441 | | - | |
442 | | - | |
443 | | - | |
444 | | - | |
445 | | - | |
446 | | - | |
447 | | - | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
448 | 464 | | |
449 | 465 | | |
450 | | - | |
451 | | - | |
452 | | - | |
| 466 | + | |
| 467 | + | |
453 | 468 | | |
454 | 469 | | |
455 | 470 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
980 | 980 | | |
981 | 981 | | |
982 | 982 | | |
983 | | - | |
| 983 | + | |
984 | 984 | | |
985 | 985 | | |
986 | 986 | | |
| |||
0 commit comments