From ef77f543cd89c918dba8c83d6836ebfc5ae5e615 Mon Sep 17 00:00:00 2001 From: rtoy <rtoy> Date: Mon, 1 May 2006 16:10:26 +0000 Subject: [PATCH] code/format.lisp: o Add an additional case where we want to print out a trailing zero: There's no width constraint and the previous character was a decimal point, so the fraction to be printed is zero. code/print.lisp: o Honor the d option if we run out of room so (format nil "~,2f" 0.001) produces "0.00", not "0.001". --- code/format.lisp | 13 +++++++++++-- code/print.lisp | 10 ++++++++-- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/code/format.lisp b/code/format.lisp index 6c868c9b4..7dc8887f4 100644 --- a/code/format.lisp +++ b/code/format.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/format.lisp,v 1.68 2006/04/28 20:58:43 rtoy Exp $") + "$Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/code/format.lisp,v 1.69 2006/05/01 16:10:26 rtoy Exp $") ;;; ;;; ********************************************************************** ;;; @@ -1257,7 +1257,16 @@ (if atsign (write-char #\+ stream))) (when lpoint (write-char #\0 stream)) (write-string fstr stream) - (when add-zero-p + ;; Add a zero if we need it. Which means + ;; we figured out we need one above, or + ;; another condition. Basically, append a + ;; zero if there are no width constraints + ;; and if the last char to print was a + ;; decimal (so the trailing fraction is + ;; zero.) + (when (or add-zero-p + (and (null w) + (char= (aref fstr (1- flen)) #\.))) ;; It's later and we're adding the zero ;; digit. (write-char #\0 stream)) diff --git a/code/print.lisp b/code/print.lisp index 6bc6a9232..b993f158f 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.109 2006/04/28 20:51:42 rtoy Exp $") + "$Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/code/print.lisp,v 1.110 2006/05/01 16:10:26 rtoy Exp $") ;;; ;;; ********************************************************************** ;;; @@ -1539,7 +1539,13 @@ radix-R. If you have a power-list then pass it in as PL." (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. This fixes + ;; things like (format nil "~,2f" 0.001). We should + ;; print ".00", not ".001". + (when (or (null fdigits) + (plusp (+ e fdigits))) + (write-string string stream)) (when fdigits (dotimes (i (+ fdigits e (- (length string)))) (write-char #\0 stream))))) -- GitLab