Bug 11475 - support for printing/reading decimal numbers (_Decimal64)
Summary: support for printing/reading decimal numbers (_Decimal64)
Status: RESOLVED WONTFIX
Alias: None
Product: glibc
Classification: Unclassified
Component: libc (show other bugs)
Version: unspecified
: P2 enhancement
Target Milestone: ---
Assignee: Ulrich Drepper
URL:
Keywords:
: 11476 (view as bug list)
Depends on:
Blocks:
 
Reported: 2010-04-07 08:40 UTC by Paul Zimmermann
Modified: 2014-06-30 18:18 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:
fweimer: security-


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Paul Zimmermann 2010-04-07 08:40:13 UTC
as far as I know, the current glibc does not print/read decimal formats
(_Decimal64 for example). Is there any plan to support this?

Example code:
#include <stdio.h>

int
main()
{
  double d = 0.1;
  _Decimal64 e = 0.1;
  printf ("%.20f\n", d);
  printf ("%.20f\n", e);
}

gives:

tarte% gcc bug.c
tarte% ./a.out 
0.10000000000000000555
0.00000000000000000000

We expect 0.10000000000000000000 for the second output.
Comment 1 Vincent Lefèvre 2010-04-07 09:11:31 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.
Comment 2 Paul Zimmermann 2010-04-07 09:15:57 UTC
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
Comment 3 Vincent Lefèvre 2010-04-07 09:17:24 UTC
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
Comment 4 Vincent Lefèvre 2010-04-07 09:25:42 UTC
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;
Comment 5 Andreas Schwab 2010-04-07 09:37:43 UTC
*** Bug 11476 has been marked as a duplicate of this bug. ***
Comment 6 Ulrich Drepper 2010-04-07 13:30:46 UTC
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.
Comment 7 Vincent Lefèvre 2010-04-07 15:30:16 UTC
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.
Comment 8 Paul Zimmermann 2010-04-28 08:15:40 UTC
(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?
Comment 9 joseph@codesourcery.com 2010-04-28 11:46:15 UTC
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.)