Assigning nan to a double

Quote:

>>Can anyone tell me how to assign the value nan (as known on an

>>Intel processor) to a double

>Although off topic, the answer is short. For infinity, all 11

>exponent bits are 1's and all 52 significand bits are 0's. The

>sign bit differentiates positive vs negative infinity.

>For NaN's, all 11 exponent bits are also 1's, but all 52

>significand bits are NOT 0's.

That still doesn't tell him how to assign a NaN to a variable.

One could use such representation information to initialize a

union of an array of integer and a double with the integer values,

then access the double value, but that isn't strictly conforming

code. Another approach is to cheaply generate a NaN and just

assign that. I assume the environment supports IEEE math (since

there is little use for NaNs otherwise):

#include <math.h>

...

double d = sqrt(-1.0);

// d now holds some representation of a NaN