Community
cancel
Showing results for 
Search instead for 
Did you mean: 
nicolassellenet
Beginner
79 Views

Question about SNaN

Hi,

I like to initialize variables in my program with values that will crash if they are not modified. For this I thought to use NaN. I have seen in the standard IEEE754 that "SNaN can be handy to assign to uninitialized variables to trap premature usage".

But, I can not generate this type of values.

So my question is : How is it possible to generate SNaN ?

Thanks in advance.

Regards,

Nicolas S.
0 Kudos
2 Replies
jimdempseyatthecove
Black Belt
79 Views


In reading IEEE 754 sign can be either 0/1, exponent of all 1's, msb of fraction 0, any/all remainder bits of fraction non-zero (a zero fraction represents +/- Infinity based on sign bit)

The binary representation is: Sign bit, exponent, fraction

Single precision 1, 8, 23 (e.g. B'01111111100000000000000000000001')

Double precision 1, 11, 52 (e.g. B'0111111111110000000000000000000000000000000000000000000000000001')

The problem is you cannot use a variable containing this bit pattern to load your arrays AS REAL(4) or REAL(8)

What you can do is use an INTEGER(4) or INTEGER(8) that is equivalence'd or union/map'd over the top of the REAL.

Jim Dempsey


jimdempseyatthecove
Black Belt
79 Views


Oops, sorry about using FORTRAN reference (forgot what forum this was), you should be able to convert to C++

Jim
Reply