To: J3 J3/18-268 From: Steve Lionel Subject: Control of leading zero in formatted numeric output Date: 2018-October-15 Reference: 18-007r1, 18-120r3, 18-010 Overview -------- When using F format to output a value less than 1, the standard allows the implementation to choose whether to include a zero before the decimal symbol. 13.7.2.3.2 (F format) paragraph 11 says (in part): "Leading zeros are not permitted except for an optional zero immediately to the left of the decimal symbol if the magnitude of the value in the output field is less than one. The optional zero shall appear if there would otherwise be no digits in the output field." Similarly for E and D formats, when the scale factor is zero, 13.7.2.3.2p11 says: "Leading zeros are not permitted except for an optional zero immediately to the left of the decimal symbol if the magnitude of the value in the output field is less than one. The optional zero shall appear if there would otherwise be no digits in the output field." EN, ES and EX formats do not have this option. Some implementations always provide the leading zeros, some do not, and this inconsistency results in user complaints, especially when test programs produce different results across different implementations. The inconsistency also occurs for G format when the value is in a certain range, since E and F formatting is used. Unlike the optional sign before a positive value, there is no user control over the optional zero. Use Cases --------- Many users have complained over the years that this inconsistency makes it difficult to automatically validate results across different implementations and, in some cases where the leading zero is omitted, makes the output from a Fortran application unusable by applications written in other languages. At meeting 215, J3 agreed to add "leading zero format control" to its work list for Fortran 202x. Requirements ------------ - Add control edit descriptors, analogous to the SS, SP and S edit descriptors, allowing the programmer to specify whether a leading zero is to appear in output for the F, E, D and G formats in the cases where it is currently optional. The requirement of the leading zero when otherwise no digits would appear is to remain. As with the existing S control descriptor, one of the new descriptors selects the implementation-defined behavior, which remains the default. - Continuing the analogy with SS, SP and S, and the SIGN= OPEN/INQUIRE specifier, add a new specifier to OPEN and INQUIRE to allow specification or inquiry of the current mode. Like SIGN=, this is to be a "changeable mode" (12.5.2p1). List-directed and namelist- directed output are to use the current "leading zero" mode.