Opened 8 years ago

Last modified 8 years ago

#835 reopened defect

format function issue (floating point directive)

Reported by: eugu Owned by:
Priority: normal Milestone:
Component: ANSI CL Compliance Version: 1.6
Keywords: format Cc:

Description

Trying example from "Land of Lisp" book:

(format t " Percentages are ~,,2f percent better than fractions" .77) 

Output: Percentages are 0.77 percent better than fractions


Expected: Percentages are 77.0 percent better than fractions


According to CLHS: http://www.lispworks.com/documentation/HyperSpec/Body/22_cca.htm third arg to floating point directive is a scale factor which multiplies the value of arg times 10

Environment: MS Windows Vista SP2, CCL Version 1.6-r14468M (WindowsX8632)

Tried also in clisp and sbcl - both output according to spec

Change History (5)

comment:1 Changed 8 years ago by eugu

Corrected description: third parameter to floating point directive is a scale factor k which multiplies the value of arg times 10k

comment:2 follow-up: Changed 8 years ago by rme

On the other hand, 22.3.3.1 also says:

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).

Presumably, that text is the reason why ccl::format-fixed-aux does

(if (not (or w d))
  (prin1 number stream)
  ...)

comment:3 Changed 8 years ago by eugu

Oh, I see. It's possible to interpret spec that way, esp considering formatting. this way also work ecl, allegro-express

Another view is that the meaning of the k parameter is independent of the other two (w d) and described in the first paragraph. Following implementations understand it so as I checked: abcl clisp sbcl cmucl

So probably not a bug but a different reading

comment:4 Changed 8 years ago by eugu

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

comment:5 in reply to: ↑ 2 Changed 8 years ago by aidenn0

  • Resolution invalid deleted
  • Status changed from closed to reopened

I think this is a perverse reading of the specification. 22.3.3.1 doesn't say "arg" it says "the value" which in all other places in that section refers to arg scaled by 10k

For example: "If it is impossible to print the value in the required format in a field of width w" then..." clearly refers to the value as scaled by 10k

Note: See TracTickets for help on using tickets.