summaryrefslogtreecommitdiff
path: root/java/math/BigInteger.java
diff options
context:
space:
mode:
authorAnthony Balkissoon <abalkiss@redhat.com>2006-02-28 18:04:37 +0000
committerAnthony Balkissoon <abalkiss@redhat.com>2006-02-28 18:04:37 +0000
commit2134d6bac7625f75de967a2e9d9e080a040437a9 (patch)
treefa57667851a219e17e66bc9c23ef05adb4862947 /java/math/BigInteger.java
parent49d6832f6bcc2afa710d1e7f6ce63baf0a617e3e (diff)
downloadclasspath-2134d6bac7625f75de967a2e9d9e080a040437a9.tar.gz
2006-02-28 Anthony Balkissoon <abalkiss@redhat.com>
* java/math/BigInteger.java: Committed patch by Rafael: developer.classpath.org/pipermail/classpath-patches/ 2006-February/000473.html (signum): Return early 0 if words == null and ival == 0. (readObject): Handle special case of magnitude.length or signum being 0. (writeObject): If signum is zero return a zero-sized byte[].
Diffstat (limited to 'java/math/BigInteger.java')
-rw-r--r--java/math/BigInteger.java22
1 files changed, 15 insertions, 7 deletions
diff --git a/java/math/BigInteger.java b/java/math/BigInteger.java
index 5a336b872..86d6924af 100644
--- a/java/math/BigInteger.java
+++ b/java/math/BigInteger.java
@@ -356,9 +356,9 @@ public class BigInteger extends Number implements Comparable
public int signum()
{
- int top = words == null ? ival : words[ival-1];
- if (top == 0 && words == null)
+ if (ival == 0 && words == null)
return 0;
+ int top = words == null ? ival : words[ival-1];
return top < 0 ? -1 : 1;
}
@@ -2227,17 +2227,25 @@ public class BigInteger extends Number implements Comparable
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;
+ if (magnitude.length == 0 || signum == 0)
+ {
+ this.ival = 0;
+ this.words = null;
+ }
+ else
+ {
+ 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();
+ magnitude = signum == 0 ? new byte[0] : toByteArray();
s.defaultWriteObject();
}
}