This is the mail archive of the
java@gcc.gnu.org
mailing list for the Java project.
BigDecimal problem.
- To: java at gcc dot gnu dot org
- Subject: BigDecimal problem.
- From: Alexandre Petit-Bianco <apbianco at cygnus dot com>
- Date: Tue, 16 Oct 2001 12:59:53 -0700
- Reply-to: apbianco at cygnus dot com
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.
I guess I can work around the problem by hand building a String
argument for BigDecimal(<min_value>) Nonetheless, I'm going to file a
PR.
./A