From 75de54220b6c225d97f3110f8135c91994c536ad Mon Sep 17 00:00:00 2001 From: rtoy <rtoy> Date: Sat, 26 Jan 2008 02:09:44 +0000 Subject: [PATCH] Was failing to print enough digits for things like (format nil "~9,,,-2E" 1.2345689d-3). This change also allows us to get rid of one other call to flonum-to-string, so printing should be faster now. Some additional tests: (assert (string= (format nil "~9,,,-2E" 1.2345689d3) ".00123d+6")) (assert (string= (format nil "~9,,,-2E" -1.2345689d3) "-.0012d+6")) (assert (string= (format nil "~9,,,-2E" 1.2345689d-3) ".00123d+0")) (assert (string= (format nil "~9,,,-2E" -1.2345689d-3) "-.0012d+0")) --- code/print.lisp | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/code/print.lisp b/code/print.lisp index 4498fadfa..eb1872235 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.118 2008/01/25 19:16:12 rtoy Exp $") + "$Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/code/print.lisp,v 1.119 2008/01/26 02:09:44 rtoy Exp $") ;;; ;;; ********************************************************************** ;;; @@ -1511,21 +1511,18 @@ radix-R. If you have a power-list then pass it in as PL." (- (or fmin 0))) num-expt)) (if (and width (> width 1)) - (let ((w (multiple-value-list - (let ((ndigits (1- width)) - (scaled (+ num-expt (or scale 0)))) - (when (and scale (< scale 0)) - (setf ndigits (- ndigits scaled 1))) - (fixup-flonum-to-digits x num-expt - ndigits - t)))) - (f (multiple-value-list - (fixup-flonum-to-digits x num-expt - (- num-expt (or fmin 0) 1))))) - (cond - ((>= (length (cadr w)) (length (cadr f))) - (values-list w)) - (t (values-list f)))) + (let ((ndigits (1- width))) + #+(or) + (progn + (format t "ndigits = ~A~%" ndigits) + (format t "scale = ~A~%" scale)) + (when (and scale (< scale 0)) + (setf ndigits (+ ndigits scale))) + (when (minusp num-expt) + (incf ndigits (- num-expt))) + (fixup-flonum-to-digits x num-expt + ndigits + t)) (fixup-flonum-to-digits x num-expt))) (let ((e (+ e (or scale 0))) (stream (make-string-output-stream))) -- GitLab