Why am I getting a NaN? 
Author Message
 Why am I getting a NaN?

I have some code that generates a NaN. I haven't a clue
why. I have run out of things to try. Please, if you have
any suggestions at all, tell me! Especially if it is something
stupid I'm doing, or missing.

The following code is inside a loop that is executed thousands
of times. The write statement was added to try and work out
what was wrong (file is opened and closed outside the loop)

      PRECOR=(B1*B1*PAK + (1-PAK)/B1)**(-1.5)

      write(99,900) precor, b1, pak
900   format(3e15.5)

A relevant section of the output:
    0.10000E+01    0.10000E+01    0.46807E+00
    0.10000E+01    0.10000E+01    0.20209E+00
    0.10000E+01    0.10000E+01    0.46807E+00
    0.10000E+01    0.10000E+01    0.46807E+00
    0.10000E+01    0.10000E+01    0.94192E+00
    0.10000E+01    0.10000E+01    0.20209E+00
           -nan    0.10000E+01    0.82435E+00
    0.10000E+01    0.10000E+01    0.82435E+00
    0.10000E+01    0.10000E+01    0.94192E+00
    0.10000E+01    0.10000E+01    0.61741E+00
    0.10000E+01    0.10000E+01    0.15435E+00
    0.10000E+01    0.10000E+01    0.82435E+00
    0.10000E+01    0.10000E+01    0.82435E+00
    0.10000E+01    0.10000E+01    0.61741E+00
    0.10000E+01    0.10000E+01    0.15435E+00

Notice that the values for b1 and pak are the same on the
line with the nan, and the one after. Perhaps they are different
after more decimal places, but surely a small difference like that
wouldn't turn this result into a NaN?

I am running this on:
  a 486/50 running Windows 3.1, 8 MBytes of RAM,
  code compiled as a Windows app using Watcom fortran 9.0
  Program is a 32 bit exe, using Watcom's "386 supervisor"
  Am linking with FPI87 flag (no x87 emulation, use and require
  x87)

The other interesting thing to note is that this doesn't appear
to generate a NaN when run on a 386 with a 387 installed.

Any and all suggestions gratefully received!

Anne.
--

It wasn't {*filter*} in general he couldn't stand the sight of, it was just his
{*filter*} in particular that was so upsetting.
        -- (Terry Pratchett, Sourcery)



Fri, 18 Oct 1996 13:54:27 GMT  
 Why am I getting a NaN?

Quote:

>      PRECOR=(B1*B1*PAK + (1-PAK)/B1)**(-1.5)

I note that in the sample output, B1 is always 1.
For any finite value of PAK, 1*1*PAK = PAK, (1-PAK)/B1 = 1-PAK,
so this is equivalent to (PAK + (1-PAK)).
When ABS(PAK) is much greater than 1, you'd get 0**(-1.5).
But all your values of PAK are close to 1, so we'd expect PRECOR = 1**(-1.5)
which is just 1, and indeed that's what your program usually prints.

What can produce a NaN?
        0/0
        infinity +/- infinity
        infinity * 0, 0 * infinity, infinity/infinity
        sqrt(-ve number)
However, you are using an operation which is not in the IEEE standard,
namely X ** (-1.5).  It could possibly be a bug in the implementation
of real**real.  I would be inclined to try
        PRECOR = B1*B1*PAK + (1-PAK)/B1
        PRECOR = 1/SQRT(PRECOR*PRECOR*PRECOR)
All of the operations in this version of the code are covered by the
IEEE standard, and for B1 > 0.1, PAK in [0.0,1.0] this certainly has
no business producing a NaN.

Quote:
>I am running this on:
>  a 486/50 running Windows 3.1, 8 MBytes of RAM,
>  code compiled as a Windows app using Watcom Fortran 9.0
>  Program is a 32 bit exe, using Watcom's "386 supervisor"
>  Am linking with FPI87 flag (no x87 emulation, use and require
>  x87)
>The other interesting thing to note is that this doesn't appear
>to generate a NaN when run on a 386 with a 387 installed.

I've heard of "486" chips from a certain non-Intel manufacturer that
were shipped with a bug in the floating-point system, where an FMOV
followed by some other instruction would sometimes not happen.  If
the FMOV is followed by an FWAIT, the bug doesn't bite.  If your
compiler is generating FWAITs, and the library code for real**real
has FWAITs in the right places, or if you have actual Intel chips,
this isn't your problem.

--

"C is quirky, flawed, and an enormous success."  -- Dennis M. Ritchie.



Sat, 19 Oct 1996 11:10:26 GMT  
 Why am I getting a NaN?

Quote:
Jason Taylor writes:
>Are there any programs that can take fortran
>source code and produce some sort of flowchart.

DEC sells a package named FUSE that provides a graphical interface to
several software development tools, including de{*filter*}s
and a call graph browser that maps the connectivity of subprogram
calls.  FUSE works for both C and Fortran.  It doesn't provide
information about the structure of I/O or conditional branching
in my experience.  Hopefully this will change in new versions.
I think that it is priced dearly, but I have found it very useful.
Bob Williams


Fri, 25 Oct 1996 21:12:21 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Why am I getting bind errors?

2. ERROR 48 - Why am I getting it?

3. why am i getting processor stack fault error?

4. Newbe help : Why am I getting this output ?!?

5. Getting NAN while reading the data using AIRead

6. When is a Nan not a Nan?

7. What does NaN and -NaN mean?

8. max(NaN,0) should be NaN

9. The Smalltalk Store: Why we've been slow, and why we're getting better

10. why why why oh why why baby

11. Into what am I getting?

12. I am getting THISTHREADACTIVE error (lots of them)

 

 
Powered by phpBB® Forum Software