public static void TestMultiplyDivideOne( EInteger bigintA, EInteger bigintB) { // Test that A*B/A = B and A*B/B = A try { EInteger bigintRem; EInteger bigintE; EInteger bigintD; EInteger bigintC = bigintA.Multiply (bigintB); TestCommon.CompareTestEqualAndConsistent ( bigintC, bigintB.Multiply (bigintA)); if (!bigintB.IsZero) { { EInteger [] divrem = bigintC.DivRem (bigintB); bigintD = divrem [0]; bigintRem = divrem [1]; } TestCommon.CompareTestEqualAndConsistent (bigintD, bigintA); TestCommon.CompareTestEqual (EInteger.Zero, bigintRem); bigintE = bigintC.Divide (bigintB); // Testing that DivRem and division method return // the same value TestCommon.CompareTestEqualAndConsistent (bigintD, bigintE); bigintE = bigintC.Remainder (bigintB); TestCommon.CompareTestEqualAndConsistent (bigintRem, bigintE); if (bigintE.Sign > 0 && !bigintC.Mod (bigintB).Equals (bigintE)) { TestCommon.CompareTestEqualAndConsistent ( bigintE, bigintC.Mod (bigintB)); } } if (!bigintA.IsZero) { EInteger [] divrem = bigintC.DivRem (bigintA); bigintD = divrem [0]; bigintRem = divrem [1]; TestCommon.CompareTestEqualAndConsistent (bigintD, bigintB); TestCommon.CompareTestEqual (EInteger.Zero, bigintRem); } if (!bigintB.IsZero) { EInteger [] divrem = bigintA.DivRem (bigintB); bigintC = divrem [0]; bigintRem = divrem [1]; bigintD = bigintB.Multiply (bigintC); bigintD += (EInteger)bigintRem; TestCommon.CompareTestEqualAndConsistent (bigintA, bigintD); } // ----------------------------------- // EDecimal // ----------------------------------- EDecimal edecA = EDecimal.FromEInteger (bigintA); EDecimal edecB = EDecimal.FromEInteger (bigintB); EDecimal edecC = edecA.Multiply (edecB); EDecimal edecRem; EDecimal edecE; EDecimal edecD; TestCommon.CompareTestEqualAndConsistent ( edecC, edecB.Multiply (edecA)); if (!edecB.IsZero) { EDecimal [] divrem = edecC.DivRemNaturalScale (edecB); edecD = divrem [0].Plus (null); edecRem = divrem [1]; TestCommon.CompareTestEqualAndConsistent (edecD, edecA); TestCommon.CompareTestEqual (EDecimal.Zero, edecRem); edecE = edecC.DivideToExponent (edecB, 0, ERounding.Down); // Testing that DivRemNaturalScale and division method return // the same value TestCommon.CompareTestEqualAndConsistent (edecD, edecE); edecE = edecC.RemainderNaturalScale (edecB, null); TestCommon.CompareTestEqualAndConsistent (edecRem, edecE); } if (!edecA.IsZero) { EDecimal [] divrem = edecC.DivRemNaturalScale (edecA); edecD = divrem [0].Plus (null); edecRem = divrem [1]; TestCommon.CompareTestEqualAndConsistent (edecD, edecB); TestCommon.CompareTestEqual (EDecimal.Zero, edecRem); } if (!edecB.IsZero) { EDecimal [] divrem = edecA.DivRemNaturalScale (edecB); edecC = divrem [0].Plus (null); edecRem = divrem [1]; edecD = edecB.Multiply (edecC); edecD = edecD.Add (edecRem); TestCommon.CompareTestEqualAndConsistent (edecA, edecD); } // ----------------------------------- // EFloat // ----------------------------------- EFloat efloatA = EFloat.FromEInteger (bigintA); EFloat efloatB = EFloat.FromEInteger (bigintB); EFloat efloatC = efloatA.Multiply (efloatB); EFloat efloatRem; EFloat efloatE; EFloat efloatD; TestCommon.CompareTestEqualAndConsistent ( efloatC, efloatB.Multiply (efloatA)); if (!efloatB.IsZero) { EFloat [] divrem = efloatC.DivRemNaturalScale (efloatB); efloatD = divrem [0].Plus (null); efloatRem = divrem [1]; TestCommon.CompareTestEqualAndConsistent (efloatD, efloatA); TestCommon.CompareTestEqual (EFloat.Zero, efloatRem); efloatE = efloatC.DivideToExponent (efloatB, 0, ERounding.Down); // Testing that DivRemNaturalScale and division method return // the same value TestCommon.CompareTestEqualAndConsistent (efloatD, efloatE); efloatE = efloatC.RemainderNaturalScale (efloatB, null); TestCommon.CompareTestEqualAndConsistent (efloatRem, efloatE); } if (!efloatA.IsZero) { EFloat [] divrem = efloatC.DivRemNaturalScale (efloatA); efloatD = divrem [0].Plus (null); efloatRem = divrem [1]; TestCommon.CompareTestEqualAndConsistent (efloatD, efloatB); TestCommon.CompareTestEqual (EFloat.Zero, efloatRem); } if (!efloatB.IsZero) { EFloat [] divrem = efloatA.DivRemNaturalScale (efloatB); efloatC = divrem [0].Plus (null); efloatRem = divrem [1]; efloatD = efloatB.Multiply (efloatC); efloatD = efloatD.Add (efloatRem); TestCommon.CompareTestEqualAndConsistent (efloatA, efloatD); } } catch (Exception ex) { string testLine = "TestMultiplyDivideOne (\nEInteger.FromRadixString (\"" + bigintA.ToRadixString (16) + "\",16),\nEInteger.FromRadixString (\"" + bigintB.ToRadixString (16) + "\",16));"; Console.WriteLine(testLine); throw new InvalidOperationException(ex.Message + "\n"+testLine,ex); } }