[Cfp-interest 2257] Re: printf and rounding recommendation

Vincent Lefevre vincent at vinc17.net
Thu Nov 4 04:44:59 PDT 2021


On 2021-11-04 10:51:37 +0100, Vincent Lefevre wrote:
> In the current C2x draft N2731, 7.21.6.1 The fprintf function:
> 
>     Recommended practice
> [...]
>  13 [...] If the number of significant decimal digits is more than M
>     but the source value is exactly representable with M digits, then
>     the result should be an exact representation with trailing zeros.
>     Otherwise, the source value is bounded by two adjacent decimal
>     strings L < U, both having M significant digits; the value of
>     the resultant decimal string D should satisfy L ≤ D ≤ U, with the
>     extra stipulation that the error should have a correct sign for
>     the current rounding direction.
> 
> In the case of directed rounding, this means that correct rounding is
> recommended (in both cases: exact[*] or not). But this is not the case
> for rounding-to-nearest. This is surprising.

Since L and U are restricted to M digits, I shouldn't have said
"correct rounding", but this is actually very similar. Indeed, in
rounding to nearest, the only constraint is that D should be in
the interval [L,U]. But in a directed rounding mode, due to the
condition on the sign of the error, if C is the exact value, the
constraint becomes either [L,C] (rounding toward −∞ or equivalent)
or [C,U] (rounding toward +∞ or equivalent). Thus, if the exact
value C is very close to L or U, i.e. to an M-digit number, then
the approximation needs to be computed with a much higher accuracy
due to the Table Maker's Dilemma.

-- 
Vincent Lefèvre <vincent at vinc17.net> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)


More information about the Cfp-interest mailing list