MATH-1617: Fix equality check.

Thanks to Ng Tsz Sum.
This commit is contained in:
Gilles Sadowski 2021-07-18 17:28:04 +02:00
parent 01e899a35f
commit 0b56f2cf54
4 changed files with 23 additions and 2 deletions

View File

@ -314,8 +314,8 @@ public class BigReal implements FieldElement<BigReal>, Comparable<BigReal>, Seri
return true;
}
if (other instanceof BigReal){
return d.equals(((BigReal) other).d);
if (other instanceof BigReal) {
return d.compareTo(((BigReal) other).d) == 0;
}
return false;
}

View File

@ -175,6 +175,9 @@ public class BigRealTest {
BigReal one = new BigReal(1.0);
Assert.assertFalse(one.equals(zero) || zero.equals(one));
Assert.assertTrue(one.equals(BigReal.ONE));
BigReal oneWithScaleOne = new BigReal(new BigDecimal("1.0"));
BigReal oneWithScaleTwo = new BigReal(new BigDecimal("1.00"));
Assert.assertTrue(oneWithScaleOne.equals(oneWithScaleTwo));
}
@Test

View File

@ -298,4 +298,19 @@ public class FieldLUDecompositionTest {
Assert.assertTrue(u == lu.getU());
Assert.assertTrue(p == lu.getP());
}
@Test
public void testConstructorWithBigReal() {
BigReal[][] leftMatrixData = new BigReal[][]{
{new BigReal(1), new BigReal(0), new BigReal(0), new BigReal(0)},
{new BigReal(1), new BigReal(0), new BigReal(1), new BigReal(0)},
{new BigReal(1), new BigReal(1), new BigReal(0), new BigReal(0)},
{new BigReal(1), new BigReal(1), new BigReal(1), new BigReal(1)},
};
FieldMatrix<BigReal> matrix = MatrixUtils.createFieldMatrix(leftMatrixData);
FieldLUDecomposition<BigReal> lu = new FieldLUDecomposition<>(matrix);
Assert.assertEquals(new BigReal(-1), lu.getDeterminant());
Assert.assertArrayEquals(new int[]{0, 2, 1, 3}, lu.getPivot());
}
}

View File

@ -95,6 +95,9 @@ Caveat:
nightmare was one of the main reasons for creating more focused
components.]
">
<action dev="erans" type="fix" issue="MATH-1617" due-to="Ng Tsz Sum">
Class "BigReal": Fix equality check.
</action>
<action dev="erans" type="update" issue="MATH-1595">
Clean up "o.a.c.math4.legacy.random" package.
</action>