Opened 8 years ago

Closed 5 years ago

#880 closed defect (fixed)

~F format directive incorrectly uses exponential form when "w" and "d" are omitted.

Reported by: aidenn0 Owned by: rme
Priority: normal Milestone:
Component: ANSI CL Compliance Version: 1.7
Keywords: Cc:


From Section

If both w and d are omitted, then the effect is to print the value using ordinary free-format output; prin1 uses this format for any number whose magnitude is either zero or between 10-3 (inclusive) and 107 (exclusive).

free-format is defined in this section to be the same format used by prin1 for the range 10-3 through 107. This is covered in section

If the magnitude of the float is either zero or between 10-3 (inclusive) and 107 (exclusive), it is printed as the integer part of the number, then a decimal point, followed by the fractional part of the number; there is always at least one digit on each side of the decimal point. If the sign of the number (as determined by float-sign) is negative, then a minus sign is printed before the number. If the format of the number does not match that specified by *read-default-float-format*, then the exponent marker for that format and the digit 0 are also printed. For example, the base of the natural logarithms as a short float might be printed as 2.71828S0. does go on to say that if the width would be greater than 100, exponential notation may be used. However, it follows from the specification that (for example)

(format t "~F" 1e7)

should print:




Change History (2)

comment:1 Changed 5 years ago by rme

  • Owner set to rme

For a long time, I didn't understand this. I was interpreting to mean that then when both the w and d parameters are omitted, "~f" means to print the value like prin1 does. Since prin1 uses computerized scientific notation for numbers 1e7 and greater, I didn't see a problem.

But I think now that the spec is using the output of prin1 on numbers in [1e-3, 1e7) as an example of "ordinary free-form output". So, I now (finally) agree that (format t "~f" 1e7) should print 10000000.0.

comment:2 Changed 5 years ago by rme

  • Resolution set to fixed
  • Status changed from new to closed

(In [16338]) Pull out the code that prints a free-form floating-point number from print-a-float, and put it into a new helper function print-float-free-form-1.

New function print-float-free-form, which uses the above helper function.

Make format-fixed-aux (which handles "~f") call print-float-free-form instead of prin1 when the w and d parameters are null.

Closes ticket:880.

Note: See TracTickets for help on using tickets.