|
From: zhngbn on 15 Aug 2006 11:37 I am just a freshman to fortran,and when i run my program recently, the value of a variable turns out to be NaN.I am a little confused and have no idea how to deal with it. Can anyone tell me normally in what kind of situation will the variable become NaN?Thank you!
From: dpb on 15 Aug 2006 11:48 zhn...(a)mail.ustc.edu.cn wrote: > I am just a freshman to fortran,and when i run my program recently, the > value of a variable turns out to be NaN.I am a little confused and have > no idea how to deal with it. Can anyone tell me normally in what kind > of situation will the variable become NaN?Thank you! >From CVF help files... Not a Number (NaN) results from an operation involving one or more invalid operands. For instance 0/0 and SQRT(-1) result in NaN. In general, an operation involving a NaN produces another NaN. Because the fraction of a NaN is unspecified, there are many possible NaNs. This may give you a few clues -- to understand precisely what is going on in your particular case if you could make a test case that causes the problem in a short demo and post that code, most likely somebody here can spot the problem. Depending on the compiler and hardware, there may be a way to cause and exception when the NaN is generated that might help isolate the first occurrence.
From: leaf on 15 Aug 2006 11:51 Not a Number=NaN The denominator might be zero or functions having a invalid operand such as sqrt(-1)
From: Richard E Maine on 15 Aug 2006 11:53 <zhngbn(a)mail.ustc.edu.cn> wrote: > I am just a freshman to fortran,and when i run my program recently, the > value of a variable turns out to be NaN.I am a little confused and have > no idea how to deal with it. Can anyone tell me normally in what kind > of situation will the variable become NaN?Thank you! Basically 2 kinds of situations. 1. NaN stands for "Not A Number". It typically results when there is not a well-defined numeric answer for a computation. A classic example is dividing 0.0/0.0, but other operations can also get it. Another type of example might be invalid operations such as the arcsin of a number greater than 1 or the square root of a negative number. Invalid operations sometimes cause the program to abort, but depending on compiler options, they might give a NaN result instead. 2. Variables that have never been properly given a value might (or might not, depending on compiler details) have a NaN value instead. The simplest example is most variables at the beginning of execution of the program. Variable values do *NOT* automatically start out at zero as some programmers incorrectly assume. -- Richard Maine | Good judgment comes from experience; email: my first.last at org.domain| experience comes from bad judgment. org: nasa, domain: gov | -- Mark Twain
From: Herman D. Knoble on 15 Aug 2006 13:54
Other posters gave you situations in which could result in a NaN. Pay particular attention to Richard's statement about uninitialized variables. An example of a compiler that initializes uninitialized variables to NaN is G95 G95 has a compiler option: -freal=nan which initializes uninitialized scalar real and complex varable values to NaN. Here is an example of Fortran code that demonstrates NaN's. See the URL's in the comments which point to more formal information on NaN's http://ftp.cac.psu.edu/pub/ger/fortran/hdk/nan.f90 Skip Knoble On 15 Aug 2006 08:37:07 -0700, zhngbn(a)mail.ustc.edu.cn wrote: -|I am just a freshman to fortran,and when i run my program recently, the -|value of a variable turns out to be NaN.I am a little confused and have -|no idea how to deal with it. Can anyone tell me normally in what kind -|of situation will the variable become NaN?Thank you! |