Problem with the "cl-format" function from the clojure.pprint

Description

Let's see the following scenario:

vdim@home:~/clojure$ git log -1
commit ba930d95fc3a4a78c5bd6756ea483c9dac681618
Author: Rich Hickey <richhickey@gmail.com>
Date: Sun Oct 30 10:44:55 2011 -0400

inline equiv in variadic =
vdim@home:~/clojure$ rlwrap java -cp clojure-1.4.0-master-SNAPSHOT.jar clojure.main
Clojure 1.4.0-master-SNAPSHOT
user=> (use 'clojure.pprint)
nil
user=> (cl-format nil "~12,10F" 1.00000000074)
"1.0000000007"
user=> (cl-format nil "~12,10F" 1.00000000076)
NumberFormatException For input string: "10000000007" java.lang.NumberFormatException.forInputString (NumberFormatException.java:65)
user=>

The exception is caused from round-str function (cl-format.clj) where
my number (100000000076) is coerced to an Integer (see line with Integer/valueOf code
into this function).

Is this normal behaviour?

See patch with tests and my suggestion for solving this problem.

Environment

Linux 2.6.31-22-generic #61-Ubuntu SMP Wed Jul 28 01:57:06 UTC 2010 i686 GNU/Linux

Attachments

2

Activity

Tom Faulhaber 
March 30, 2012 at 2:15 AM

This patch looks good to me. I recommend we apply it.

Andy Fingerhut 
March 26, 2012 at 11:04 PM

clj-881-cl-format-exception-patch2.txt Mar 26, 2012 applies cleanly to latest master, and fixes the problem in the same way as my Feb 12, 2012 patch (since deleted to avoid confusion). I am the author, and have signed a CA.

Andy Fingerhut 
February 12, 2012 at 8:29 AM

I've modified Vyacheslav's patch so that it is in the proper format. I also changed his implementation of function inc-s so that it should allocate a bit less memory, and removed an addition of a redundant test case that is in his patch. There is a bug he has found here, and I've verified that this patch fixes it.

import 
November 20, 2011 at 8:49 AM

Comment made by: vdim

Also I can create pull request if any.

Completed

Details

Assignee

Reporter

Approval

Patch

Priority

Affects versions

Fix versions

Created November 20, 2011 at 8:47 AM
Updated May 19, 2012 at 2:37 AM
Resolved May 19, 2012 at 2:37 AM