ifort functions for test NaN and Inf

This is a discussion on ifort functions for test NaN and Inf within the Fortran forums in Programming Languages category; Hello, Anybody knows an intrinsic function for testing if a variable is -+INF. I have found in the reference the function ISNAN but not the equivalent for INF. Thanks...

Go Back   Application Development Forum > Programming Languages > Fortran

Object Mix

Register FAQ Calendar Search Today's Posts Mark Forums Read
  #1  
Old 07-18-2007, 07:06 AM
ddb78s@gmail.com
Guest
 
Default ifort functions for test NaN and Inf


Hello,

Anybody knows an intrinsic function for testing if a variable is
-+INF. I have found in the reference the function ISNAN but not the
equivalent for INF.

Thanks

Reply With Quote
  #2  
Old 07-18-2007, 07:19 AM
Ian Bush
Guest
 
Default Re: ifort functions for test NaN and Inf


Hi,

As if by magic, ddb78s appeared !

>
> Anybody knows an intrinsic function for testing if a variable is
> -+INF. I have found in the reference the function ISNAN but not the
> equivalent for INF.


ISNAN is not standard. To perform either of these tests you will either
need a non-standard extension ( e.g. ISNAN ), so look in your compiler
docs, or, and much better, use the IEEE stuff in Fortran 2003. See
e.g.

http://docs.sun.com/app/docs/doc/819...7bsi97k?a=view

However your compiler might not support this yet,

Ian
Reply With Quote
  #3  
Old 07-18-2007, 09:02 AM
Tim Prince
Guest
 
Default Re: ifort functions for test NaN and Inf

Ian Bush wrote:
> Hi,
>
> As if by magic, ddb78s appeared !
>
>> Anybody knows an intrinsic function for testing if a variable is
>> -+INF. I have found in the reference the function ISNAN but not the
>> equivalent for INF.

>
> ISNAN is not standard. To perform either of these tests you will either
> need a non-standard extension ( e.g. ISNAN ), so look in your compiler
> docs, or, and much better, use the IEEE stuff in Fortran 2003. See
> e.g.
>
> http://docs.sun.com/app/docs/doc/819...7bsi97k?a=view
>
> However your compiler might not support this yet,
>


Of course, you can write such functions yourself.
Reply With Quote
  #4  
Old 07-18-2007, 10:12 AM
Herman D. Knoble
Guest
 
Default Re: ifort functions for test NaN and Inf

For information:

The latest Pathscale compiler (pathf90) compiles and run the following:
use ieee_arithmetic
..
..
..
if (ieee_is_nan(y(i))) then
....
endif

Latest Intel or g95 do not recognize resolutiion of the use statement.

Skip Knoble

On Wed, 18 Jul 2007 13:01:51 GMT, Tim Prince <timothyprince@sbcglobal.net> wrote:

-|Ian Bush wrote:
-|> Hi,
-|>
-|> As if by magic, ddb78s appeared !
-|>
-|>> Anybody knows an intrinsic function for testing if a variable is
-|>> -+INF. I have found in the reference the function ISNAN but not the
-|>> equivalent for INF.
-|>
-|> ISNAN is not standard. To perform either of these tests you will either
-|> need a non-standard extension ( e.g. ISNAN ), so look in your compiler
-|> docs, or, and much better, use the IEEE stuff in Fortran 2003. See
-|> e.g.
-|>
-|> http://docs.sun.com/app/docs/doc/819...7bsi97k?a=view
-|>
-|> However your compiler might not support this yet,
-|>
-|
-|Of course, you can write such functions yourself.

Reply With Quote
  #5  
Old 07-18-2007, 10:27 AM
Herman D. Knoble
Guest
 
Default Re: ifort functions for test NaN and Inf

I was wrong about g95. It does support logical function ieee_is_nan(x) and
companion use ieee_arithmetic.

Skip

On Wed, 18 Jul 2007 10:12:20 -0400, Herman D. Knoble <SkipKnobleLESS@SPAMpsu.DOT.edu>
wrote:

-|Latest Intel or g95 do not recognize resolutiion of the use statement.

Reply With Quote
  #6  
Old 07-18-2007, 04:07 PM
James Giles
Guest
 
Default Re: ifort functions for test NaN and Inf

Ian Bush wrote:
....
> As if by magic, ddb78s appeared !

....
>> Anybody knows an intrinsic function for testing if a variable
>> is -+INF. I have found in the reference the function ISNAN but not
>> the equivalent for INF.

>
> ISNAN is not standard. To perform either of these tests you will
> either need a non-standard extension ( e.g. ISNAN ), so look in your
> compiler docs, or, and much better, use the IEEE stuff in Fortran
> 2003. [...]


The two options are not mutually exclusive. I would recommend

USE IEEE_ARITHMETIC, &
ISNAN=>IEEE_IS_NAN, &
ISFINITE=>IEEE_IS_FINITE

That way you're not stuck with the unnecessarily verbose names.

--
J. Giles

"I conclude that there are two ways of constructing a software
design: One way is to make it so simple that there are obviously
no deficiencies and the other way is to make it so complicated
that there are no obvious deficiencies." -- C. A. R. Hoare


Reply With Quote
  #7  
Old 07-18-2007, 08:11 PM
John Harper
Guest
 
Default Re: ifort functions for test NaN and Inf

In article <hi8s93t18h4gqd8ukk3isbubuvkgpn7gkc@4ax.com>,
Herman D. Knoble <SkipKnobleLESS at SPAMpsu dot edu> wrote:
>I was wrong about g95. It does support logical function
>ieee_is_nan(x) and companion use ieee_arithmetic.


Note that parts of g95 ieee_arithmetic were wrong in versions before
17 July but are now right AFAIK. I had reported the bug that day, and
about 25 hours later Andy reported that he had fixed it, so still on
17 July in his time zone:-) Look at the timestamp before downloading:
g95 of 2007-07-17 21:52 or later will have been fixed.

-- John Harper, School of Mathematics, Statistics and Computer Science,
Victoria University, PO Box 600, Wellington 6140, New Zealand
e-mail john.harper@vuw.ac.nz phone (+64)(4)463 5341 fax (+64)(4)463 5045
Reply With Quote
  #8  
Old 07-19-2007, 07:22 AM
highegg
Guest
 
Default Re: ifort functions for test NaN and Inf

On Jul 18, 1:06 pm, "ddb..." <ddb...> wrote:
> Hello,
>
> Anybody knows an intrinsic function for testing if a variable is
> -+INF. I have found in the reference the function ISNAN but not the
> equivalent for INF.
>
> Thanks


The preferable way is the F2003's ieee_is_finite(x). If that's not
supported by your compiler, then a reasonably good replacement is
abs(x) <= huge(x).
This typically works reliably (i.e. regardless of optimization level)
with finite numbers and +-Inf, but not with NaN.
So if NaN is already ruled out (e.g. by isnan), then it's OK. If not,
then perhaps
..not. (abs(x) > huge(x))
may be better, but I would not bet much on magic like that. Of course,
various NaN test like x /= x are not reliable either.

Reply With Quote
  #9  
Old 07-19-2007, 07:48 AM
highegg
Guest
 
Default Re: ifort functions for test NaN and Inf

On Jul 18, 1:06 pm, "ddb..." <ddb...> wrote:
> Hello,
>
> Anybody knows an intrinsic function for testing if a variable is
> -+INF. I have found in the reference the function ISNAN but not the
> equivalent for INF.
>
> Thanks


I'd recommend you to simulate the F2003's
ieee_is_nan and ieee_is_finite, which are the standard way to achieve
this:
elemental logical function ieee_is_nan(x)
real,intent(in):: x
ieee_is_nan = isnan(x)
end function
elemental logical function ieee_is_finite(x)
real,intent(in):: x
ieee_is_finite = .not. (isnan(x) .or. abs(x) > huge(x))
end function

this is a reasonably reliable replacement (always worked for me on
g95, Intel and EkoPath, regardless of optimization level),
and once the IEEE modules are supported by intel, you simply remove
the definitions.

HTH,
Jaroslav

Reply With Quote
  #10  
Old 07-19-2007, 09:43 AM
Steve Lionel
Guest
 
Default Re: ifort functions for test NaN and Inf

On Jul 18, 7:06 am, "ddb..." <ddb...> wrote:

> Anybody knows an intrinsic function for testing if a variable is
> -+INF. I have found in the reference the function ISNAN but not the
> equivalent for INF.


See the FP_CLASS intrinsic (an extension).

Steve

Reply With Quote
Reply


Thread Tools
Display Modes


All times are GMT -5. The time now is 05:53 AM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
vB Ad Management by =RedTyger=

In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.