When is a Nan not a Nan? 
Author Message
 When is a Nan not a Nan?

        When I run the following code on an SGI machine I get the output
as indicated:

      PROGRAM BITEST
      REAL X

      X = B'11111111111111111111111111111111'
      WRITE(*,*) X

      END

Output:

   0.0000000E+00

        However, according to the IEEE 754 standard, I was expecting
to get NaN.  Does anyone know if there is a reason for this behavior?



Fri, 22 Aug 1997 14:49:05 GMT  
 When is a Nan not a Nan?

Quote:

>    When I run the following code on an SGI machine I get the output
> as indicated:

>       PROGRAM BITEST
>       REAL X

>       X = B'11111111111111111111111111111111'
>       WRITE(*,*) X

>       END

> Output:

>    0.0000000E+00

>    However, according to the IEEE 754 standard, I was expecting
> to get NaN.  Does anyone know if there is a reason for this behavior?

Since you are assigning an integer constant to a real variable, it might
be reasonable to assume that the type conversion may yield something other
than the expected bit pattern.  I've found that EQUIVALENCE works well to
set specific bit patterns in floating-point variables.  Something like:

      PROGRAM BITEST
      REAL X
      EQUIVALENCE (X, I)

      I = B'11111111111111111111111111111111'
      WRITE(*,*) X

      END


--
"Where a calculator on the ENIAC is equipped with 18,000 vacuum tubes and
weighs 30 tons, computers in the future may have only 1,000 vacuum tubes
and perhaps weigh 1 1/2 tons."   --Popular Mechanics, March 1949



Sat, 23 Aug 1997 00:26:28 GMT  
 When is a Nan not a Nan?

Quote:

>Since you are assigning an integer constant to a real variable, it might
>be reasonable to assume that the type conversion may yield something other
>than the expected bit pattern.  I've found that EQUIVALENCE works well to
>set specific bit patterns in floating-point variables.  Something like:

>      PROGRAM BITEST
>      REAL X
>      EQUIVALENCE (X, I)

>      I = B'11111111111111111111111111111111'
>      WRITE(*,*) X

>      END



        I followed your suggestion and wrote the following program:

      PROGRAM BITEST
      REAL X, Y
      EQUIVALENCE (X, I)

      I = B'11111111111111111111111111111111'
      Y = B'11111111111111111111111111111111'
      WRITE(*,*) X
      WRITE(*,*) Y

      END

For which I got the following output:

 nan            
   0.0000000E+00

However, I decided to check the assembly code.  I am including the following
fragment:

 #   2        REAL X, Y
 #   3        EQUIVALENCE (X, I)
 #   4  
 #   5        I = B'11111111111111111111111111111111'
        li      $24, -1
        sw      $24, .bitest_.0
        .loc    2 6
 #   6        Y = B'11111111111111111111111111111111'
        li.s    $f4, nan
        s.s     $f4, 44($sp)
        .loc    2 7

So even though Y is set to nan in the assemble code, it is still
equal to 0.0 on output.
        I still find this behaviour curious.

Ed Lang



Sat, 30 Aug 1997 01:26:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. What does NaN and -NaN mean?

2. max(NaN,0) should be NaN

3. Why am I getting a NaN?

4. Catching NaN .. not a number

5. NaN with RedHat 6.2 but not 6.1

6. NaN remover and interpolator

7. Getting NAN while reading the data using AIRead

8. NaN, screen shots, & posting a .vi

9. Comparing NaN

10. Nan and Infinity

11. isnan, nan? and ruby versions

12. FXRuby compilations consume NAN RAM?

 

 
Powered by phpBB® Forum Software