[Bug c/41049] New: conversion from integer to decimal float loses trailing zeros
janis at gcc dot gnu dot org
gcc-bugzilla@gcc.gnu.org
Wed Aug 12 21:05:00 GMT 2009
IEEE 754 says that the preferred exponent of the result of a conversion from an
integer to a decimal float value is zero. In all active branches of GCC a
compile-time conversion discards trailing zeros and then adds one back, and a
runtime conversion for the densely-packed decimal format adds an extra trailing
zero. Runtime conversions for the BID format are correct, as are runtime
conversions for DPD using hardware DFP.
This test demonstrates the problem:
----------------------------
#include <stdio.h>
int
main ()
{
volatile _Decimal32 d;
volatile long long ll;
d = 5.DF;
printf ("5.DF constant 0x%x want this\n", *(int *)&d);
d = 5.0DF;
printf ("5.0DF constant 0x%x not this\n", *(int *)&d);
d = 5;
printf ("5 constant 0x%x\n", *(int *)&d);
d = 5LL;
printf ("5LL constant 0x%x\n", *(int *)&d);
ll = 5LL;
d = ll;
printf ("5LL variable 0x%x\n", *(int *)&d);
printf ("\n");
d = 50.DF;
printf ("50.DF constant 0x%x want this\n", *(int *)&d);
d = 50.0DF;
printf ("50.0DF constant 0x%x not this\n", *(int *)&d);
d = 50;
printf ("50 constant 0x%x\n", *(int *)&d);
d = 50LL;
printf ("50LL constant 0x%x\n", *(int *)&d);
ll = 50LL;
d = ll;
printf ("50LL variable 0x%x\n", *(int *)&d);
printf ("\n");
d = 500.DF;
printf ("500.DF constant 0x%x want this\n", *(int *)&d);
d = 5.0E2DF;
printf ("5.0E2DF constant 0x%x not this\n", *(int *)&d);
d = 500.0DF;
printf ("500.0DF constant 0x%x not this\n", *(int *)&d);
d = 500;
printf ("500 constant 0x%x\n", *(int *)&d);
d = 500LL;
printf ("500LL constant 0x%x\n", *(int *)&d);
ll = 500LL;
d = ll;
printf ("500LL variable 0x%x\n", *(int *)&d);
return 0;
}
----------------------------
With DPD on either powerpc64-linux or i686-linux the results are:
laptop% /home/janis/tools/gcc-trunk-dpd/bin/gcc bug3.c && ./a.out
5.DF constant 0x22500005 want this
5.0DF constant 0x22400050 not this
5 constant 0x22400050
5LL constant 0x22400050
5LL variable 0x22400050
50.DF constant 0x22500050 want this
50.0DF constant 0x22400280 not this
50 constant 0x22500050
50LL constant 0x22500050
50LL variable 0x22400280
500.DF constant 0x22500280 want this
5.0E2DF constant 0x22600050 not this
500.0DF constant 0x22401400 not this
500 constant 0x22600050
500LL constant 0x22600050
500LL variable 0x22401400
For BID on i686-linux the results are:
laptop% /home/janis/tools/gcc-trunk-bid/bin/gcc bug3.c && ./a.out
5.DF constant 0x32800005 want this
5.0DF constant 0x32000032 not this
5 constant 0x32000032
5LL constant 0x32000032
5LL variable 0x32800005
50.DF constant 0x32800032 want this
50.0DF constant 0x320001f4 not this
50 constant 0x32800032
50LL constant 0x32800032
50LL variable 0x32800032
500.DF constant 0x328001f4 want this
5.0E2DF constant 0x33000032 not this
500.0DF constant 0x32001388 not this
500 constant 0x33000032
500LL constant 0x33000032
500LL variable 0x328001f4
I'm working on fixes to the compiler and to the DPD runtime.
--
Summary: conversion from integer to decimal float loses trailing
zeros
Product: gcc
Version: 4.3.5
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
AssignedTo: janis at gcc dot gnu dot org
ReportedBy: janis at gcc dot gnu dot org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41049
More information about the Gcc-bugs
mailing list