To: J3 J3/18-278r1 From: Robert Corbett Subject: sign of zero on write Date: 2018-October-18 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.0 and -0.0 to write the sign '-' for -0.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. References are to 18-007r1. 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.0 and -0.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 might be called "zero sign 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 sign 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. The edit descriptors ZN, ZP, and ZS set the zero sign mode to the values NONE, PLUS, and SIGN, respectively. The zero sign mode affects formatted output of data whose internal values are floating-point zeros only. The zero sign mode NONE takes precedence over the sign mode (13.8.4) when a floating-point zero is written. If the zero sign mode is NONE, no sign shall be written for a floating-point zero, regardless of the sign mode. If the zero sign mode is PLUS, a zero, including -0.0, shall write the sign '+' if the sign mode would write a sign for a positive value. If the zero sign mode is SIGN, the sign of -0.0 shall be written as if it were negative value, and the sign of +0.0 shall be written as if it were a positive value. If the processor does not distinguish between +0.0 and -0.0, all floating-point zeros are written as if they are +0.0.