- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
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.
Link Copied
2 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Oops, sorry about using FORTRAN reference (forgot what forum this was), you should be able to convert to C++
Jim

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page