diff options
author | Tom Faulhaber <git_net@infolace.com> | 2009-10-31 00:38:29 -0700 |
---|---|---|
committer | Tom Faulhaber <git_net@infolace.com> | 2009-10-31 00:38:29 -0700 |
commit | 6f9e9c276bf53b0fce2275abf29a25f9735a6409 (patch) | |
tree | 45a789b66d99164ac49fdd7c2e694219bbcc3b3c /src/clojure/contrib/pprint | |
parent | 3f267049a38f205ac3c7d91173c63648f139e790 (diff) |
cl-format: ~$ wasn't handling very small fractions (that round to 0) correctly.
refs #40
Diffstat (limited to 'src/clojure/contrib/pprint')
-rw-r--r-- | src/clojure/contrib/pprint/cl-format.clj | 28 |
1 files changed, 15 insertions, 13 deletions
diff --git a/src/clojure/contrib/pprint/cl-format.clj b/src/clojure/contrib/pprint/cl-format.clj index b0531c14..6fd691e2 100644 --- a/src/clojure/contrib/pprint/cl-format.clj +++ b/src/clojure/contrib/pprint/cl-format.clj @@ -575,19 +575,21 @@ Note this should only be used for the last one in the sequence" [(str "0" m) (inc e) 1 (inc len)] [m e round-pos len])] (if round-pos - (if (> len round-pos) - (let [round-char (nth m1 round-pos) - #^String result (subs m1 0 round-pos)] - (if (>= (int round-char) (int \5)) - (let [result-val (Integer/valueOf result) - leading-zeros (subs result 0 (min (prefix-count result \0) (- round-pos 1))) - round-up-result (str leading-zeros - (String/valueOf (+ result-val - (if (neg? result-val) -1 1)))) - expanded (> (count round-up-result) (count result))] - [round-up-result e1 expanded]) - [result e1 false])) - [m e false]) + (if (neg? round-pos) + ["0" 0 false] + (if (> len round-pos) + (let [round-char (nth m1 round-pos) + #^String result (subs m1 0 round-pos)] + (if (>= (int round-char) (int \5)) + (let [result-val (Integer/valueOf result) + leading-zeros (subs result 0 (min (prefix-count result \0) (- round-pos 1))) + round-up-result (str leading-zeros + (String/valueOf (+ result-val + (if (neg? result-val) -1 1)))) + expanded (> (count round-up-result) (count result))] + [round-up-result e1 expanded]) + [result e1 false])) + [m e false])) [m e false])) [m e false])) |