|
|
Up |
|
|
  |
Author: Ralf SchaaRalf Schaa Date: Jul 12, 2007 18:37
People,
looking at all the threads abouth this topic leaves me confused - I
could not find an answer to the following question:
if( var/var /= 1) then
write(*,*) 'This is a NAN or INF'
endif
i) can I test wether a real variable is a number with this test?
ii) or is it highly dependent on what platform/compiler you are
using ?
iii) does it always work?
Cheers
-Ralf
|
| |
|
| | 7 Comments |
|
  |
Author: Tim PrinceTim Prince Date: Jul 12, 2007 18:59
Ralf Schaa wrote:
> People,
>
> looking at all the threads abouth this topic leaves me confused - I
> could not find an answer to the following question:
>
>
> if( var/var /= 1) then
> write(*,*) 'This is a NAN or INF'
> endif
>
> i) can I test wether a real variable is a number with this test?
> ii) or is it highly dependent on what platform/compiler you are
> using ?
> iii) does it always work?
With the right code generation, it will work on any hardware which
supports IEEE754 and the like. (I assume var is a real data type).
A more reasonable way to write an equivalent test would be
if(var /= var)then
write(*,*)'Nan value' ...
|
| Show full article (1.31Kb) |
|
| | no comments |
|
  |
Author: nospamnospam Date: Jul 12, 2007 19:02
Ralf Schaa wrote:
> if( var/var /= 1) then
> write(*,*) 'This is a NAN or INF'
> endif
>
> i) can I test wether a real variable is a number with this test?
> ii) or is it highly dependent on what platform/compiler you are
> using ?
> iii) does it always work?
It is highly dependent on the platform and compiler. No, it doesn't
always work. I wouldn't even count on it usually working. It is likely
to cause an abort on some platforms. That's not to speak of the fact
that 0.0 is a perfectly valid number that is neither NaN nor Inf, but is
quite unlikely to give you 1 as a result. In fact, based on that, I
would venture to say that there are probably no compilers where this
test is accurate.
|
| Show full article (1.14Kb) |
| no comments |
|
  |
Author: Ralf SchaaRalf Schaa Date: Jul 12, 2007 19:21
Ralf Schaa wrote:
>> if( var/var /= 1) then
>> write(*,*) 'This is a NAN or INF'
>> endif
>> i) can I test wether a real variable is a number with this test?
>> ii) or is it highly dependent on what platform/compiler you are
>> using ?
>> iii) does it always work?
On Jul 13, 12:02 pm, nos...@see.signature (Richard Maine) wrote:
> It is highly dependent on the platform and compiler. No, it doesn't
> always work. I wouldn't even count on it usually working. It is likely
> to cause an abort on some platforms.
[snip]
Thanks Richard and Tim.
It's never easy ...
|
| |
| no comments |
|
  |
Author: glen herrmannsfeldtglen herrmannsfeldt Date: Jul 12, 2007 20:03
Ralf Schaa wrote:
> looking at all the threads abouth this topic leaves me confused - I
> could not find an answer to the following question:
> if( var/var /= 1) then
> write(*,*) 'This is a NAN or INF'
> endif
> i) can I test wether a real variable is a number with this test?
(snip)
I thought the test for NaN was supposed to be var.ne.var, but compilers
might optimize that one away.
Are you only considered IEEE standard floating point? Without that
I don't believe you can safely test 0./0..
-- glen
|
| |
| no comments |
|
  |
Author: Ralf SchaaRalf Schaa Date: Jul 12, 2007 21:40
On Jul 13, 2:00 pm, glen herrmannsfeldt ugcs.caltech.edu> wrote:
[snip]
> Are you only considered IEEE standard floating point? Without that
> I don't believe you can safely test 0./0..
>
> -- glen
Glen,
the problem would concern F95 (as of 2006) and the Lahey v5.7
compilers on Windows PC's - if this is the right answer to that
question at all (?)
-Ralf
|
| |
| no comments |
|
  |
|
|
  |
|
|
  |
Author: Jan Gerrit KootstraJan Gerrit Kootstra Date: Jul 13, 2007 06:03
Ralf Schaa wrote:
> People,
>
> looking at all the threads abouth this topic leaves me confused - I
> could not find an answer to the following question:
>
>
> if( var/var /= 1) then
> write(*,*) 'This is a NAN or INF'
> endif
>
> i) can I test wether a real variable is a number with this test?
> ii) or is it highly dependent on what platform/compiler you are
> using ?
> iii) does it always work?
>
> Cheers
> -Ralf
>
Ralf, ...
|
| Show full article (0.84Kb) |
| no comments |
|
RELATED THREADS |
  |
|
|
|