Clojure

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

Details

  • Type: Defect Defect
  • Status: Closed Closed
  • Priority: Trivial Trivial
  • Resolution: Completed
  • Affects Version/s: Release 1.3, Release 1.4
  • Fix Version/s: Release 1.5
  • Component/s: None
  • Labels:
    None
  • Environment:
    Linux 2.6.31-22-generic #61-Ubuntu SMP Wed Jul 28 01:57:06 UTC 2010 i686 GNU/Linux
  • Patch:
    Code and Test
  • Approval:
    Ok

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.

  1. clj-881-cl-format-exception-patch2.txt
    26/Mar/12 5:04 PM
    3 kB
    Andy Fingerhut
  2. patchfile
    20/Nov/11 2:47 AM
    3 kB
    Vyacheslav Dimitrov

Activity

Hide
Vyacheslav Dimitrov added a comment -

Also I can create pull request if any.

Show
Vyacheslav Dimitrov added a comment - Also I can create pull request if any.
Hide
Andy Fingerhut added a comment -

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.

Show
Andy Fingerhut added a comment - 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.
Andy Fingerhut made changes -
Field Original Value New Value
Attachment CLJ-881-patch-from-dimitrov.txt [ 10905 ]
Hide
Andy Fingerhut added a comment -

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.

Show
Andy Fingerhut added a comment - 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 made changes -
Andy Fingerhut made changes -
Attachment CLJ-881-patch-from-dimitrov.txt [ 10905 ]
Hide
Tom Faulhaber added a comment -

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

Show
Tom Faulhaber added a comment - This patch looks good to me. I recommend we apply it.
Rich Hickey made changes -
Fix Version/s Release 1.5 [ 10150 ]
Stuart Halloway made changes -
Approval Screened [ 10004 ]
Rich Hickey made changes -
Approval Screened [ 10004 ] Ok [ 10007 ]
Stuart Halloway made changes -
Resolution Completed [ 1 ]
Status Open [ 1 ] Closed [ 6 ]

People

Vote (1)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved: