From: Steve Lionel on
Frank wrote:
> I wanted to work up a facility to deal with floating point exceptions
> in fortran. P. 557 of the _Handbook_ has the following source.
> Gfortran does not have the modules used. G95 seems to, but I can't
> understand the errors I'm getting without thinking that they might not
> be complete:

Your example has two errors. Bob Corbett found one, I found another
(incorrect syntax for a PRINT statement.) Here is a corrected source
which builds and runs with Intel Fortran:

use IEEE_FEATURES, only : IEEE_DATATYPE
use IEEE_ARITHMETIC, only : IEEE_SUPPORT_DATATYPE
use IEEE_EXCEPTIONS, only: IEEE_OVERFLOW, &
IEEE_GET_FLAG, IEEE_SET_HALTING_MODE, IEEE_SUPPORT_HALTING
implicit none

real x, y, z
logical :: overflow_flag

if(IEEE_SUPPORT_DATATYPE(x) .and. &
IEEE_SUPPORT_HALTING(IEEE_OVERFLOW)) then
read *, x, y

call IEEE_SET_HALTING_MODE(IEEE_OVERFLOW, .false. )

z = x * y
call IEEE_GET_FLAG(IEEE_OVERFLOW, overflow_flag )
if (overflow_flag) then
print *, "overflow"
else
print *, "no overflow"
print *, x, y, z
endif

else
print *, "no overflow support"
endif


end program
From: robert.corbett on
On Sep 8, 1:04 pm, Steve Lionel <steve.lio...(a)intel.invalid> wrote:
> Frank wrote:
> > I wanted to work up a facility to deal with floating point exceptions
> > in fortran. P. 557 of the _Handbook_ has the following source.
> > Gfortran does not have the modules used. G95 seems to, but I can't
> > understand the errors I'm getting without thinking that they might not
> > be complete:
>
> Your example has two errors. Bob Corbett found one, I found another
> (incorrect syntax for a PRINT statement.) Here is a corrected source
> which builds and runs with Intel Fortran:
>
> use IEEE_FEATURES, only : IEEE_DATATYPE
> use IEEE_ARITHMETIC, only : IEEE_SUPPORT_DATATYPE
> use IEEE_EXCEPTIONS, only: IEEE_OVERFLOW, &
> IEEE_GET_FLAG, IEEE_SET_HALTING_MODE, IEEE_SUPPORT_HALTING
> implicit none
>
> real x, y, z
> logical :: overflow_flag
>
> if(IEEE_SUPPORT_DATATYPE(x) .and. &
> IEEE_SUPPORT_HALTING(IEEE_OVERFLOW)) then
> read *, x, y
>
> call IEEE_SET_HALTING_MODE(IEEE_OVERFLOW, .false. )
>
> z = x * y
> call IEEE_GET_FLAG(IEEE_OVERFLOW, overflow_flag )
> if (overflow_flag) then
> print *, "overflow"
> else
> print *, "no overflow"
> print *, x, y, z
> endif
>
> else
> print *, "no overflow support"
> endif
>
> end program


It is a subtle point, one of little worth, but technically
the print statement in the original program is standard
conformant unless it is executed. The standard says

The default-char-expr shall evaluate to a valid
format specification

The word "evaluate" is the key. The default-char-expr is
not evaluated until the statement is executed.

Bob Corbett
From: Frank on
On Sep 8, 6:45 pm, robert.corb...(a)sun.com wrote:
> On Sep 8, 1:04 pm, Steve Lionel <steve.lio...(a)intel.invalid> wrote:
>
>
>
> > Frank wrote:
> > > I wanted to work up a facility to deal with floating point exceptions
> > > in fortran.  P. 557 of the _Handbook_ has the following source.
> > > Gfortran does not have the modules used.  G95 seems to, but I can't
> > > understand the errors I'm getting without thinking that they might not
> > > be complete:
>
> > Your example has two errors.  Bob Corbett found one, I found another
> > (incorrect syntax for a PRINT statement.)  Here is a corrected source
> > which builds and runs with Intel Fortran:
>
> > use IEEE_FEATURES, only : IEEE_DATATYPE
> > use IEEE_ARITHMETIC, only : IEEE_SUPPORT_DATATYPE
> > use IEEE_EXCEPTIONS, only: IEEE_OVERFLOW, &
> >     IEEE_GET_FLAG, IEEE_SET_HALTING_MODE, IEEE_SUPPORT_HALTING
> > implicit none
>
> > real x, y, z
> > logical :: overflow_flag
>
> > if(IEEE_SUPPORT_DATATYPE(x) .and. &
> >    IEEE_SUPPORT_HALTING(IEEE_OVERFLOW)) then
> >       read *, x, y
>
> > call IEEE_SET_HALTING_MODE(IEEE_OVERFLOW, .false. )
>
> > z = x * y
> > call IEEE_GET_FLAG(IEEE_OVERFLOW, overflow_flag )
> > if (overflow_flag) then
> >     print *, "overflow"
> > else
> >    print *, "no overflow"
> >    print *, x, y, z
> > endif
>
> > else
> >    print *, "no overflow support"
> > endif
>
> > end program
>
> It is a subtle point, one of little worth, but technically
> the print statement in the original program is standard
> conformant unless it is executed.  The standard says
>
>     The default-char-expr shall evaluate to a valid
>     format specification
>
> The word "evaluate" is the key.  The default-char-expr is
> not evaluated until the statement is executed.
>
> Bob Corbett

Bob, does sun fortran run the above? By what I could scrape off the
net, it looks like Intel and HP have this working.


C:\q\dan>g95 float3.f90 -Wall -Wextra -o out
In file float3.f90:11

IEEE_SUPPORT_HALTING(IEEE_OVERFLOW)) then
1
Error: Too many arguments in call to 'ieee_support_halting' at (1)


C:\q\dan>type float3.f90
use IEEE_FEATURES, only : IEEE_DATATYPE
use IEEE_ARITHMETIC, only : IEEE_SUPPORT_DATATYPE
use IEEE_EXCEPTIONS, only: IEEE_OVERFLOW, &
IEEE_GET_FLAG, IEEE_SET_HALTING_MODE, IEEE_SUPPORT_HALTING
implicit none

real x, y, z
logical :: overflow_flag

if(IEEE_SUPPORT_DATATYPE(x) .and. &
IEEE_SUPPORT_HALTING(IEEE_OVERFLOW)) then
read *, x, y

call IEEE_SET_HALTING_MODE(IEEE_OVERFLOW, .false. )

z = x * y
call IEEE_GET_FLAG(IEEE_OVERFLOW, overflow_flag )
if (overflow_flag) then
print *, "overflow"
else
print *, "no overflow"
print *, x, y, z
endif

else
print *, "no overflow support"
endif

end program

! g95 float3.f90 -Wall -Wextra -o out
C:\q\dan>

This looks like a bug in g95.
From: robert.corbett on
On Sep 8, 6:57 pm, Frank <merr...(a)lomas-assault.net> wrote:
> On Sep 8, 6:45 pm, robert.corb...(a)sun.com wrote:
>
>
>
> > On Sep 8, 1:04 pm, Steve Lionel <steve.lio...(a)intel.invalid> wrote:
>
> > > Frank wrote:
> > > > I wanted to work up a facility to deal with floating point exceptions
> > > > in fortran. P. 557 of the _Handbook_ has the following source.
> > > > Gfortran does not have the modules used. G95 seems to, but I can't
> > > > understand the errors I'm getting without thinking that they might not
> > > > be complete:
>
> > > Your example has two errors. Bob Corbett found one, I found another
> > > (incorrect syntax for a PRINT statement.) Here is a corrected source
> > > which builds and runs with Intel Fortran:
>
> > > use IEEE_FEATURES, only : IEEE_DATATYPE
> > > use IEEE_ARITHMETIC, only : IEEE_SUPPORT_DATATYPE
> > > use IEEE_EXCEPTIONS, only: IEEE_OVERFLOW, &
> > > IEEE_GET_FLAG, IEEE_SET_HALTING_MODE, IEEE_SUPPORT_HALTING
> > > implicit none
>
> > > real x, y, z
> > > logical :: overflow_flag
>
> > > if(IEEE_SUPPORT_DATATYPE(x) .and. &
> > > IEEE_SUPPORT_HALTING(IEEE_OVERFLOW)) then
> > > read *, x, y
>
> > > call IEEE_SET_HALTING_MODE(IEEE_OVERFLOW, .false. )
>
> > > z = x * y
> > > call IEEE_GET_FLAG(IEEE_OVERFLOW, overflow_flag )
> > > if (overflow_flag) then
> > > print *, "overflow"
> > > else
> > > print *, "no overflow"
> > > print *, x, y, z
> > > endif
>
> > > else
> > > print *, "no overflow support"
> > > endif
>
> > > end program
>
> > It is a subtle point, one of little worth, but technically
> > the print statement in the original program is standard
> > conformant unless it is executed. The standard says
>
> > The default-char-expr shall evaluate to a valid
> > format specification
>
> > The word "evaluate" is the key. The default-char-expr is
> > not evaluated until the statement is executed.
>
> > Bob Corbett
>
> Bob, does sun fortran run the above? By what I could scrape off the
> net, it looks like Intel and HP have this working.

The modified version of the prgram compiles and runs
using Sun f90/f95.

Bob Corbett