Clojure-Contrib

cl-format rounding bugs

Details

  • Type: Defect Defect
  • Status: Closed 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")

Activity

Hide
Assembla Importer added a comment -
Show
Assembla Importer added a comment - Converted from http://www.assembla.com/spaces/clojure/tickets/47
Hide
Assembla Importer added a comment -

stuart.sierra said: Updating tickets (#28, #32, #45, #47, #51, #19)

Show
Assembla Importer added a comment - stuart.sierra said: Updating tickets (#28, #32, #45, #47, #51, #19)
Hide
Assembla Importer added a comment -

tomfaulhaber said: (In revision:912e5671cc8237addf55753ff524bf283830e684) clojure.contrib.pprint (cl-format): Fixes to rounding and width issues in ~f and ~$. See #47.

Branch: master

Show
Assembla Importer added a comment - tomfaulhaber said: (In revision:912e5671cc8237addf55753ff524bf283830e684) clojure.contrib.pprint (cl-format): Fixes to rounding and width issues in ~f and ~$. See #47. Branch: master
Hide
Assembla Importer added a comment -

tomfaulhaber said: (In revision:5a703b33391e9486548af9ae7d8c3601d6f44505) Remove debug prints . See #47

Branch: master

Show
Assembla Importer added a comment - tomfaulhaber said: (In revision:5a703b33391e9486548af9ae7d8c3601d6f44505) Remove debug prints . See #47 Branch: master

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: