Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

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

nicolassellenet

Beginner

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

12-07-2009
06:30 AM

79 Views

Question about SNaN

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

jimdempseyatthecove

Black Belt

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

12-07-2009
08:20 AM

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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

12-07-2009
08:23 AM

79 Views

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

Jim

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

For more complete information about compiler optimizations, see our Optimization Notice.