|
|
Up |
|
|
  |
Author: jmdrake_98jmdrake_98 Date: Jul 11, 2006 08:06
Bernd Paysan wrote:
>> (version 2)
>> : digit -10 + -if -7 + then 65 + ;
>>
>> (Again, thanks CF mailing list).
>
> Good example, but slightly missing the point. If you have a destructive -IF,
> you would write that
>
> : digit -10 + dup -if -7 + then 65 + ;
>
> and the dup won't destroy anything (since the -10 consumes the same stack
> element as the dup after the +). Yes, that's more work to do, but what you
> waste here you might gain elsewhere, so it's all about trade-offs, anyway.
> And there's no space in the instruction set for both destructive and
> non-destructive branches ;-).
>
> -- ...
|
| Show full article (1.74Kb) |
|
| | 19 Comments |
|
  |
Author: dpbdpb Date: Aug 15, 2006 08:48
> 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.
|
| |
|
| | no comments |
|
  |
Author: leafleaf Date: Aug 15, 2006 08:51
Not a Number=NaN
The denominator might be zero or functions having a invalid operand
such as sqrt(-1)
|
| |
| no comments |
|
  |
Author: nospamnospam Date: Aug 15, 2006 08:53
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.
|
| Show full article (1.33Kb) |
| no comments |
|
  |
Author: Herman D. KnobleHerman D. Knoble Date: Aug 15, 2006 10: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@ 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!
|
| |
| 8 Comments |
|
  |
Author: zhngbnzhngbn Date: Aug 15, 2006 16:51
Thank you guys all.I am really lucky to be in this group and now the
problem is under control.
|
| |
| no comments |
|
  |
Author: George N. White IIIGeorge N. White III Date: Aug 19, 2006 07:48
> 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!
Others have described situations that produce NaN, but it is important to
mention that some expressions that seem "mathematically" safe can
produce NaN's in numerical code. To mathematicians, exp(-x) > 0, but
in machine arithmetic, exp(-x) can be zero for large positive x.
|
| |
| no comments |
|
  |
Author: brubru Date: Aug 21, 2006 03:40
Herman D. Knoble wrote:
> 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@ mail.ustc.edu.cn wrote:
>
> -|I am just a freshman to fortran,and when i run my program recently, the ...
|
| Show full article (1.82Kb) |
| 7 Comments |
|
  |
Author: Herman D. KnobleHerman D. Knoble Date: Aug 21, 2006 05:03
The NAG compiler is complaining about Binary constants of the
form: data PInf/B'01111111100000000000000000000000'/ ! +Infinity
where PInf is REAL.
I've updated this file; the lagest version of it:
http://ftp.cac.psu.edu/pub/ger/fortran/hdk/nan.f90
uses Integer variables and Equivalence to Reals to effect
the use/detection of NaN's.
Thanks for reporting this.
Skip
On Mon, 21 Aug 2006 12:40:28 +0200, bru wrote:
-|Herman D. Knoble wrote:
-|> Other posters gave you situations in which could result in a NaN.
-|> Pay particular attention to Richard's statement about uninitialized
-|> variables.
-|>
-|> An example...
|
| Show full article (2.34Kb) |
| 6 Comments |
|
  |
|
|
  |
Author: Bernard BruBernard Bru Date: Aug 21, 2006 05:45
Herman D. Knoble wrote:
> The NAG compiler is complaining about Binary constants of the
> form: data PInf/B'01111111100000000000000000000000'/ ! +Infinity
> where PInf is REAL.
>
> I've updated this file; the lagest version of it:
> http://ftp.cac.psu.edu/pub/ger/fortran/hdk/nan.f90
>
> uses Integer variables and Equivalence to Reals to effect
> the use/detection of NaN's.
>
> Thanks for reporting this.
> Skip
>
>
> On Mon, 21 Aug 2006 12:40:28 +0200, bru wrote:
>
> -|Herman D. Knoble wrote:
> -|> Other posters gave you situations in which could result in a NaN.
> -|> Pay particular attention to Richard's statement about uninitialized ...
|
| Show full article (2.63Kb) |
| 5 Comments |
|
|
|
|