Skip to content
Snippets Groups Projects
Commit 5187b8b6 authored by rtoy's avatar rtoy
Browse files

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.
parent 1eb81310
No related branches found
No related tags found
No related merge requests found
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
;;; Carnegie Mellon University, and has been placed in the public domain. ;;; Carnegie Mellon University, and has been placed in the public domain.
;;; ;;;
(ext:file-comment (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." ...@@ -1440,8 +1440,18 @@ radix-R. If you have a power-list then pass it in as PL."
(digits (float-digits x)) (digits (float-digits x))
(fudge (- digits precision)) (fudge (- digits precision))
(width (if width (max width 1) nil))) (width (if width (max width 1) nil)))
(float-string (ash sig (- fudge)) (+ exp fudge) precision width ;; If the number won't fit in the width, we need to
fdigits scale fmin)))))) ;; 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) (defun float-string (fraction exponent precision width fdigits scale fmin)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment