On 4/25/06, Raymond Toy <raymond.toy@ericsson.com> wrote:
>>>>> "Dave" == Dave Kern <ipsuid@gmail.com> 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". Hopefully
    Dave> the following makes it clear:

    Dave> (format t "~,2F" 0.001) => 0.001   ;; should be 0.00
    Dave> (format t "~,2F" 0.005) => 0.005   ;; should be 0.00 or 0.01
    Dave> (format t "~,2F" 0.006) => 0.01     ;; correct

CMUCL has a similar problem.  One possible fix is the following
patch.  This should probably apply cleanly to sbcl, since they both
have very similar fp printing routines.

This issue appears to still be present (src/code/print.lisp, line 1185). Any particular reason the patch below hasn't made it to the repository yet, or is it just that no one got around to it?

In function flonum-to-string:
Index: print.lisp
===================================================================
RCS file: /project/cmucl/cvsroot/src/code/print.lisp,v
retrieving revision 1.108
diff -u -r1.108 print.lisp
--- print.lisp  17 Feb 2006 15:45:40 -0000      1.108
+++ print.lisp  25 Apr 2006 13:24:15 -0000
@@ -1539,7 +1539,11 @@
                   (write-string "." stream)
                   (dotimes (i (- e))
                     (write-char #\0 stream))
-                  (write-string string stream)
+                  ;; If we're out of room (because fdigits is too
+                  ;; small), don't print out our string.
+                  (when (or (null fdigits)
+                            (plusp (+ e fdigits)))
+                    (write-string string stream))
                   (when fdigits
                     (dotimes (i (+ fdigits e (- (length string))))
                       (write-char #\0 stream)))))

Regards,
Marijn