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]

exotic floating point formats test


I'd appreciate knowing what this program prints on a VAX (or an Alpha
asked to use VAX floating point), an IBM mainframe target, and a C4x
processor.  For reference:

i686-pc-linux-gnu $ ./a.out
3.25098346789696250880e+01      46454443 42414040       FEDC BA@@
sparc-sun-solaris2.7 $ ./a.out
3.25098346789696250880e+01      40404142 43444546       @@AB CDEF

[that's little- and big-endian IEEE, respectively]

If you want to be clever and come up with floating point numbers that
generate recognizable, distinct, strings in those formats, that'd be
even niftier.

Also, does anyone know why c4x.h requests an exotic target float
format, but xm-c4x.h leaves us in IEEE on the host?

zw

#include <stdio.h>
#include <ctype.h>

static double n[] =
{
  3.25098346789696250880e+01,	/* IEEE */
};

#define X(n) (isgraph(x[n]) ? x[n] : '.')
int main(void)
{
  int i;
  for (i = 0; i < (sizeof(n) / sizeof(double)); i++)
    {
      unsigned char *x = (unsigned char *) (n + i);
      printf("%.20e\t"
	     "%.2x%.2x%.2x%.2x %.2x%.2x%.2x%.2x\t"
	     "%c%c%c%c %c%c%c%c\n",
	     n[i],
	     x[0], x[1], x[2], x[3],
	     x[4], x[5], x[6], x[7],
	     X(0), X(1), X(2), X(3),
	     X(4), X(5), X(6), X(7));
    }
  return 0;
}


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