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.
This commit is contained in:
Marius Gerbershagen 2022-09-03 18:15:07 +02:00
parent d0a24fe283
commit d55d31df3b

View file

@ -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))