[J3] defining a parameter to be signaling NaN?
Clune, Thomas L. (GSFC-6101)
thomas.l.clune at nasa.gov
Tue May 22 14:17:58 EDT 2018
Bill,
Thanks. We want it as a parameter so that it can be used to initialize other quantities. Doing it as a protected module variable is a bit late-in-the-day.
In practice, compiler flags can be used to accomplish much the same, but we’d like use the standard itself where possible. Uninitialized quantities continue to be a not-too-uncommon source of bugs.
- Tom
On May 22, 2018, at 11:48 AM, Bill Long via J3 <j3 at mailman.j3-fortran.org<mailto:j3 at mailman.j3-fortran.org>> wrote:
On May 22, 2018, at 7:39 AM, Clune, Thomas L. (GSFC-6101) via J3 <j3 at mailman.j3-fortran.org<mailto:j3 at mailman.j3-fortran.org>> wrote:
A colleague was asking me about why the following code is not conforming
(assuming the appropriate USE statements):
real, parameter :: my_snan = ieee_value(0.0,ieee_signaling_nan)
This seems to work:
real :: my_snan
my_snan = ieee_value(0.0,ieee_signaling_nan)
The standard does note that the types and procedures in the intrinsic IEEE
modules are not themselves intrinsic, and thus the expression is not suitable for defining a PARAMETER.
Transformational functions from IEEE_ARITHMETIC are allowed:
• a reference to a transformational function from the intrinsic module IEEE_ARITHMETIC or IEEE_EXCEPTIONS, where each argument is a constant expression,
But IEEE_VALUE is elemental.
In practice, I don’t see a problem with allowing IEEE_VALUE in a constant expression. Maybe Bob (aka Dr. IEEE) has a reason that’s not obvious to me.
If, for some reason, a named constant is urgently needed (as opposed to a module variable with the PROTECTED attribute), then you could try
real,parameter :: my_snan = real(Z"7F800001”)
which assumes a particular representation for an SNAN.
Why the interest in a named constant for a signaling NaN? Comparing another value for equal to that constant is not useful.
Cheers,
Bill
First, is this explanation correct?
Second, presuming that the explanation is correct, was this our intent?
Is there a reasonably way to set a parameter to a signaling nan value, or do we need to propagate the longer expression to various parts of our code? Or could additional intrinsics be defined such as IEEE_SIGNALING_NAN_REAL32?
Thanks,
- Tom
Bill Long longb at cray.com<mailto:longb at cray.com>
Principal Engineer, Fortran Technical Support & voice: 651-605-9024
Bioinformatics Software Development fax: 651-605-9143
Cray Inc./ 2131 Lindau Lane/ Suite 1000/ Bloomington, MN 55425
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.j3-fortran.org/pipermail/j3/attachments/20180522/c1d5a6c9/attachment-0001.html>
More information about the J3
mailing list