From 30a2593c2c9808d7ad118d8e120e8ce807df746a Mon Sep 17 00:00:00 2001 From: Ng Tsz Sum Date: Mon, 19 Jul 2021 22:12:45 +0800 Subject: [PATCH] MATH-1617: Ensure that "hashCode" is consistent with "equals". --- .../java/org/apache/commons/math4/legacy/linear/BigReal.java | 2 +- .../org/apache/commons/math4/legacy/linear/BigRealTest.java | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/BigReal.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/BigReal.java index 744fe1b68..6450e56a2 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/BigReal.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/linear/BigReal.java @@ -323,7 +323,7 @@ public class BigReal implements FieldElement, Comparable, Seri /** {@inheritDoc} */ @Override public int hashCode() { - return d.hashCode(); + return Double.hashCode(d.doubleValue()); } /** {@inheritDoc} */ diff --git a/commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/linear/BigRealTest.java b/commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/linear/BigRealTest.java index 9c2540443..f02741b7a 100644 --- a/commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/linear/BigRealTest.java +++ b/commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/linear/BigRealTest.java @@ -178,6 +178,7 @@ public class BigRealTest { BigReal oneWithScaleOne = new BigReal(new BigDecimal("1.0")); BigReal oneWithScaleTwo = new BigReal(new BigDecimal("1.00")); Assert.assertEquals(oneWithScaleOne, oneWithScaleTwo); + Assert.assertEquals(oneWithScaleOne.hashCode(), oneWithScaleTwo.hashCode()); } @Test