Re: Portable isfinite for gfortran 4.0.3 and ifort 8.1/9.0
- From: "Joost" <jv244@xxxxxxxxx>
- Date: 15 Jul 2006 04:46:24 -0700
The following can often be used to do so. I tested g95 and ifort 9.0.
! false for +inf, -inf and nans if things don't trap
LOGICAL FUNCTION isfinite(a)
REAL :: a
isfinite = (a-a).EQ.0
END FUNCTION isfinite
LOGICAL :: isfinite
write(6,*) isfinite(1.0/1.0)
write(6,*) isfinite(1.0/0.0)
write(6,*) isfinite(0.0/0.0)
END
You can use optimisation (e.g. -O3) but with ifort you need the flag
-mp while you should not use -ffast-math if using g95. Needless to say
that the above is not foolproof if compiled with random compiler
options or compilers.
BTW: Is it possible to determine the name of the compiler from inside
the code?
sometimes it is possible in combination with preprocessing. E.g. :
#if defined(__G95__)
write(6,*) " g95 in use"
#fi
will include the write statement if you use 'g95 -cpp' to compile (or
use .F90 as a filename extension) whereas the line will not be present
if you preprocess with a different compiler. Other compilers have
similar features.
Cheers,
Joost
.
- References:
- Portable isfinite for gfortran 4.0.3 and ifort 8.1/9.0
- From: Niels L Ellegaard
- Portable isfinite for gfortran 4.0.3 and ifort 8.1/9.0
- Prev by Date: Portable isfinite for gfortran 4.0.3 and ifort 8.1/9.0
- Next by Date: Re: Algorithm for distance from point to function
- Previous by thread: Portable isfinite for gfortran 4.0.3 and ifort 8.1/9.0
- Next by thread: Re: Portable isfinite for gfortran 4.0.3 and ifort 8.1/9.0
- Index(es):
Relevant Pages
|