Summary: | support for printing/reading decimal numbers (_Decimal64) | ||
---|---|---|---|
Product: | glibc | Reporter: | Paul Zimmermann <zimmerma+gcc> |
Component: | libc | Assignee: | Ulrich Drepper <drepper.fsp> |
Status: | RESOLVED WONTFIX | ||
Severity: | enhancement | CC: | glibc-bugs, vincent-srcware |
Priority: | P2 | Flags: | fweimer:
security-
|
Version: | unspecified | ||
Target Milestone: | --- | ||
Host: | Target: | ||
Build: | Last reconfirmed: |
Description
Paul Zimmermann
2010-04-07 08:40:13 UTC
The code is invalid. %f takes an argument of type double, not a _Decimal64. You need the D modifier (see WG14/N1312, 9.5 Formatted input/output specifiers), e.g. %Df. Vincent, you are right. With printf ("%.20Df\n", e) I get: tarte% gcc bug.c tarte% ./a.out 0.10000000000000000555 %.20Df which is not very useful... Paul With a corrected code: #include <stdio.h> int main (void) { double d = 0.1; _Decimal64 e = 0.1; printf ("%.20f\n", d); printf ("%Da\n", e); printf ("%De\n", e); printf ("%Df\n", e); printf ("%Dg\n", e); return 0; } currently gives: 0.10000000000000000555 %Da %De %Df %Dg Also, this doesn't matter now, but if accuracy needs to be taken into account (once this is implemented), one should use _Decimal64 e = 0.1dd; for the tests, instead of: _Decimal64 e = 0.1; *** Bug 11476 has been marked as a duplicate of this bug. *** This is what the printf hooks are for. I'm not going to add any such non-standard conversion. It far too dangerous a compability risk going forward. The conversion is currently non-standard, but it may become standard in the future. At that time, the status of this bug will have to be revised. (In reply to comment #6) > This is what the printf hooks are for. I'm not going to add any such > non-standard conversion. It far too dangerous a compability risk going forward. Dear Ulrich, please can you explain why this is "non-standard". With respect to which standard? Is _Decimal64 standard? Also, if someone provides changes to scanf/printf based on functions already existing in libbid or libdecnumber (currently used internally by gcc) for conversions between strings and decimal formats, would them be included in glibc? Subject: Re: support for printing/reading decimal numbers (_Decimal64) On Wed, 28 Apr 2010, zimmerma+gcc at loria dot fr wrote: > ------- Additional Comments From zimmerma+gcc at loria dot fr 2010-04-28 08:15 ------- > (In reply to comment #6) > > This is what the printf hooks are for. I'm not going to add any such > > non-standard conversion. It far too dangerous a compability risk going forward. > > Dear Ulrich, please can you explain why this is "non-standard". With respect to > which standard? Is _Decimal64 standard? A Technical Report Type 2 (such as TR 24732) is not a standard or an amendment to a standard. > Also, if someone provides changes to scanf/printf based on functions already > existing in libbid or libdecnumber (currently used internally by gcc) for > conversions between strings and decimal formats, would them be included in glibc? The functionality is in the libfdp add-on. This is an example of what the add-on mechanism is for; it doesn't need to be in the core libc. (I imagine the libdfp people will propose a scanf hook facility at some point to allow that part to be fully implemented in an add-on. One remaining DFP requirement relates to the predefined macro __STDC_DEC_FP__ but unfortunately my proposal for a change which would also allow that to be handled entirely within the add-on has stalled; see bug 10110.) |