lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Bulat Ziganshin wrote:
> > But the stores from the x87 FPU to a long double only write to the
> > first 12 bytes.
> 
> 10 bytes, i think

Yup, you're right. Which makes this even more problematic because
the hash code is prone to failure on 32 bit, too. It just happens
statistically less often. Rewriting hashnum() to cope with this is
left as an exercise to the reader ...

--Mike

#include <stdio.h>
#include <string.h>

int main(int argc, char **argv)
{
  union { long double ld; unsigned char b[sizeof(long double)]; } x;
  int i;
  memset(x.b, 0xaa, sizeof(long double));
  for (i = 0; i < sizeof(long double); i++) printf("%02x ", x.b[i]);
  printf("\n");
  x.ld = (long double)argc + 0.0;  /* Force a runtime calculation. */
  for (i = 0; i < sizeof(long double); i++) printf("%02x ", x.b[i]);
  printf("\n");
  return 0;
}

32 bit output:
aa aa aa aa aa aa aa aa aa aa aa aa 
00 00 00 00 00 00 00 80 ff 3f aa aa 

64 bit output:
aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa 
00 00 00 00 00 00 00 80 ff 3f aa aa aa aa aa aa