aboutsummaryrefslogtreecommitdiff
path: root/libjava/java/math
diff options
context:
space:
mode:
authorWarren Levy <warrenl@cygnus.com>2000-10-27 10:33:46 +0000
committerWarren Levy <warrenl@gcc.gnu.org>2000-10-27 10:33:46 +0000
commitdf98a50bb05465d9ad789c039281975230a27188 (patch)
treec250d6267fbdab1f69cdf85ae2a504f5447570f0 /libjava/java/math
parentc11a03240fe13025b4f33184ead72e441d7297b0 (diff)
downloadgcc-df98a50bb05465d9ad789c039281975230a27188.zip
gcc-df98a50bb05465d9ad789c039281975230a27188.tar.gz
gcc-df98a50bb05465d9ad789c039281975230a27188.tar.bz2
Makefile.am: Added locale files from Classpath.
* Makefile.am: Added locale files from Classpath. * Makefile.in: Rebuilt. * gnu/java/locale/Calendar.java: New file. * gnu/java/locale/Calendar_de.java: New file. * gnu/java/locale/Calendar_en.java: New file. * gnu/java/locale/Calendar_nl.java: New file. * java/lang/ClassNotFoundException.java: Replaced with Classpath file. * java/math/BigDecimal.java (intVal): Renamed from 'num' for serialization compatibility. (scale): Made private. (serialVersionUID): New field. * java/math/BigInteger.java (ival): Made transient. (words): Made transient. (bitCount): New serialization field. (bitLength): Ditto. (firstNonzeroByteNum): Ditto. (lowestSetBit): Ditto. (magnitude): Ditto. (signum): Ditto. (serialVersionUID): New field. (readObject): New method. (writeObject): New method. * java/util/BitSet.java (serialVersionUID): New field. * java/util/Calendar.java: Replaced with Classpath file. * java/util/GregorianCalendar.java (GregorianCalendar): Pass result of getDefault() for TimeZone or Locale instead of passing nulls. * java/util/Locale.java (serialVersionUID): New field. (writeObject): New method. (readObject): New method. * java/util/SimpleTimeZone.java: Replaced with Classpath file. Serialization mods. From-SVN: r37080
Diffstat (limited to 'libjava/java/math')
-rw-r--r--libjava/java/math/BigDecimal.java44
-rw-r--r--libjava/java/math/BigInteger.java34
2 files changed, 55 insertions, 23 deletions
diff --git a/libjava/java/math/BigDecimal.java b/libjava/java/math/BigDecimal.java
index 30384ec..6844b24 100644
--- a/libjava/java/math/BigDecimal.java
+++ b/libjava/java/math/BigDecimal.java
@@ -29,8 +29,9 @@ package java.math;
import java.math.BigInteger;
public class BigDecimal extends Number implements Comparable {
- BigInteger num;
- int scale;
+ private BigInteger intVal;
+ private int scale;
+ private static final long serialVersionUID = 6108874887143696463L;
private final static BigDecimal ZERO =
new BigDecimal (BigInteger.valueOf (0), 0);
@@ -56,7 +57,7 @@ public class BigDecimal extends Number implements Comparable {
{
if (scale < 0)
throw new NumberFormatException ("scale of " + scale + " is < 0");
- this.num = num;
+ this.intVal = num;
this.scale = scale;
}
@@ -68,7 +69,7 @@ public class BigDecimal extends Number implements Comparable {
public BigDecimal (String num) throws NumberFormatException
{
int point = num.indexOf('.');
- this.num = new BigInteger (point == -1 ? num :
+ this.intVal = new BigInteger (point == -1 ? num :
num.substring (0, point) +
num.substring (point + 1));
scale = num.length() - (point == -1 ? num.length () : point + 1);
@@ -99,8 +100,8 @@ public class BigDecimal extends Number implements Comparable {
// 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;
+ BigInteger op1 = intVal;
+ BigInteger op2 = val.intVal;
if (scale < val.scale)
op1 = op1.multiply (BigInteger.valueOf (10).pow (val.scale - scale));
else if (scale > val.scale)
@@ -116,7 +117,7 @@ public class BigDecimal extends Number implements Comparable {
public BigDecimal multiply (BigDecimal val)
{
- return new BigDecimal (num.multiply (val.num), scale + val.scale);
+ return new BigDecimal (intVal.multiply (val.intVal), scale + val.scale);
}
public BigDecimal divide (BigDecimal val, int roundingMode)
@@ -135,13 +136,13 @@ public class BigDecimal extends Number implements Comparable {
if (scale < 0)
throw new ArithmeticException ("scale is negative: " + scale);
- if (num.signum () == 0) // handle special case of 0.0/0.0
+ if (intVal.signum () == 0) // handle special case of 0.0/0.0
return ZERO;
- BigInteger dividend = num.multiply (BigInteger.valueOf (10).pow
+ BigInteger dividend = intVal.multiply (BigInteger.valueOf (10).pow
(newScale + 1 - (scale - val.scale)));
- BigInteger parts[] = dividend.divideAndRemainder (val.num);
+ BigInteger parts[] = dividend.divideAndRemainder (val.intVal);
// System.out.println("int: " + parts[0]);
// System.out.println("rem: " + parts[1]);
@@ -194,12 +195,12 @@ public class BigDecimal extends Number implements Comparable {
public int compareTo (BigDecimal val)
{
if (scale == val.scale)
- return num.compareTo (val.num);
+ return intVal.compareTo (val.intVal);
BigInteger thisParts[] =
- num.divideAndRemainder (BigInteger.valueOf (10).pow (scale));
+ intVal.divideAndRemainder (BigInteger.valueOf (10).pow (scale));
BigInteger valParts[] =
- val.num.divideAndRemainder (BigInteger.valueOf (10).pow (val.scale));
+ val.intVal.divideAndRemainder (BigInteger.valueOf (10).pow (val.scale));
int compare;
if ((compare = thisParts[0].compareTo (valParts[0])) != 0)
@@ -263,7 +264,7 @@ public class BigDecimal extends Number implements Comparable {
public BigDecimal movePointLeft (int n)
{
- return (n < 0) ? movePointRight (-n) : new BigDecimal (num, scale + n);
+ return (n < 0) ? movePointRight (-n) : new BigDecimal (intVal, scale + n);
}
public BigDecimal movePointRight (int n)
@@ -272,15 +273,15 @@ public class BigDecimal extends Number implements Comparable {
return movePointLeft (-n);
if (scale >= n)
- return new BigDecimal (num, scale - n);
+ return new BigDecimal (intVal, scale - n);
- return new BigDecimal (num.multiply
+ return new BigDecimal (intVal.multiply
(BigInteger.valueOf (10).pow (n - scale)), 0);
}
public int signum ()
{
- return num.signum ();
+ return intVal.signum ();
}
public int scale ()
@@ -290,17 +291,17 @@ public class BigDecimal extends Number implements Comparable {
public BigDecimal abs ()
{
- return new BigDecimal (num.abs (), scale);
+ return new BigDecimal (intVal.abs (), scale);
}
public BigDecimal negate ()
{
- return new BigDecimal (num.negate (), scale);
+ return new BigDecimal (intVal.negate (), scale);
}
public String toString ()
{
- String bigStr = num.toString();
+ String bigStr = intVal.toString();
if (scale == 0)
return bigStr;
@@ -322,7 +323,8 @@ public class BigDecimal extends Number implements Comparable {
public BigInteger toBigInteger ()
{
- return scale == 0 ? num : num.divide (BigInteger.valueOf (10).pow (scale));
+ return scale == 0 ? intVal :
+ intVal.divide (BigInteger.valueOf (10).pow (scale));
}
diff --git a/libjava/java/math/BigInteger.java b/libjava/java/math/BigInteger.java
index 738680a..ed1f4f0 100644
--- a/libjava/java/math/BigInteger.java
+++ b/libjava/java/math/BigInteger.java
@@ -11,6 +11,9 @@ details. */
package java.math;
import gnu.gcj.math.*;
import java.util.Random;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.IOException;
/**
* @author Warren Levy <warrenl@cygnus.com>
@@ -35,8 +38,17 @@ public class BigInteger extends Number implements Comparable
* If words == null, the ival is the value of this BigInteger.
* Otherwise, the first ival elements of words make the value
* of this BigInteger, stored in little-endian order, 2's-complement form. */
- private int ival;
- private int[] words;
+ transient private int ival;
+ transient private int[] words;
+
+ // Serialization fields.
+ private int bitCount = -1;
+ private int bitLength = -1;
+ private int firstNonzeroByteNum = -2;
+ private int lowestSetBit = -2;
+ private byte[] magnitude;
+ private int signum;
+ private static final long serialVersionUID = -8287574255936472291L;
/** We pre-allocate integers in the range minFixNum..maxFixNum. */
@@ -2201,4 +2213,22 @@ public class BigInteger extends Number implements Comparable
}
return isNegative() ? x_len * 32 - i : i;
}
+
+ private void readObject(ObjectInputStream s)
+ throws IOException, ClassNotFoundException
+ {
+ s.defaultReadObject();
+ words = byteArrayToIntArray(magnitude, signum < 0 ? -1 : 0);
+ BigInteger result = make(words, words.length);
+ this.ival = result.ival;
+ this.words = result.words;
+ }
+
+ private void writeObject(ObjectOutputStream s)
+ throws IOException, ClassNotFoundException
+ {
+ signum = signum();
+ magnitude = toByteArray();
+ s.defaultWriteObject();
+ }
}