From 0506ce34a3bd134b0e69b13af1bd448eb0fedc71 Mon Sep 17 00:00:00 2001 From: Marius Gerbershagen Date: Sun, 18 Sep 2022 16:33:00 +0200 Subject: [PATCH] format.lsp: fix format ~e with width argument Fixes #632. --- src/lsp/format.lsp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/lsp/format.lsp b/src/lsp/format.lsp index c024bf5a7..ae08b5182 100644 --- a/src/lsp/format.lsp +++ b/src/lsp/format.lsp @@ -127,19 +127,20 @@ nil)) ((null width) (float-to-digits* nil x nil nil)) - (T (let ((w (multiple-value-list + (T (let (;; w: the width-1 leading non-zero digits + (w (multiple-value-list (float-to-digits* nil x (max 0 (+ (- width 2) - (if (minusp scale) - scale 0))) + (max 0 scale))) t))) + ;; f: the fmin+1 leading non-zero digits; this + ;; is used if w is empty (not enough space) (f (multiple-value-list (float-to-digits* nil x (- (+ fmin scale)) nil)))) - (if (>= (length (cadr w)) - (length (cadr f))) + (if (>= (first f) (first w)) (values-list w) (values-list f))))) (let* ((exp (+ e scale))