a simple overflow example

  • Follow


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:

C:\MinGW\source>g95 float1.f90 -Wall -Wextra -o out
In file float1.f90:11

  IEEE_SUPPORT_HALTING(IEEE_OVERFLOW)) then
  1
Warning (165): Implicit interface 'ieee_support_halting' called at (1)
In file float1.f90:14

call IEEE_SET_HALTING_MODE(IEEE_OVERFLOW, .false. )
     1
Error: Too many arguments in call to 'ieee_set_halting_mode' at (1)

C:\MinGW\source>type float1.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
implicit none

real x, y, z
logical :: overflow_flag, IEEE_SUPPORT_HALTING

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


endprogram

! g95 float1.f90 -Wall -Wextra -o out

C:\MinGW\source>

I seem to have at least 2 problems, according to my compiler.  I can't
really tell what ieee_support_halting wants to be.  P. 540 lists
ieee_set_halting_mode with 2 arguments, so I'm stumped and fishing for
tips.

Thanks for your comment.
0
Reply merrill (193) 9/8/2009 3:54:12 PM

In article 
<e59a6bcb-a79c-4680-8c8b-be20a6542985@f20g2000prn.googlegroups.com>,
 Frank <merrill@lomas-assault.net> wrote:

> 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
[...]
> if(IEEE_SUPPORT_DATATYPE(x) .and. &
>   IEEE_SUPPORT_HALTING(IEEE_OVERFLOW)) then
[...]

I don't think I can answer your question, but it is clear that the 
function IEEE_SUPPORT_HALTING() is not in scope, so that looks like 
an error.  If it does exist in one of the above modules, it is being 
hidden with the ONLY clauses.  That function probably needs to be 
added to one of the ONLY lists.

$.02 -Ron Shepard
0
Reply ron-shepard (1197) 9/8/2009 5:29:58 PM


On Sep 8, 10:29=A0am, Ron Shepard <ron-shep...@NOSPAM.comcast.net>
wrote:
> In article
> <e59a6bcb-a79c-4680-8c8b-be20a6542...@f20g2000prn.googlegroups.com>,
>
> =A0Frank <merr...@lomas-assault.net> wrote:
> > use IEEE_FEATURES, only : IEEE_DATATYPE
> > use IEEE_ARITHMETIC, only : IEEE_SUPPORT_DATATYPE
> > use IEEE_EXCEPTIONS, only: IEEE_OVERFLOW, &
> > =A0 =A0IEEE_GET_FLAG, IEEE_SET_HALTING_MODE
> [...]
> > if(IEEE_SUPPORT_DATATYPE(x) .and. &
> > =A0 IEEE_SUPPORT_HALTING(IEEE_OVERFLOW)) then
>
> [...]
>
> I don't think I can answer your question, but it is clear that the
> function IEEE_SUPPORT_HALTING() is not in scope, so that looks like
> an error. =A0If it does exist in one of the above modules, it is being
> hidden with the ONLY clauses. =A0That function probably needs to be
> added to one of the ONLY lists.
>
> $.02 -Ron Shepard

That seems to be right, but I have other problems:

C:\MinGW\source> g95 float2.f90 -Wall -Wextra -o out
In file float2.f90:15

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

C:\MinGW\source>type float2.f90
use IEEE_FEATURES, only : IEEE_DATATYPE
use IEEE_ARITHMETIC, only : IEEE_SUPPORT_DATATYPE, &
   IEEE_SUPPORT_HALTING, IEEE_SUPPORT_STANDARD
use IEEE_EXCEPTIONS, only: IEEE_OVERFLOW, &
   IEEE_GET_FLAG, IEEE_SET_HALTING_MODE
implicit none

real x, y, z
logical :: overflow_flag

if(IEEE_SUPPORT_DATATYPE(x)) then
   print *, "so far so good"
endif

if(IEEE_SUPPORT_HALTING(IEEE_OVERFLOW)) then
  print *, "still alright"
endif

endprogram

! g95 float2.f90 -Wall -Wextra -o out

C:\MinGW\source>

How do I find these modules with g95 to read what they actually have
in them?
0
Reply merrill (193) 9/8/2009 6:45:05 PM

On Sep 8, 8:54 am, Frank <merr...@lomas-assault.net> 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:
>
> C:\MinGW\source>g95 float1.f90 -Wall -Wextra -o out
> In file float1.f90:11
>
>   IEEE_SUPPORT_HALTING(IEEE_OVERFLOW)) then
>   1
> Warning (165): Implicit interface 'ieee_support_halting' called at (1)
> In file float1.f90:14
>
> call IEEE_SET_HALTING_MODE(IEEE_OVERFLOW, .false. )
>      1
> Error: Too many arguments in call to 'ieee_set_halting_mode' at (1)
>
> C:\MinGW\source>type float1.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
> implicit none
>
> real x, y, z
> logical :: overflow_flag, IEEE_SUPPORT_HALTING
>
> 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
>
> endprogram
>
> ! g95 float1.f90 -Wall -Wextra -o out
>
> C:\MinGW\source>
>
> I seem to have at least 2 problems, according to my compiler.  I can't
> really tell what ieee_support_halting wants to be.  P. 540 lists
> ieee_set_halting_mode with 2 arguments, so I'm stumped and fishing for
> tips.
>
> Thanks for your comment.


One of the problems is easily fixed.  Add IEEE_SUPPORT_HALTING
to the ONLY list for IEEE_EXCEPTIONS.

Bob Corbett
0
Reply robert.corbett2 (862) 9/8/2009 6:56:31 PM

Hello,

On 2009-09-08 14:45:05 -0400, Frank <merrill@lomas-assault.net> said:

> How do I find these modules with g95 to read what they actually have
> in them?

Intrinsic modules are magic and need not exist anywhere.
If they do exist, they might be encoded so you can't read them.

There might be several versions, with one selected depending
upon compiler options or other incantations.

You might want to use ieee_selected_real_kind()
to get the right kind value for your reals.

HTH

-- 
Cheers!

Dan Nagle

0
Reply dannagle (1019) 9/8/2009 7:51:22 PM

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
0
Reply Steve.Lionel5921 (403) 9/8/2009 8:04:35 PM

On Sep 8, 1:04 pm, Steve Lionel <steve.lio...@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
0
Reply robert.corbett2 (862) 9/9/2009 1:45:31 AM

On Sep 8, 6:45=A0pm, robert.corb...@sun.com wrote:
> On Sep 8, 1:04 pm, Steve Lionel <steve.lio...@intel.invalid> wrote:
>
>
>
> > Frank wrote:
> > > I wanted to work up a facility to deal with floating point exceptions
> > > in fortran. =A0P. 557 of the _Handbook_ has the following source.
> > > Gfortran does not have the modules used. =A0G95 seems to, but I can't
> > > understand the errors I'm getting without thinking that they might no=
t
> > > be complete:
>
> > Your example has two errors. =A0Bob Corbett found one, I found another
> > (incorrect syntax for a PRINT statement.) =A0Here 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, &
> > =A0 =A0 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. &
> > =A0 =A0IEEE_SUPPORT_HALTING(IEEE_OVERFLOW)) then
> > =A0 =A0 =A0 read *, x, y
>
> > call IEEE_SET_HALTING_MODE(IEEE_OVERFLOW, .false. )
>
> > z =3D x * y
> > call IEEE_GET_FLAG(IEEE_OVERFLOW, overflow_flag )
> > if (overflow_flag) then
> > =A0 =A0 print *, "overflow"
> > else
> > =A0 =A0print *, "no overflow"
> > =A0 =A0print *, x, y, z
> > endif
>
> > else
> > =A0 =A0print *, "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. =A0The standard says
>
> =A0 =A0 The default-char-expr shall evaluate to a valid
> =A0 =A0 format specification
>
> The word "evaluate" is the key. =A0The 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 =3D 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.
0
Reply merrill (193) 9/9/2009 1:57:41 AM

On Sep 8, 6:57 pm, Frank <merr...@lomas-assault.net> wrote:
> On Sep 8, 6:45 pm, robert.corb...@sun.com wrote:
>
>
>
> > On Sep 8, 1:04 pm, Steve Lionel <steve.lio...@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
0
Reply robert.corbett2 (862) 9/9/2009 2:19:44 AM

8 Replies
44 Views

(page loaded in 0.099 seconds)

Similiar Articles:













7/28/2012 2:03:19 PM


Reply: