> get_nanbits(unsigned int *b, int k)
> {
> union { double d; unsigned int z[2]; } u, u1, u2;
>
> k = 2 - k;
> u1.z[k] = u2.z[k] = 0x7ff00000;
> u1.z[1-k] = u2.z[1-k] = 0;
> u.d = u1.d - u2.d; /* Infinity - Infinity */ <<<<<<<====== this is the
> FATAL ERROR.
> b[0] = u.z[0];
> b[1] = u.z[1];
> }
>
> called as getnanbits(nanbits,1)
oh, boy.
we can assume ieee 754. the pattern you want for the nan is
u.hi = 0x7ff80000; /* sign = 0; exp = 1s; msb in signf set */
u.lo = 0;
you can use FPdbleword in <u.h> for regular plan 9 programs,
and <float.h> for ape programs which will take care of this for you.
in that case, you'd have
void
get_nanbits(unsigned int *b, int)
{
FPdbleword w;
assert(sizeof(double) == 8);
w.hi = 0x7ff80000;
w.lo = 0;
memcpy(b, &w, 8);
}