From d87a15cc0076071bc4501bbeece802e1b8616585 Mon Sep 17 00:00:00 2001 From: Warren Levy Date: Thu, 29 Jun 2000 23:20:33 +0000 Subject: * 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). --- java/math/BigDecimal.java | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'java/math/BigDecimal.java') 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) -- cgit v1.2.1