From: Sam Steingold
Subject: format ~f with width
Date: 
Message-ID: <uelpf859m.fsf@xchange.com>
What is the right way to print floats which do not fit into the
specified width with ~f?
I thought the answer was obvious (after all, the spec is fairly clear on
the matter!) but then I discovered these:

ACL6:   (format nil "~2f" 123456.123) ==> "100000."
LWW:    (format nil "~2f" 123456.123) ==> "123456."
CMUCL:  (format nil "~2f" 123456.123) ==> "100000."
CLISP:  (format nil "~2f" 123456.123) ==> "100000."
Corman: (format nil "~2f" 123456.123) ==> "100000."

naively, I think the LWW way is the right one (and as a user I would
have preferred it), but I can understand the other answer too and the
fact that most implementations return it is somewhat sad.

So what is "the right way"?

-- 
Sam Steingold (http://www.podval.org/~sds)
Support Israel's right to defend herself! <http://www.i-charity.com/go/israel>
Read what the Arab leaders say to their people on <http://www.memri.org/>
Takeoffs are optional.  Landings are mandatory.
From: Thomas A. Russ
Subject: Re: format ~f with width
Date: 
Message-ID: <ymik7z7540u.fsf@sevak.isi.edu>
Sam Steingold <···@gnu.org> writes:
> What is the right way to print floats which do not fit into the
> specified width with ~f?
> I thought the answer was obvious (after all, the spec is fairly clear on
> the matter!) but then I discovered these:
> 
> ACL6:   (format nil "~2f" 123456.123) ==> "100000."
> LWW:    (format nil "~2f" 123456.123) ==> "123456."
> CMUCL:  (format nil "~2f" 123456.123) ==> "100000."
> CLISP:  (format nil "~2f" 123456.123) ==> "100000."
> Corman: (format nil "~2f" 123456.123) ==> "100000."

  MCL4.3.1: (format nil "~2f" 123456.123) ==> "100000.0"  (!)

> naively, I think the LWW way is the right one (and as a user I would
> have preferred it), but I can understand the other answer too and the
> fact that most implementations return it is somewhat sad.

I would have to agree with Sam that it would appear that the Spec was
fairly clear that LWW is correct and the other implmentations are
buggy.  The relevant passages from the Hyperspec are:

  The full form is ~w,d,k,overflowchar,padcharF. The parameter w is the
  width of the field to be printed; d is the number of digits to print
  after the decimal point; k is a scale factor that defaults to zero.

  ...

  If it is impossible to print the value in the required format in a field
  of width w, then one of two actions is taken. If the parameter
  overflowchar is supplied, then w copies of that parameter are printed
  instead of the scaled value of arg. If the overflowchar parameter is
  omitted, then the scaled value is printed using more than w characters,
  as many more as may be needed.

It would appear that the appropriate to use additional space to get the
number output.

-- 
Thomas A. Russ, USC/Information Sciences Institute ···@isi.edu