Skip to content
This repository has been archived by the owner on May 3, 2024. It is now read-only.

Commit

Permalink
cl-format: ~$ wasn't handling negative numbers correctly
Browse files Browse the repository at this point in the history
refs #40
  • Loading branch information
tomfaulhaber committed Oct 31, 2009
1 parent d9c4221 commit 3f26704
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/clojure/contrib/pprint/cl-format.clj
Expand Up @@ -759,7 +759,7 @@ Note this should only be used for the last one in the sequence"
d (:d params) ; digits after the decimal
n (:n params) ; minimum digits before the decimal
w (:w params) ; minimum field width
add-sign (and (:at params) (not (neg? arg)))
add-sign (or (:at params) (neg? arg))
[rounded-mantissa scaled-exp _] (round-str mantissa exp d nil)
#^String fixed-repr (get-fixed rounded-mantissa scaled-exp d)
full-repr (str (apply str (repeat (- n (.indexOf fixed-repr (int \.))) \0)) fixed-repr)
Expand Down
17 changes: 16 additions & 1 deletion src/clojure/contrib/test_contrib/pprint/cl_format.clj
Expand Up @@ -176,7 +176,22 @@
(cl-format nil "~3,5,14@$" 22.375) " +00022.375"
(cl-format nil "~3,5,14@$" 22.375) " +00022.375"
(cl-format nil "~3,5,14@:$" 22.375) "+ 00022.375"
(cl-format nil "~3,,14@:$" 0.375) "+ 0.375")
(cl-format nil "~3,,14@:$" 0.375) "+ 0.375"
(cl-format nil "~1,1$" -12.0) "-12.0"
(cl-format nil "~1,1$" 12.0) "12.0"
(cl-format nil "~1,1$" 12.0) "12.0"
(cl-format nil "~1,1@$" 12.0) "+12.0"
(cl-format nil "~1,1,8,' @:$" 12.0) "+ 12.0"
(cl-format nil "~1,1,8,' @$" 12.0) " +12.0"
(cl-format nil "~1,1,8,' :$" 12.0) " 12.0"
(cl-format nil "~1,1,8,' $" 12.0) " 12.0"
(cl-format nil "~1,1,8,' @:$" -12.0) "- 12.0"
(cl-format nil "~1,1,8,' @$" -12.0) " -12.0"
(cl-format nil "~1,1,8,' :$" -12.0) "- 12.0"
(cl-format nil "~1,1,8,' $" -12.0) " -12.0")

(simple-tests f-tests
(cl-format nil "~,1f" -12.0) "-12.0")

(simple-tests ampersand-tests
(cl-format nil "The quick brown ~a jumped over ~d lazy dogs" 'elephant 5)
Expand Down

0 comments on commit 3f26704

Please sign in to comment.