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

Highlighted
##

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.

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

7 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.

2 Replies

Highlighted
##

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:20 AM

7 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

Highlighted
##

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

Jim

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

7 Views

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

Jim

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