Index: src/main/java/java/math/BigInteger.java =================================================================== --- src/main/java/java/math/BigInteger.java (revision 501416) +++ src/main/java/java/math/BigInteger.java (working copy) @@ -85,6 +85,8 @@ /** @ar.org.fitc.spec_ref */ private byte[] magnitude; + + private transient int hashCode = 0; /* Public Constructors */ @@ -541,7 +543,15 @@ /** @ar.org.fitc.spec_ref */ @Override public int hashCode() { - return intValue(); + if (hashCode != 0) { + return hashCode; + } + System.out.println(digits.length); + for (int i = 0; i < digits.length; i ++) { + hashCode = (int)(hashCode * 33 + (digits[i] & 0xffffffff)); + } + hashCode = hashCode * sign; + return hashCode; } /** @ar.org.fitc.spec_ref */ Index: src/main/java/java/math/BigDecimal.java =================================================================== --- src/main/java/java/math/BigDecimal.java (revision 501416) +++ src/main/java/java/math/BigDecimal.java (working copy) @@ -74,6 +74,8 @@ /** The String representation is cached. */ private transient String toStringImage = null; + + private transient int hashCode = 0; /** * An array with powers of five that fit in the type long @@ -1368,10 +1370,18 @@ /** @ar.org.fitc.spec_ref */ @Override - public int hashCode() { - /* Take the 24 trailing bits of BigInteger hashcode - * and the 8 trailing bits of scale. */ - return ((getUnscaledValue().hashCode() << 24) | (0xFF & scale)); + public int hashCode() { + if (hashCode != 0) { + return hashCode; + } + if (bitLength < 64) { + hashCode = (int)(smallValue & 0xffffffff); + hashCode = 33 * hashCode + (int)((smallValue >> 32) & 0xffffffff); + hashCode = 17 * hashCode + scale; + return hashCode; + } + hashCode = 17 * intVal.hashCode() + scale; + return hashCode; } /** @ar.org.fitc.spec_ref */