From 4f2960d07c7d17f30bc8d4f66f62e666cc274c84 Mon Sep 17 00:00:00 2001
From: rtoy <rtoy>
Date: Fri, 1 Feb 2008 14:54:42 +0000
Subject: [PATCH] For ~w,dF, don't print out too man leading digits if the
 number is less than 10^(-d) (approximately).  Previously, we'd print out m
 leading digits if the number were 10^(-m) even if d < m.

Additional tests:

(assert (string= (format nil "~,3F" 0.000001) "0.000"))
---
 code/print.lisp | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/code/print.lisp b/code/print.lisp
index eb1872235..ca4bf12f1 100644
--- a/code/print.lisp
+++ b/code/print.lisp
@@ -5,7 +5,7 @@
 ;;; Carnegie Mellon University, and has been placed in the public domain.
 ;;;
 (ext:file-comment
-  "$Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/code/print.lisp,v 1.119 2008/01/26 02:09:44 rtoy Exp $")
+  "$Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/code/print.lisp,v 1.120 2008/02/01 14:54:42 rtoy Exp $")
 ;;;
 ;;; **********************************************************************
 ;;;
@@ -1542,7 +1542,15 @@ radix-R.  If you have a power-list then pass it in as PL."
 			 (write-char #\0 stream))))
 		   (progn
 		     (write-string "." stream)
-		     (dotimes (i (- e))
+		     ;; Write out the leading zeroes.  If fmin is set,
+		     ;; we need all of them.  But if fdigits is given
+		     ;; and is smaller than -e, we only want fdigits
+		     ;; to be output.  That way we don't print too
+		     ;; many leading zeroes if the number is too
+		     ;; small.
+		     (dotimes (i (if (or fmin (null fdigits))
+				     (- e)
+				     (min (- e) fdigits)))
 		       (write-char #\0 stream))
 		     ;; If we're out of room (because fdigits is too
 		     ;; small), don't print out our string.  This
-- 
GitLab