To: J3 J3/18-278
From: Robert Corbett
Subject: sign of zero on write
Date: 2018-October-17
1. Introduction
The Fortran standards up to Fortran 90 treated the sign of a
floating-point zero in formatted output the same as the sign of a
positive value. If a sign was written for a zero, it was '+'.
Subsequent Fortran standards require processors that distinguish
between +0 and -0 to write the sign '-' for -0. For the sake of
backward compatibility, some implementations provide an option
that tells the processor to write floating-point zeros using the
old rules.
This paper proposes a language extension to allow a user to choose
how he or she wants the sign of a floating-point zero to be
treated during formatted output.
2. Use Cases
The extension proposed here would allow a user to specify
compatibility with programs that were compiled with older
implementations. It also allows user to specify consistent
treatment of floating-point zero between implementations that do
and do not distinguish between +0 and -0, which could be useful
for testing. An additional way of treating zeros is proposed for
the purpose of writing tables of floating-point values.
3. Requirements
A new changeable mode (12.5.2) is to be added. It could be called
"zero mode". The mode could be specified in OPEN statements and
WRITE statements and could be accessed in INQUIRE statements. The
mode for an output statement with an explicit format could be
overridden by a control edit descriptor. The mode would affect
list-directed and namelist output as well as output with an
explicit format.
4. Possible Syntax and Semantics
The form of the specifier for the zero mode might be "ZERO_SIGN=".
The possible values might be PLUS, SIGN, and NONE. The value PLUS
would mean that the sign of a floating-point zero should be treated
the same as the sign of a positive value. The value SIGN would
mean that a processor that distinguishes between +0 and -0 should
treat the sign of +0 the same as the sign of a positive value and
the sign of -0 the same as a sign of a negative value. For a
processor that does not distinguish between +0 and -0, the values
PLUS and SIGN have the same effect.
The value NONE specifies that when a floating-point zero is written
using formatted output, no sign is to be written. This mode could
be used in combination with the sign mode PLUS to distinguish zeros
from small nonzero values when writing using F edit descriptors.
Some tables of mathematical values use such a convention. For
example, a column in a table might contain the values
+.00021
+.00002
+.00000
.00000
-.00000
-.00001
Here +.00000 represents a small positive value, .00000 represents
zero and -.00000 represents a small magnitude negative value.
The forms ZN, ZP, and ZS might be used as the control edit
descriptors.