This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
real_to_decimal rounds incorrectly
- From: Stephen L Moshier <steve at moshier dot net>
- To: gcc at gcc dot gnu dot org
- Date: Tue, 15 Oct 2002 16:29:49 -0400 (EDT)
- Subject: real_to_decimal rounds incorrectly
/* Link this test case with real.o and libiberty.a:
./xgcc -B./ tst.c real.o ../libiberty/libiberty.a
(The test case assumes 'long' is 32 bits, for real_from_target_fmt.) */
#include <stdio.h>
extern const struct real_format ieee_double_format;
extern void real_from_target_fmt (unsigned long *r, const long *buf,
const struct real_format
*fmt);
extern void real_to_decimal (char *str, const unsigned long *r_orig,
int digits);
void fancy_abort () {}
double td = 1.975949500000000000000000E6;
main ()
{
char s[80];
unsigned long r[6];
union
{
unsigned long l[4];
double d;
} u;
u.d = td;
printf ("Compiled double value %.16e\n", u.d);
real_from_target_fmt (r, &u.l[0], &ieee_double_format);
real_to_decimal (s, r, 7);
printf ("real_to_decimal value %s, should be 1.975950e6\n", s);
}