Clojure-Contrib

bugs in cl-format

Details

  • Type: Defect Defect
  • Status: Closed Closed
  • Resolution: Completed
  • Affects Version/s: None
  • Fix Version/s: None
  • Component/s: None
  • Labels:
    None

Description

As reported in the google group (http://groups.google.com/group/clojure/browse_thread/thread/ae3e636a44c95686):

Hello,

I've encountered a couple of issues with the cl-format function
included in contrib.pprint

(cl-format nil "~1,1$" -12.0) ;; => "12.0" the sign is lost

I think the problem is the following assignment in the dollar-float
function
add-sign (and (:at params) (not (neg? arg))) ;; wrong
(the sign is only printed when the colon modifier is present and only
for positive numbers)
that should read, if I understand correctly the logic,
add-sign (or (:at params) (neg? arg))

The second issue is not so straightforward to solve:

(cl-format true "1,1$%" 0.001) ;; => String index out of range: -1

I've tracked down the bug into the function round-str (the variable
round-pos will be negative and this case is not handled properly), but
I don't understand the code well enough to propose a fix.

Cheers,

Carlos

Activity

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

tomfaulhaber said: (In revision:3f267049a38f205ac3c7d91173c63648f139e790) cl-format: ~$ wasn't handling negative numbers correctly
refs #40

Branch: master

Show
Assembla Importer added a comment - tomfaulhaber said: (In revision:3f267049a38f205ac3c7d91173c63648f139e790) cl-format: ~$ wasn't handling negative numbers correctly refs #40 Branch: master
Hide
Assembla Importer added a comment -

tomfaulhaber said: (In revision:6f9e9c276bf53b0fce2275abf29a25f9735a6409) cl-format: ~$ wasn't handling very small fractions (that round to 0) correctly.
refs #40

Branch: master

Show
Assembla Importer added a comment - tomfaulhaber said: (In revision:6f9e9c276bf53b0fce2275abf29a25f9735a6409) cl-format: ~$ wasn't handling very small fractions (that round to 0) correctly. refs #40 Branch: master
Hide
Assembla Importer added a comment -

tomfaulhaber said: Fixed with the two above changelists

Show
Assembla Importer added a comment - tomfaulhaber said: Fixed with the two above changelists

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: