This is the mail archive of the
java-patches@gcc.gnu.org
mailing list for the Java project.
BigDecimal fixlets
- From: Mark Wielaard <mark at klomp dot org>
- To: java-patches at gcc dot gnu dot org
- Date: 14 Feb 2003 10:57:25 +0100
- Subject: BigDecimal fixlets
- Organization:
Hi,
The following fixed all remaining BigDecimal failures in Mauve. The
divide() fixlet makes sure that the scale is set even in the special
case of a ZERO result. (Fixes ssc005 and ssc006.) The String constructor
fixlet implements the pedantic reading of the spec where a zero
significant can be interpreted specially in the sentence: "in every
case, the resulting BigDecimal is equal to significand × 10^exponent".
(Fixes div376, mul038 and sca007.) Note that those last three do fail in
the Blackdown-1.4.1-beta which I tested against. So the test might be a
bit to pedantic, but Sun is known for not always following their own
spec when it comes to parsing/decoding numeric types.
2003-02-14 Mark Wielaard <mark@klomp.org>
* java/math/BigDecimal.java (BigDecimal(String)): Always set scale to
zero when there is an exponent and the significant is zero.
(divide): Always set scale to newScale even in special ZERO case.
OK for mainline and branch?
Cheers,
Mark
Index: java/math/BigDecimal.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/math/BigDecimal.java,v
retrieving revision 1.7
diff -u -r1.7 BigDecimal.java
--- java/math/BigDecimal.java 7 Feb 2003 21:05:12 -0000 1.7
+++ java/math/BigDecimal.java 14 Feb 2003 09:55:04 -0000
@@ -189,7 +189,9 @@
{
int exp = Integer.parseInt (num.substring (point));
exp -= scale;
- if (exp > 0)
+ if (signum () == 0)
+ scale = 0;
+ else if (exp > 0)
{
intVal = intVal.multiply (BigInteger.valueOf (10).pow (exp));
scale = 0;
@@ -266,7 +268,7 @@
throw new ArithmeticException ("scale is negative: " + newScale);
if (intVal.signum () == 0) // handle special case of 0.0/0.0
- return ZERO;
+ return newScale == 0 ? ZERO : new BigDecimal (ZERO.intVal, newScale);
// Ensure that pow gets a non-negative value.
int valScale = val.scale;