This is the mail archive of the
java-prs@gcc.gnu.org
mailing list for the Java project.
libgcj/4583: problems BigDecimal(double) ctor.
- To: gcc-gnats at gcc dot gnu dot org
- Subject: libgcj/4583: problems BigDecimal(double) ctor.
- From: apbianco at redhat dot com
- Date: 16 Oct 2001 20:19:38 -0000
- Reply-To: apbianco at redhat dot com
>Number: 4583
>Category: libgcj
>Synopsis: problems BigDecimal(double) ctor.
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: unassigned
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Tue Oct 16 13:26:01 PDT 2001
>Closed-Date:
>Last-Modified:
>Originator: Alex Petit-Bianco
>Release: unknown-1.0
>Organization:
>Environment:
linux/x86, current trunk.
>Description:
I'm running into the following situation with BigDecimal. Consider
this code:
private static final BigDecimal minDouble =
new java.math.BigDecimal(Double.MIN_VALUE);
It ends up throwing a java.lang.NumberFormatException.
It seems to be that Long.parseLong doesn't handle what it is given as
an argument (`50E-324', and `scale' in BigDecimal would be modified
accordingly) as Long.parseLong won't handle anything but digits, and
the exception is thrown from there:
private static long parseLong(String str, int index, int len, boolean isNeg,
int radix) throws NumberFormatException
{
...
if ((digval = Character.digit(str.charAt(index), radix)) < 0)
throw new NumberFormatException();
Long.parseLong() complies with the spec, but BigDecimal uses
Double.toString to convert the input number. If the input can't be
represented in a string without using the scientific notation,
Long.parseLong() won't receive something it can deal with. 4.0e-4
instead of Double.MIN_VALUE will trigger the same error; but 4.0e-3
won't.
The attached test case can be use and could be added to our testsuite.
>How-To-Repeat:
Build BIG.java.
>Fix:
Not yet. One can work around the problem by hand crafting
a string representation of Double.MIN_VALUE or Double.MAX_VALUE that doesn't use a scientific notation.
>Release-Note:
>Audit-Trail:
>Unformatted:
----gnatsweb-attachment----
Content-Type: text/x-java; name="BIG.java"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="BIG.java"
aW1wb3J0IGphdmEubWF0aC5CaWdEZWNpbWFsOwppbXBvcnQgamF2YS5tYXRoLkJpZ0ludGVnZXI7
CgpjbGFzcyBCSUcgewogIHByaXZhdGUgc3RhdGljIGZpbmFsIEJpZ0ludGVnZXIgbWluRG91Ymxl
ID0KICAgIG5ldyBqYXZhLm1hdGguQmlnRGVjaW1hbChEb3VibGUuTUlOX1ZBTFVFKS50b0JpZ0lu
dGVnZXIoKTsKICBwcml2YXRlIHN0YXRpYyBmaW5hbCBCaWdJbnRlZ2VyIG1heERvdWJsZSA9CiAg
ICBuZXcgamF2YS5tYXRoLkJpZ0RlY2ltYWwoRG91YmxlLk1BWF9WQUxVRSkudG9CaWdJbnRlZ2Vy
KCk7CiAgcHVibGljIHN0YXRpYyB2b2lkIG1haW4gKFN0cmluZ1tdIGFyZykKICB7CiAgfQp9Cg==