Details
-
Type:
Defect
-
Status:
Closed
-
Resolution: Completed
-
Affects Version/s: None
-
Fix Version/s: None
-
Component/s: None
-
Labels:None
Description
Reported to me by Carlos Ungil (and confirmed by me):
Unfortunately there are still some issues with rounding. I've noticed that when the
mantissa is rounded up from 9 to 10 the exponent is not changed
accordingly. As a result, we get for example
clojure.contrib.pprint> (cl-format nil "~,0F" 9.4) => "9."
clojure.contrib.pprint> (cl-format nil "~,0F" 9.5) => "1.0"
I've compared the output from Clojure and Common Lisp for a handful of
cases. Below we see how "0.10" is returned instead of "1.0" when
printing 0.99 with a single digit after the decimal point. There is
also a minor problem with "01." being printed instead of "1.", but
returning a different representation for a number is of course not as
bad as returning a wrong representation.
;;(map #(cl-format nil % 0.99) ["~,0F" "~,1F" "~,2F" "~,3F"])
("01." "0.10" "0.99" "0.990")
;;(loop for fmt in '(",0F" ",1F" ",2F" ",3F") collect (format nil
fmt 0.99))
("1." "1.0" "0.99" "0.990")
There are also issues with negative numbers, the add-sign variable has
the same bug in fixed-float that it had in dollar-float but fixing
that is not enough to correct the problem.
;; > (map #(cl-format nil % -0.99) ["~,0F" "~,1F" "~,2F" "~,3F"])
("010." "0-1.0" "0-0.99" "0-0.990")
Converted from http://www.assembla.com/spaces/clojure/tickets/47