ISO/IEC JTC1/SC22/WG5 N1743 UK proposal for Gw and G0.d Formats This is one of the papers promised in the UK ballot, see N1740. It is written in the format of a new repository item. Number: UK-013 Title: Gw and G0.d Formats Submitted by: UK Status: Proposed in ballot Severity Level : 3 References: N1723, 08-251r3 Basic Functionality: Extend generalized output editing of real and complex data by defining G0.d to mean output in the smallest field width that shows the same number of significant digits as ESw.d editing (i.e., d+1 significant digits). Also, define G0 to mean G0.d where d has a reasonable processor-dependent value and Gw with w nonzero to mean output in a field of w character positions with as many significant digits as can be fitted into that width with G0.d editing. Rationale: Although Fortran already has good facilities for converting numerical information into formatted text, there are two situations sometimes encountered where a suitable format descriptor is currently lacking. (a) Writing as many significant digits as possible into a fixed-width field. This will be useful when writing large quantities of numerical data in tabular form when it is important to avoid excessive line length. (b) Writing a given number of significant digits into a field of minimum width. This will be useful when writing CSV files and other text files designed for ingestion by other software packages, and also when writing HTML tables and other human-readable files where the layout is determined by means outside of Fortran, but it is desirable to round the data to a specified level of precision. In this case also, file-size or line-length limits often make compact output formats desirable. Discussions on comp.lang.fortran and elsewhere indicate that many programmers have attempted to write procedures to remedy these defects using a complicated set of internal file writes. Such procedures are hard to use and not very efficient, and it is easy to fail to handle all the possible cases. A standard conversion by means of a dedicated edit descriptor would be more satisfactory in many ways. To illustrate these formats, here is a table showing the desirable output of an internal value N of approximately 1.23456789*10^J using the proposed G8 and G0.3 formats for a small range of values of J: J G8 G0.3 10 1.235e10 1.235e10 9 1.2346e9 1.235e9 8 1.2346e8 1.235e8 7 1.2346e7 1.235e7 6 1234568. 1.235e6 5 123456.8 1.235e5 4 12345.68 1.235e4 3 1234.568 1235. 2 123.4568 123.5 1 12.34568 12.35 0 1.234568 1.235 -1 .1234568 .1235 -2 1.235e-2 1.235e-2 -3 1.235e-3 1.235e-3 -4 1.235e-4 1.235e-4 -5 1.235e-5 1.235e-5 etc -10 1.23e-10 1.235e-10 The idea, in both cases, is to omit the sign from the number (and the exponent if present) if optional and to omit leading zeros from the exponent. We considered further reducing the length by omitting the letter "e" when followed by a - sign. This form is compatible with input, but the meaning is far less apparent to the reader and is not permitted for constants in source code. The G0 edit descriptor has been added in N1723 with the meaning that it is equivalent to ESw.dEe with reasonable processor-dependent values for w, d, and e [254:2]. We disagree with this choice. G edit descriptors are intended to use fixed format where possible and floating format otherwise. Furthermore, the US vote proposes to extend this to G0.d (see J3 paper 08-251r3). We disagree with this for the same reason. This proposal replaces both of these. Alternatives WG5 may wish to consider these alternatives. 1. Make d specify the number of significant decimals, as does Gw.d. 2. For the floating format, use ES without removing any redundant characters. 3. In the edits, spell out how d is chosen for Gw. Estimated Impact: Detailed Specification: [xiii:2] In Introduction, paragraph 2, bullet point Input/output, before "Recursive transfers" add "G0.d and Gw format descriptors give additional facilities for output of real and complex data." [243] In 10.3.2 Edit descriptors, delete C1007 (R1006). [254:2] In 10.7.5.2.2 Generalized real and complex editing, delete paragraph 2. [254:3] In 10.7.5.2.2 Generalized real and complex editing, paragraph 3 replace "Gw.d and" by "Gw, Gw.d, and". [254:4-6] In 10.7.5.2.2 Generalized real and complex editing, move the table in paragraph 5 to follow the first sentence of paragraph 4 and start a new paragraph after this. At the start of this new paragraph, change "If" to "When w>0 and d is present, if". Do not start new paragraphs where paragraphs 5 and 6 start now. [254:6+] In 10.7.5.2.2 Generalized real and complex editing, insert the following paragraphs after paragraph 6: "For the G0.d edit when N/=0, let n be such that 10^n <= N < 10^{n+1}. If n > d or n <= -1, the form of the output field is that of ESw.d editing for a very large value of w, except that leading blanks, + signs in the exponent, and leading zeros in the exponent are omitted. Otherwise, the output field is that of F(d+s+2).(d-n), where s = 1 if a sign is required because N is negative or sign mode is PLUS (9.5.6.7, 9.6.2.14), otherwise s = 0. For the G0.d edit when N=0, the output field is that of F0.0. For each output value, the form of the output field for the Gw edit descriptor when w>0 is that of G0.d, where d has the largest value that results in the number of characters produced being w or less. The form of the output field for the G0 edit descriptor is that of G0.d, where d has a reasonable processor-dependent value." [461] In A2 Processor dependencies, 10th last bullet, change "the field width used for the G0 edit descriptor (10.7.5)" to "the field width and the decimal part width used for the G0 edit descriptor (10.7.5)".