From: Dave K. <ip...@gm...> - 2006-04-28 23:57:13
|
I do remember reading that, but don't think it applies since w wasn't specified. I think the trailing zero's thing means something like "0.200" which would have two trailing zeros. You are right that I'm not specifying w - my thoughts on this would that w would be choosen automatically based on the constraint that there be the specified number of decimal places... So in this example, w =3D 2 decimal places + 1 for the dot + # of digits in front of the decimal place. Perhaps I am abusing the formatter in this regard, and w must always be specified? I'm still working on learning LISP, but coming from a C background, doing: printf(""%.2f\n", 0.02345f); gives me 0.02. I know this is apples and oranges... C and LISP are both ANSI specs, so they share *some* things in common :-) Of course maybe I'm abusing the C compiler too. For the software that I work on it is fairly common to want to print out a number where you only care about the first 3 or 4 decimal places, but do care about all of the digits in front of the decimal place. (For example, perhaps you have an instrument that is only precise to the 1000th place, so you truncate all further displayed numbers to that). So again, I could be doing something wrong... but I don't think so. Dave On 4/28/06, Raymond Toy <ray...@er...> wrote: > >>>>> "Dave" =3D=3D Dave Kern <ip...@gm...> writes: > > Dave> In sbcl-0.9.11 running under linux on an x86 machine: > Dave> When I use format with "~F" and specify the number of fraction = digits, > Dave> an extra digit is output if the input is a "small number". Hope= fully > Dave> the following makes it clear: > > Dave> (format t "~,2F" 0.001) =3D> 0.001 ;; should be 0.00 > Dave> (format t "~,2F" 0.005) =3D> 0.005 ;; should be 0.00 or 0.01 > Dave> (format t "~,2F" 0.006) =3D> 0.01 ;; correct > > Despite the patch I sent, consider this from 22.3.3.1: > > If the parameter d is omitted, then there is no constraint on the > number of digits to appear after the decimal point. A value is > chosen for d in such a way that as many digits as possible may be > printed subject to the width constraint imposed by the parameter w > and the constraint that no trailing zero digits may appear in the > fraction, except that if the fraction to be printed is zero, then > a single zero digit should appear after the decimal point if > permitted by the width constraint. > > Since w is not specified, I think sbcl and cmucl are correct as is. > No trailing zero digits are allowed in the fraction, except if the > fraction is zero. > > Ray > > |