summaryrefslogtreecommitdiff
path: root/java/math
diff options
context:
space:
mode:
authorWarren Levy <warrenl@redhat.com>2000-06-29 23:20:33 +0000
committerWarren Levy <warrenl@redhat.com>2000-06-29 23:20:33 +0000
commitd87a15cc0076071bc4501bbeece802e1b8616585 (patch)
treea91f4394b934a32b48fb1683af562852cc2a5223 /java/math
parenta40aa46838c98db56191e72ceef41d471ed4ed0d (diff)
downloadclasspath-d87a15cc0076071bc4501bbeece802e1b8616585.tar.gz
* java/math/BigDecimal.java (add): Reimplemented.
(subtract): Corrected method name from 'substract'. Reimplemented. * java/sql/Connection.java (TRANSACTION_SERIALIZABLE): Corrected spelling to match JDK spec. * java/sql/DatabaseMetaData.java (getIdentifierQuoteString): Corrected method name from 'getIdentiferQuoteString'. (getTimeDateFunctions): Corrected name to match the spec. (supportsCatalogsInPrivilegeDefinitions): Ditto. (getMaxUserNameLength): Ditto. (getTables): Added String types[] parameter to match the spec. * java/sql/Driver.java (getMajorVersion): Corrected method name. * java/sql/PreparedStatement.java: Class extends Statement. (setBigDecimal): New method. (setAsciiStream): Added int length parameter. (setUnicodeStream): Ditto. (setBinaryStream): Ditto. (setCharacterStream): Ditto. (execute): New method. (executeQuery): New method. (executeUpdate): New method. Mods to match the JDK spec (and to fix BigDecimal bugs).
Diffstat (limited to 'java/math')
-rw-r--r--java/math/BigDecimal.java19
1 files changed, 14 insertions, 5 deletions
diff --git a/java/math/BigDecimal.java b/java/math/BigDecimal.java
index 03a1a5d09..d07f3d70c 100644
--- a/java/math/BigDecimal.java
+++ b/java/math/BigDecimal.java
@@ -1,5 +1,5 @@
/* java.math.BigDecimal -- Arbitrary precision decimals.
- Copyright (C) 1999 Free Software Foundation, Inc.
+ Copyright (C) 1999, 2000 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -96,13 +96,22 @@ public class BigDecimal extends Number implements Comparable {
public BigDecimal add (BigDecimal val)
{
- return new BigDecimal (num.add (val.num), Math.max (scale, val.scale));
+ // For addition, need to line up decimals. Note that the movePointRight
+ // method cannot be used for this as it might return a BigDecimal with
+ // scale == 0 instead of the scale we need.
+ BigInteger op1 = num;
+ BigInteger op2 = val.num;
+ if (scale < val.scale)
+ op1 = op1.multiply (BigInteger.valueOf (10).pow (val.scale - scale));
+ else if (scale > val.scale)
+ op2 = op2.multiply (BigInteger.valueOf (10).pow (scale - val.scale));
+
+ return new BigDecimal (op1.add (op2), Math.max (scale, val.scale));
}
- public BigDecimal substract (BigDecimal val)
+ public BigDecimal subtract (BigDecimal val)
{
- return new BigDecimal (num.subtract (val.num),
- Math.max (scale, val.scale));
+ return this.add(val.negate());
}
public BigDecimal multiply (BigDecimal val)