Clojure

GC Issue 113: Incorrect handling of trailing decimal points in numbers

Details

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

Description

Reported by scgilardi, May 04, 2009

What (small set of) steps will reproduce the problem?

        user=> (class 123.)
        java.lang.Integer

In contrast, Java reads such a number as a double.

        % javac Foo.java
        Foo.java:5: possible loss of precision
        found   : double
        required: int
                    int a = 123.;
                            ^
        1 error

Another place this comes up is with a number formatted as 123.e4.  
Currently that's an invalid number in Clojure:

        user=> (class 123.e4)
        java.lang.NumberFormatException: Invalid number: 123.e4
        java.lang.Exception: Unmatched delimiter: )
        user=>

Java reads it as 1230000.0

What version are you using?

1.0.0

Was this discussed on the group? If so, please provide a link to the
discussion:

http://groups.google.com/group/clojure/browse_thread/thread/c0db774b78171b9b/c57e878f11f2f199?lnk=gst&q=number#c57e878f11f2f199

Please provide any additional information below.

I've enclosed a patch to LispReader.java that fixes the problem. The patch
contains two changes, one necessary, one optional:

necessary: change the regular expressions intPat and floatPat so that "1."
is not considered an "int" and "1.e3" is accepted as a legal float.

optional: change the handling of the "M" suffix in matchNumber to make the
float handling code use matcher groups like the int and bigint handling
code does rather than using string manipulations.

I recommend both changes.

Comment 1  by scgilardi, May 04, 2009

I've attached a patch to clojure-contrib/src/clojure/contrib/test_clojure/reader.clj
to provide additional tests for reading Doubles and BigDecimals that pass with the
fixed Clojure LispReader.

Activity

Hide
Assembla Importer added a comment -
Show
Assembla Importer added a comment - oranenj said: [file:drAVxMw4mr3Ou4eJe5aVNr]
Hide
Assembla Importer added a comment -

oranenj said: [file:drAYtUw4mr3Ou4eJe5aVNr]: on comment 1

Show
Assembla Importer added a comment - oranenj said: [file:drAYtUw4mr3Ou4eJe5aVNr]: on comment 1
Hide
Assembla Importer added a comment -

importer said: (In [[r:f1d13b8f1fbda376352caf85857cc0585717bcd9]]) parse "1." and "1.e3" as legal floats. Refs #117

Signed-off-by: Chouser <chouser@n01se.net>

Branch: master

Show
Assembla Importer added a comment - importer said: (In [[r:f1d13b8f1fbda376352caf85857cc0585717bcd9]]) parse "1." and "1.e3" as legal floats. Refs #117 Signed-off-by: Chouser <chouser@n01se.net> Branch: master
Hide
Assembla Importer added a comment -

chouser@n01se.net said: Leaving this open until the location of clojure-tests are settled so that the attached test patch can be committed as well.

Show
Assembla Importer added a comment - chouser@n01se.net said: Leaving this open until the location of clojure-tests are settled so that the attached test patch can be committed as well.
Hide
Assembla Importer added a comment -

importer said: (In [[r:5e34989a7098a55ca014030d7446d2dc20ebc33b]]) Test reading of numbers like "1." and "1.e3". Fixes #117

Signed-off-by: Chouser <chouser@n01se.net>

Branch: master

Show
Assembla Importer added a comment - importer said: (In [[r:5e34989a7098a55ca014030d7446d2dc20ebc33b]]) Test reading of numbers like "1." and "1.e3". Fixes #117 Signed-off-by: Chouser <chouser@n01se.net> Branch: master

People

  • Assignee:
    Unassigned
    Reporter:
    Anonymous
Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: