public inbox for fortran@gcc.gnu.org
 help / color / mirror / Atom feed
* how *not* to use denormalised numbers?
@ 2015-11-10 14:41 Anton Shterenlikht
  2015-11-10 15:16 ` Steve Kargl
  0 siblings, 1 reply; 9+ messages in thread
From: Anton Shterenlikht @ 2015-11-10 14:41 UTC (permalink / raw)
  To: fortran

Are denormalised numbers supported by default by gfortran6 (or 5)?
My understanding was that the use has to request
the use of denormalised numbers explicitly, via USE statement,
e.g. MFE, p.225.

I have a program that does *not* USE ieee_features,
compiled by gfortran6 with these flags:

-fopenmp -fbacktrace -Wall

It returns (FreeBSD amd64):

Note: The following floating-point exceptions are signalling: IEEE_UNDERFLOW_FLAG IEEE_DENORMAL

suggesting denormalised numbers were used.

I don't want to use denormalised numbers.
A flash to zero is acceptable, provided
this will trigger underflow exception.
What gfortran option(s) will achieve this?

Thanks

Anton


^ permalink raw reply	[flat|nested] 9+ messages in thread
* Re: how *not* to use denormalised numbers?
@ 2015-11-10 16:59 Dominique d'Humières
  2015-11-10 18:14 ` Steve Kargl
  0 siblings, 1 reply; 9+ messages in thread
From: Dominique d'Humières @ 2015-11-10 16:59 UTC (permalink / raw)
  To: mexas; +Cc: sgk, nmm1@cam.ac.uk gfortran

Consider the following modification of the test

use ieee_arithmetic
logical :: gradual
  write (*,*) "Support underflow control:", &
              ieee_support_underflow_control()
  call ieee_get_underflow_mode( gradual )
  write (*,*) "Gradual underflow:", gradual
  write (*,*) "Support denormals:", ieee_support_denormal()
  print *, nearest(tiny(1.0d0), -1.0d0)
  print *, nearest(0.0d0, 1.0d0)
! flip underflow mode
  call ieee_set_underflow_mode( .not. gradual )
  call ieee_get_underflow_mode( gradual )
  write (*,*) "Gradual underflow:", gradual
  write (*,*) "Support denormals:", ieee_support_denormal()
  print *, nearest(tiny(1.0d0), -1.0d0)
  print *, nearest(0.0d0, 1.0d0)
end

Compiled with gfortran -O, it outputs

 Support underflow control: F
 Gradual underflow: T
 Support denormals: T
   2.2250738585072009E-308
   4.9406564584124654E-324
 Gradual underflow: F
 Support denormals: T
   2.2250738585072009E-308
   4.9406564584124654E-324

If compiled with -O -fast-math, the output is

 Support underflow control: F
 Gradual underflow: F
 Support denormals: T
   0.0000000000000000     
   0.0000000000000000     
 Gradual underflow: T
 Support denormals: T
   0.0000000000000000     
   0.0000000000000000     

IIRC correctly, this is documented somewhere in GCC, but I cannot find where. Indeed -fast-math has other side-effects and cannot be suitable.

Dominique



^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2015-11-10 19:55 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-11-10 14:41 how *not* to use denormalised numbers? Anton Shterenlikht
2015-11-10 15:16 ` Steve Kargl
2015-11-10 15:49   ` N.M. Maclaren
2015-11-10 16:27     ` Anton Shterenlikht
2015-11-10 16:50       ` FX
2015-11-10 17:11         ` N.M. Maclaren
2015-11-10 19:55           ` FX
2015-11-10 16:59 Dominique d'Humières
2015-11-10 18:14 ` Steve Kargl

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).