floating point inconsistency

Cedric Roux cedric.roux@acri-st.fr
Tue Feb 16 12:22:00 GMT 2010


Andrew Haley wrote:
> That is strange.  A bit of debugging would be required to understand
> why that happens.

#include <stdio.h>
#include <math.h>

double length = 0.00106722283403500495;
double angle = 0.60066412215710574;

void dump(double d)
{
  unsigned char *c = (unsigned char *)&d;
  int i;
  for (i = 0; i < 8; i++, c++) printf("%2.2x", *c);
  printf("\n");
}

void calc(void)
{
  double sincos1, sincos2;

  asm volatile("fldl %2\n"
               "fsincos\n"
               "fstpl %0\n"
               "fstpl %1"
               : "=m" (sincos1), "=m" (sincos2) : "m" (angle));

  dump(sincos1);
  dump(cos(angle));
}

int main()
{
    calc();
    return 0;
}

I compile the above with gcc 4.1.2 (redhat) or 4.3.2 (debian)
(it gives the same result).

On an AMD (opteron as it seems):
/users/cro> ./a.out 
75d882701366ea3f
75d882701366ea3f

On an intel (so do I think):
/users/cro> ./a.out 
76d882701366ea3f
75d882701366ea3f

The least significant bit differs.

If that may help...
Cédric



More information about the Gcc-help mailing list