From: William H. N. <wil...@ai...> - 2002-03-13 03:49:15
|
On Sat, Mar 09, 2002 at 08:31:34AM +0100, Robert STRANDH wrote: > Here is a new version of format-dollars that fixes a bug that I ran > into the other day. Essentially, the number of pad characters to > output was not computed correctly. > > (defun format-dollars (stream number d n w pad colon atsign) > (if (rationalp number) (setq number (coerce number 'single-float))) > (if (floatp number) > (let* ((signstr (if (minusp number) "-" (if atsign "+" ""))) > (signlen (length signstr))) > (multiple-value-bind (str strlen ig2 ig3 pointplace) > (sb!cl-imp::flonum-to-string number nil d nil) ^^^^^^^^^ > (declare (ignore ig2 ig3 strlen)) > (when colon (write-string signstr stream)) > (dotimes (i (- w signlen (max n pointplace) 1 d)) > (write-char pad stream)) > (unless colon (write-string signstr stream)) > (dotimes (i (- n pointplace)) (write-char #\0 stream)) > (write-string str stream))) > (format-write-field stream > (decimal-string number) > w 1 0 #\space t))) Thank you. I merged the patch (modulo the marked weirdness) in 0.7.1.36. That was several days ago, but I only just noticed that I mislaid my original acknowledgement. Incidentally, even patches in this format are usually useful and almost always appreciated, but ideally (1) when you change old code, submitting your change as a unified diff (from e.g. "cvs diff -u") makes it easier to see what's happened (and also makes it easier to merge your change if someone else makes changes nearby), and (2) an even more precise statement of the problem, something like ;; should work but didn't... (assert (string= (format nil "~2,3,8,'0$" 1234567.3d0) "1234567.30")) can be very helpful as well (and efficient, since when you submit the patch, you already know the exact problem, while the maintainer of a complex system might not even know what the correct behavior is without having to look it up). -- William Harold Newman <wil...@ai...> "Of course, if I dig my house foundations by biting the earth while banging my own head with a spade, then upgrading to mechanical digger maybe won't help..." -- Graham Perkins <gpe...@dm...> in comp.lang.eiffel PGP key fingerprint 85 CE 1C BA 79 8D 51 8C B9 25 FB EE E0 C3 E5 7C |