[J3] defining a parameter to be signaling NaN?

Bill Long longb at cray.com
Tue May 22 16:35:56 EDT 2018


> On May 22, 2018, at 3:03 PM, Robert Corbett via J3 <j3 at mailman.j3-fortran.org> wrote:
> 
> I cannot think of a portable way to initialize variables to signaling NaNs, even for processors that implement the highest level of IEEE support defined by the standard.  As Bill noted, REAL with an appropriate BOZ constant as the first argument might work, but it is not portable.  TRANSFER is another possibility.
> 
> The standard permits the expression
> 
> IEEE_VALUE(0.0,IEEE_SIGNALING_NAN)
> 
> to produce a quiet NaN.  IIRC, this behavior was added as a result of an interpretation.

The standard does say that, but there is a NOTE just following that says:

"If the expr in an assignment statement is a reference to the IEEE_VALUE function that returns a signaling NaN and the variable is of the same type and kind as the function result, it is recommended that the signaling NaN be preserved."

IEEE_VALUE is pretty useless for a processor that does not follow that recommendation.  I assume “assignment statement” would include an initialization as well, if this reference is allowed as the constant expression in an initialization. 

> 
> I was not yet a member of the committee when the ability to include references to functions defined in the IEEE modules in constant expressions was added to the standard.  I do not see a technical reason to prohibit using IEEE_VALUE in a constant expression.

Agreed. 

> 
> While I am flattered to be designated Dr. IEEE, my talent in that area is that I know how to contact members of the IEEE floating-point committee when I have questions about the IEEE standard.

It’s all relative.  An “expert” is someone who knows \epsilon more than the person he’s (she’s) talking to. 

I assume you will be able to make it to the WG5 meeting next month.  See you there!


Cheers,
Bill

> 
> Bob Corbett
> 
> On May 22, 2018, at 11:17 AM, Clune, Thomas L. (GSFC-6101) via J3 <j3 at mailman.j3-fortran.org> wrote:
> 
>> 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> wrote:
>>> 
>>>> 
>>>> On May 22, 2018, at 7:39 AM, Clune, Thomas L. (GSFC-6101) via J3 <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
>>> 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
>> 

Bill Long                                                                       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




More information about the J3 mailing list