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

Jim Thomas jaswthomas at sbcglobal.net
Tue Nov 9 14:30:43 PST 2021


The first part of the Recommended Practice (not included in [Cfp-interest 2256]) says:

For e, E, f, F, g, and G conversions, if the number of significant decimal digits is at most the maximum value M of the T_DECIMAL_DIG macros (defined in <float.h>), then the result should be correctly rounded. 

If the implementation does this for a directed rounding mode, then it could satisfy the RP for numbers of significant decimal digits greater than M by rounding (using the directed rounding mode) to M digits and padding with zeros.

- Jim Thomas

> On Nov 4, 2021, at 4:44 AM, Vincent Lefevre <vincent at vinc17.net> wrote:
> 
> 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)
> _______________________________________________
> Cfp-interest mailing list
> Cfp-interest at oakapple.net
> http://mailman.oakapple.net/mailman/listinfo/cfp-interest

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.oakapple.net/pipermail/cfp-interest/attachments/20211109/4732b775/attachment-0001.htm>


More information about the Cfp-interest mailing list