From 5cbb3b905ab3e93ea1d935a8c0b10d05abcb2be5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Kochma=C5=84ski?= Date: Sun, 10 May 2015 15:14:49 +0200 Subject: [PATCH] format: flonum-to-string: rework nested IF statements as cond. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Simplifies code. Also creates additional clause (commented now) to handle special case, when width is too small to display number. Signed-off-by: Daniel KochmaƄski --- src/lsp/format.lsp | 51 ++++++++++++++++++++++++++-------------------- 1 file changed, 29 insertions(+), 22 deletions(-) diff --git a/src/lsp/format.lsp b/src/lsp/format.lsp index fa39598c3..e5cc87663 100644 --- a/src/lsp/format.lsp +++ b/src/lsp/format.lsp @@ -106,28 +106,35 @@ (values "." 1 t t 0))) (t (multiple-value-bind (e string) - (if fdigits - (float-to-digits nil x - (min (- (+ fdigits scale)) - (- fmin)) - nil) - (if (and width (> width 1)) - (let ((w (multiple-value-list - (float-to-digits nil x - (max 1 - (+ (1- width) - (if (minusp scale) - scale 0))) - t))) - (f (multiple-value-list - (float-to-digits nil x - (- (+ fmin scale)) - nil)))) - (cond - ((>= (length (cadr w)) (length (cadr f))) - (values-list w)) - (t (values-list f)))) - (float-to-digits nil x nil nil))) + (cond + ((not (null fdigits)) + (float-to-digits nil x + (min (- (+ fdigits scale)) + (- fmin)) + nil)) + ((null width) + (float-to-digits nil x nil nil)) + ;; ((= width 1) + ;; ;; This is a corner case. CLHS indicates, that minimal + ;; ;; number of characters required to print a value + ;; ;; should be used. + ;; (float-to-digits nil x nil nil)) + (T (let ((w (multiple-value-list + (float-to-digits nil x + (max 1 + (+ (1- width) + (if (minusp scale) + scale 0))) + t))) + (f (multiple-value-list + (float-to-digits nil x + (- (+ fmin scale)) + nil)))) + (format t "width is ~A, w is ~A~&" width w) + (if (>= (length (cadr w)) + (length (cadr f))) + (values-list w) + (values-list f))))) (let ((e (+ e scale)) (stream (make-string-output-stream))) (if (plusp e)