From c31d1f5d44343da1201ea1be86bc6b2ac8af6c8d Mon Sep 17 00:00:00 2001 From: Timothy Sample Date: Mon, 18 Oct 2021 17:07:41 -0400 Subject: [PATCH] ice-9 format: Fix scaling floats with leading zeros --- module/ice-9/format.scm | 4 ++-- test-suite/tests/format.test | 10 ++++++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/module/ice-9/format.scm b/module/ice-9/format.scm index 48d9c0c84..ee7cba910 100644 --- a/module/ice-9/format.scm +++ b/module/ice-9/format.scm @@ -1359,10 +1359,10 @@ (else (if (> left-zeros 0) (if (<= left-zeros shift) ; shift always > 0 here - (format:fn-shiftleft shift) ; shift out 0s (begin (format:fn-shiftleft left-zeros) - (set! format:fn-dot (- shift left-zeros)))) + (set! format:fn-dot (- shift left-zeros))) + (format:fn-shiftleft shift)) ; shift out 0s (set! format:fn-dot (+ format:fn-dot shift)))))))) (let ((negexp ; expon format m.nnnEee diff --git a/test-suite/tests/format.test b/test-suite/tests/format.test index b9aa7a854..d5111f1c6 100644 --- a/test-suite/tests/format.test +++ b/test-suite/tests/format.test @@ -2,7 +2,7 @@ ;;;; Matthias Koeppe --- June 2001 ;;;; ;;;; Copyright (C) 2001, 2003, 2004, 2006, 2010, 2011, 2012, -;;;; 2014, 2017 Free Software Foundation, Inc. +;;;; 2014, 2017, 2021 Free Software Foundation, Inc. ;;;; ;;;; This library is free software; you can redistribute it and/or ;;;; modify it under the terms of the GNU Lesser General Public @@ -121,7 +121,13 @@ ;; in guile prior to 1.6.9 and 1.8.1, leading zeros were incorrectly ;; stripped, moving the decimal point and giving "25.0" here (pass-if "string 02.5" - (string=? "2.5" (format #f "~f" "02.5")))) + (string=? "2.5" (format #f "~f" "02.5"))) + + (pass-if "scale with few leading zeros" + (string=? "1.23" (format #f "~,,3f" "0.00123"))) + + (pass-if "scale with many leading zeros" + (string=? "0.0123" (format #f "~,,1f" "0.00123")))) ;;; ;;; ~h -- 2.33.0