This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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);
}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]