From 5187b8b685f31fe029734e0cdb4229b0fda46d11 Mon Sep 17 00:00:00 2001
From: rtoy <rtoy>
Date: Fri, 27 Aug 2004 03:08:56 +0000
Subject: [PATCH] Fix bug where (FORMAT NIL "~2f" 1234567.1) returns "1000000."
 instead "1234567."

We just test to see if the width is large enough to hold the number.
If not, increase the width so that float-string will produce enough
digits.
---
 code/print.lisp | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/code/print.lisp b/code/print.lisp
index 1e92a1772..b9c4c9d10 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.94 2004/06/09 15:01:20 rtoy Exp $")
+  "$Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/code/print.lisp,v 1.95 2004/08/27 03:08:56 rtoy Exp $")
 ;;;
 ;;; **********************************************************************
 ;;;
@@ -1440,8 +1440,18 @@ radix-R.  If you have a power-list then pass it in as PL."
 		  (digits (float-digits x))
 		  (fudge (- digits precision))
 		  (width (if width (max width 1) nil)))
-	   (float-string (ash sig (- fudge)) (+ exp fudge) precision width
-			 fdigits scale fmin))))))
+	     ;; If the number won't fit in the width, we need to
+	     ;; increase the width so that it will.
+	     (when width
+	       (let ((xwidth (ceiling (log x (float 10 x)))))
+		 (when (< width xwidth)
+		   (setf width xwidth))
+		 ;; FIXME: It also seems that float-string doesn't
+		 ;; produce enough.  Increase width by one.  Is this
+		 ;; right?
+		 (incf width)))
+	     (float-string (ash sig (- fudge)) (+ exp fudge) precision width
+			   fdigits scale fmin))))))
 
 
 (defun float-string (fraction exponent precision width fdigits scale fmin)
-- 
GitLab