mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-04-30 03:40:34 +02:00
(ice-9 format): Fix scaling floats with leading zeros
This commit is contained in:
parent
98dff7a75e
commit
c85724bd0a
2 changed files with 9 additions and 3 deletions
|
@ -1359,10 +1359,10 @@
|
||||||
(else
|
(else
|
||||||
(if (> left-zeros 0)
|
(if (> left-zeros 0)
|
||||||
(if (<= left-zeros shift) ; shift always > 0 here
|
(if (<= left-zeros shift) ; shift always > 0 here
|
||||||
(format:fn-shiftleft shift) ; shift out 0s
|
|
||||||
(begin
|
(begin
|
||||||
(format:fn-shiftleft left-zeros)
|
(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))))))))
|
(set! format:fn-dot (+ format:fn-dot shift))))))))
|
||||||
|
|
||||||
(let ((negexp ; expon format m.nnnEee
|
(let ((negexp ; expon format m.nnnEee
|
||||||
|
|
|
@ -121,7 +121,13 @@
|
||||||
;; in guile prior to 1.6.9 and 1.8.1, leading zeros were incorrectly
|
;; 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
|
;; stripped, moving the decimal point and giving "25.0" here
|
||||||
(pass-if "string 02.5"
|
(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
|
;;; ~h
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue