From d55d31df3b02db5dce941f9d71ee8563f146bfe5 Mon Sep 17 00:00:00 2001 From: Marius Gerbershagen Date: Sat, 3 Sep 2022 18:15:07 +0200 Subject: [PATCH] format: print 0 after decimal point with ~e for integer input Example: (format t "~e" 1.0) used to print 1.e+0, now prints 1.0e+0 Code adapted from SBCL. --- src/lsp/format.lsp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/lsp/format.lsp b/src/lsp/format.lsp index 976485f0b..c024bf5a7 100644 --- a/src/lsp/format.lsp +++ b/src/lsp/format.lsp @@ -1393,14 +1393,19 @@ nil))) (if (and w ovf e (> elen e)) ;exponent overflow (dotimes (i w) (write-char ovf stream)) - (multiple-value-bind (fstr flen lpoint) + (multiple-value-bind (fstr flen lpoint tpoint) (sys::flonum-to-string number spaceleft fdig (- expt) fmin) + (when (eql fdig 0) (setq tpoint nil)) (when w (decf spaceleft flen) (when lpoint (if (> spaceleft 0) (decf spaceleft) - (setq lpoint nil)))) + (setq lpoint nil))) + (when tpoint + (if (<= spaceleft 0) + (setq tpoint nil) + (decf spaceleft)))) (cond ((and w (< spaceleft 0) ovf) ;;significand overflow (dotimes (i w) (write-char ovf stream))) @@ -1411,6 +1416,7 @@ (if atsign (write-char #\+ stream))) (when lpoint (write-char #\0 stream)) (write-string fstr stream) + (when tpoint (write-char #\0 stream)) (write-char (if marker marker (format-exponent-marker number))