[Cfp-interest] %a precision specification

Jim Thomas jaswthomas at sbcglobal.net
Mon Aug 14 15:15:48 PDT 2017


This message is about an issue raised at the April 2017 WG14 meeting: DR 11 – Why is %a different from binary FP?

The question refers to the difference in the meaning of the precision specification. For binary FP (in C11) it is the number of digits after the decimal point; for decimal FP (in TS 18661-2) it is the total number of digits, including the one before the decimal point.

Why the difference? For binary, %a formatting was modeled after %e formatting.  For decimal, %a formatting was modeled after %g formatting. In each case, the meaning of the precision was adopted from the model (%e or %g).

For both binary and decimal, the primary use of %a formatting is to obtain character sequences that exactly represent the data in the types. Otherwise, %a formatting for binary and decimal are quite different, largely because of the requirement to preserve the quantum as well as the numeric value for decimal data. Perhaps this is the reason the difference in the meaning of the precision hasn’t been seen as a problem.

The current meaning of the precision in %a formatting for decimal has been implemented and in use for about 10 years, dating back to the drafts of the 2008 Decimal TR (which included it).

 Considering that the difference has been around for so long without seeming to have been a problem, and considering that changing the meaning of the precision would break implementations and code, we recommend no change to normative text.


 If believed helpful, a footnote could be added to point out the precision difference, e.g.,


 *) The style of a conversion for decimal floating types differs is several ways from that for standard floating types. For example, for decimal floating types the formatting precision specifies the total number of digits (similar to g conversion); for standard floating types the formatting precision specifies the number of digits after the decimal point (similar to e conversion).


C FP group

 

 

 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.oakapple.net/pipermail/cfp-interest/attachments/20170814/bf581f77/attachment.html 


More information about the Cfp-interest mailing list