mpir/mpir.net/mpir.net-tests/HugeIntTests/Arithmetic.cs

1946 lines
74 KiB
C#

/*
Copyright 2014 Alex Dyachenko
This file is part of the MPIR Library.
The MPIR Library is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published
by the Free Software Foundation; either version 3 of the License, or (at
your option) any later version.
The MPIR Library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
License for more details.
You should have received a copy of the GNU Lesser General Public License
along with the MPIR Library. If not, see http://www.gnu.org/licenses/.
*/
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace MPIR.Tests.HugeIntTests
{
[TestClass]
public class Arithmetic
{
#region Add
[TestMethod]
public void IntAddHugeInt()
{
using (var a = new HugeInt("222509832503450298345029835740293845720"))
using (var b = new HugeInt("222987435987982730594288574029879874539"))
using (var c = new HugeInt())
{
c.Value = a + b;
Assert.AreEqual("445497268491433028939318409770173720259", c.ToString());
}
}
[TestMethod]
public void IntAddLimb()
{
using (var a = new HugeInt("222509832503450298345029835740293845720"))
{
var b = 4288574029879874539UL;
a.Value = a + b;
Assert.AreEqual("222509832503450298349318409770173720259", a.ToString());
}
}
[TestMethod]
public void IntAddToLimb()
{
using (var a = new HugeInt("222509832503450298345029835740293845720"))
{
var b = 4288574029879874539UL;
a.Value = b + a;
Assert.AreEqual("222509832503450298349318409770173720259", a.ToString());
}
}
[TestMethod]
public void IntAddSignedLimb()
{
using (var a = new HugeInt("222509832503450298345029835740293845720"))
{
var b = -4288574029879874539L;
a.Value = a + b;
Assert.AreEqual("222509832503450298340741261710413971181", a.ToString());
}
}
[TestMethod]
public void IntAddToSignedLimb()
{
using (var a = new HugeInt("222509832503450298345029835740293845720"))
{
var b = -4288574029879874539L;
a.Value = b + a;
Assert.AreEqual("222509832503450298340741261710413971181", a.ToString());
}
}
[TestMethod]
public void IntAddToMaxSignedLimb()
{
using (var a = new HugeInt("222509832503450298345029835740293845720"))
{
var b = long.MinValue;
a.Value = b + a;
Assert.AreEqual("222509832503450298335806463703439069912", a.ToString());
}
}
[TestMethod]
public void IntAddExpressionHugeInt()
{
using (var a = new HugeInt("222509832503450298345029835740293845720"))
using (var b = new HugeInt("222987435987982730594288574029879874539"))
using (var c = new HugeInt())
{
c.Value = 1 + (a + b);
Assert.AreEqual("445497268491433028939318409770173720260", c.ToString());
}
}
#endregion
#region Subtract
[TestMethod]
public void IntSubtractHugeInt()
{
using (var a = new HugeInt("445497268491433028939318409770173720259"))
using (var b = new HugeInt("222987435987982730594288574029879874539"))
{
a.Value = a - b;
Assert.AreEqual("222509832503450298345029835740293845720", a.ToString());
}
}
[TestMethod]
public void IntSubtractLimb()
{
using (var a = new HugeInt("222509832503450298349318409770173720259"))
{
var b = 4288574029879874539UL;
a.Value = a - b;
Assert.AreEqual("222509832503450298345029835740293845720", a.ToString());
}
}
[TestMethod]
public void IntSubtractFromLimb()
{
using (var a = new HugeInt("222509832503450298349318409770173720259"))
{
var b = 4288574029879874539UL;
a.Value = b - a;
Assert.AreEqual("-222509832503450298345029835740293845720", a.ToString());
}
}
[TestMethod]
public void IntSubtractPositiveSignedLimb()
{
using (var a = new HugeInt("222509832503450298349318409770173720259"))
{
var b = 4288574029879874539L;
a.Value = a - b;
Assert.AreEqual("222509832503450298345029835740293845720", a.ToString());
}
}
[TestMethod]
public void IntSubtractFromPositiveSignedLimb()
{
using (var a = new HugeInt("222509832503450298349318409770173720259"))
{
var b = 4288574029879874539L;
a.Value = b - a;
Assert.AreEqual("-222509832503450298345029835740293845720", a.ToString());
}
}
[TestMethod]
public void IntSubtractSignedLimb()
{
using (var a = new HugeInt("222509832503450298345029835740293845720"))
{
var b = -4288574029879874539L;
a.Value = a - b;
Assert.AreEqual("222509832503450298349318409770173720259", a.ToString());
}
}
[TestMethod]
public void IntSubtractFromSignedLimb()
{
using (var a = new HugeInt("222509832503450298345029835740293845720"))
{
var b = -4288574029879874539L;
a.Value = b - a;
Assert.AreEqual("-222509832503450298349318409770173720259", a.ToString());
}
}
#endregion
#region Multiply
[TestMethod]
public void IntMultiplyByHugeInt()
{
using (var a = new HugeInt("90234098723098475098479385345098345"))
using (var b = new HugeInt("7859487359873459872354987610987897"))
{
a.Value = a * b;
Assert.AreEqual("709193758343766370701419953880162061353595657143399816050772069730465", a.ToString());
}
}
[TestMethod]
public void IntMultiplyByLimb()
{
using (var a = new HugeInt("90234098723098475098479385345098345"))
{
ulong b = 17390538260286101342;
a.Value = a * b;
Assert.AreEqual("1569219546226477273686601978789044606491747469626478990", a.ToString());
}
}
[TestMethod]
public void IntMultiplyLimbBy()
{
using (var a = new HugeInt("90234098723098475098479385345098345"))
{
ulong b = 17390538260286101342;
a.Value = b * a;
Assert.AreEqual("1569219546226477273686601978789044606491747469626478990", a.ToString());
}
}
[TestMethod]
public void IntMultiplyBySignedLimb()
{
using (var a = new HugeInt("90234098723098475098479385345098345"))
{
long b = -7390538260286101342;
a.Value = a * b;
Assert.AreEqual("-666878558995492522701808125338061156491747469626478990", a.ToString());
}
}
[TestMethod]
public void IntMultiplySignedLimbBy()
{
using (var a = new HugeInt("90234098723098475098479385345098345"))
{
long b = -7390538260286101342;
a.Value = b * a;
Assert.AreEqual("-666878558995492522701808125338061156491747469626478990", a.ToString());
}
}
#endregion
#region Add Product
[TestMethod]
public void IntAddProductHugeInt()
{
using (var a = new HugeInt("98750293847520938457029384572093480498357"))
using (var c = new HugeInt("23094582093845093574093845093485039450934"))
using (var b = new HugeInt("-394580293847502987609283945873594873409587"))
{
var expr = a + c*b;
a.Value = expr;
Assert.AreEqual("-9112666988874677841199955832262586145147830205230375090322356322089362221491205901", a.ToString());
}
}
[TestMethod]
public void IntAddProductLimb()
{
using (var a = new HugeInt("98750293847520938457029384572093480498357"))
using (var c = new HugeInt("-23094582093845093574093845093485039450934"))
{
ulong b = 498734523097853458;
var expr = a + c*b;
a.Value = expr;
Assert.AreEqual("-11518065386718058599763388064972875060082210203928832731415", a.ToString());
}
}
[TestMethod]
public void IntAddProductLimbTo()
{
using (var a = new HugeInt("98750293847520938457029384572093480498357"))
using (var c = new HugeInt("-23094582093845093574093845093485039450934"))
{
ulong b = 498734523097853458;
var expr = a + b*c;
a.Value = expr;
Assert.AreEqual("-11518065386718058599763388064972875060082210203928832731415", a.ToString());
}
}
[TestMethod]
public void IntAddProductLimbTo2()
{
using (var a = new HugeInt("98750293847520938457029384572093480498357"))
using (var c = new HugeInt("-23094582093845093574093845093485039450934"))
{
ulong b = 498734523097853458;
var expr = b*c + a;
a.Value = expr;
Assert.AreEqual("-11518065386718058599763388064972875060082210203928832731415", a.ToString());
}
}
[TestMethod]
public void IntAddProductLimbTo3()
{
using (var a = new HugeInt("98750293847520938457029384572093480498357"))
using (var c = new HugeInt("-23094582093845093574093845093485039450934"))
using (var d = new HugeInt())
{
ulong b = 498734523097853458;
var expr = b*c + a;
d.Value = expr;
Assert.AreEqual("-11518065386718058599763388064972875060082210203928832731415", d.ToString());
}
}
[TestMethod]
public void IntAddProductSignedLimb()
{
using (var a = new HugeInt("98750293847520938457029384572093480498357"))
using (var c = new HugeInt("23094582093845093574093845093485039450934"))
{
long b = -498734523097853458;
var expr = a + c*b;
a.Value = expr;
Assert.AreEqual("-11518065386718058599763388064972875060082210203928832731415", a.ToString());
}
}
[TestMethod]
public void IntAddProductSignedLimbTo()
{
using (var a = new HugeInt("98750293847520938457029384572093480498357"))
using (var c = new HugeInt("-23094582093845093574093845093485039450934"))
{
long b = 498734523097853458;
var expr = a + b*c;
a.Value = expr;
Assert.AreEqual("-11518065386718058599763388064972875060082210203928832731415", a.ToString());
}
}
[TestMethod]
public void IntAddProductSignedLimbTo2()
{
using (var a = new HugeInt("98750293847520938457029384572093480498357"))
using (var c = new HugeInt("-23094582093845093574093845093485039450934"))
{
long b = 498734523097853458;
var expr = b*c + a;
a.Value = expr;
Assert.AreEqual("-11518065386718058599763388064972875060082210203928832731415", a.ToString());
}
}
[TestMethod]
public void IntAddProductSignedLimbTo3()
{
using (var a = new HugeInt("98750293847520938457029384572093480498357"))
using (var c = new HugeInt("23094582093845093574093845093485039450934"))
using (var d = new HugeInt())
{
long b = -498734523097853458;
var expr = b*c + a;
d.Value = expr;
Assert.AreEqual("-11518065386718058599763388064972875060082210203928832731415", d.ToString());
}
}
#endregion
#region Subtract Product
[TestMethod]
public void IntSubtractProductHugeInt()
{
using (var a = new HugeInt("98750293847520938457029384572093480498357"))
using (var c = new HugeInt("23094582093845093574093845093485039450934"))
using (var b = new HugeInt("394580293847502987609283945873594873409587"))
{
var expr = a - c*b;
a.Value = expr;
Assert.AreEqual("-9112666988874677841199955832262586145147830205230375090322356322089362221491205901", a.ToString());
}
}
[TestMethod]
public void IntSubtractProductLimb()
{
using (var a = new HugeInt("98750293847520938457029384572093480498357"))
using (var c = new HugeInt("23094582093845093574093845093485039450934"))
{
ulong b = 498734523097853458;
var expr = a - c*b;
a.Value = expr;
Assert.AreEqual("-11518065386718058599763388064972875060082210203928832731415", a.ToString());
}
}
[TestMethod]
public void IntSubtractProductSignedLimb()
{
using (var a = new HugeInt("98750293847520938457029384572093480498357"))
using (var c = new HugeInt("-23094582093845093574093845093485039450934"))
{
long b = -498734523097853458;
var expr = a - b*c;
a.Value = expr;
Assert.AreEqual("-11518065386718058599763388064972875060082210203928832731415", a.ToString());
}
}
[TestMethod]
public void IntSubtractProductSignedLimb2()
{
using (var a = new HugeInt("98750293847520938457029384572093480498357"))
using (var c = new HugeInt("-23094582093845093574093845093485039450934"))
{
long b = -498734523097853458;
a.Value = a - c*b;
Assert.AreEqual("-11518065386718058599763388064972875060082210203928832731415", a.ToString());
}
}
[TestMethod]
public void IntSubtractProductSignedLimb3()
{
using (var a = new HugeInt("98750293847520938457029384572093480498357"))
using (var c = new HugeInt("23094582093845093574093845093485039450934"))
using (var d = new HugeInt())
{
long b = 498734523097853458;
d.Value = a - c*b;
Assert.AreEqual("-11518065386718058599763388064972875060082210203928832731415", d.ToString());
}
}
#endregion
#region Shift Left
[TestMethod]
public void IntShiftLeft()
{
using (var a = new HugeInt("-12345700987ABCDEF2345CBDEFA245230948", 16))
{
ulong b = 40;
a.Value = a << b;
Assert.AreEqual("-12345700987ABCDEF2345CBDEFA2452309480000000000", a.ToString(16));
}
}
#endregion
#region Shift Right
[TestMethod]
public void IntShiftRight()
{
using (var a = new HugeInt("ABCDEF052834524092854092874502983745029345723098457209305983434345", 16))
{
ulong b = 96;
a.Value = a >> b;
Assert.AreEqual("ABCDEF052834524092854092874502983745029345", a.ToString(16));
}
}
[TestMethod]
public void IntShiftRightCeiling()
{
using (var a = new HugeInt("ABCDEF052834524092854092874502983745029345723098457209305983434345", 16))
{
ulong b = 96;
a.Value = (a >> b).Rounding(RoundingModes.Ceiling);
Assert.AreEqual("ABCDEF052834524092854092874502983745029346", a.ToString(16));
}
}
[TestMethod]
public void IntShiftRightNegativeCeiling()
{
using (var a = new HugeInt("-ABCDEF052834524092854092874502983745029345723098457209305983434345", 16))
{
ulong b = 96;
a.Value = (a >> b).Rounding(RoundingModes.Ceiling);
Assert.AreEqual("-ABCDEF052834524092854092874502983745029345", a.ToString(16));
}
}
[TestMethod]
public void IntShiftRightFloor()
{
using (var a = new HugeInt("ABCDEF052834524092854092874502983745029345723098457209305983434345", 16))
{
ulong b = 96;
a.Value = (a >> b).Rounding(RoundingModes.Floor);
Assert.AreEqual("ABCDEF052834524092854092874502983745029345", a.ToString(16));
}
}
[TestMethod]
public void IntShiftRightNegativeFloor()
{
using (var a = new HugeInt("-ABCDEF052834524092854092874502983745029345723098457209305983434345", 16))
{
ulong b = 96;
a.Value = (a >> b).Rounding(RoundingModes.Floor);
Assert.AreEqual("-ABCDEF052834524092854092874502983745029346", a.ToString(16));
}
}
[TestMethod]
public void IntShiftRightTruncate()
{
using (var a = new HugeInt("ABCDEF052834524092854092874502983745029345723098457209305983434345", 16))
{
ulong b = 96;
a.Value = (a >> b).Rounding(RoundingModes.Truncate);
Assert.AreEqual("ABCDEF052834524092854092874502983745029345", a.ToString(16));
}
}
[TestMethod]
public void IntShiftRightNegativeTruncate()
{
using (var a = new HugeInt("-ABCDEF052834524092854092874502983745029345723098457209305983434345", 16))
{
ulong b = 96;
a.Value = (a >> b).Rounding(RoundingModes.Truncate);
Assert.AreEqual("-ABCDEF052834524092854092874502983745029345", a.ToString(16));
}
}
#endregion
#region Negate
[TestMethod]
public void IntNegate()
{
using (var a = new HugeInt("24092854092874502983745029345723098457209"))
{
a.Value = -a;
Assert.AreEqual("-24092854092874502983745029345723098457209", a.ToString());
a.Value = -a;
Assert.AreEqual("24092854092874502983745029345723098457209", a.ToString());
}
}
#endregion
#region Abs
[TestMethod]
public void IntMakeAbsolute()
{
using (var a = new HugeInt("-24092854092874502983745029345723098457209"))
{
a.Value = a.Abs();
Assert.AreEqual("24092854092874502983745029345723098457209", a.ToString());
a.Value = a.Abs();
Assert.AreEqual("24092854092874502983745029345723098457209", a.ToString());
}
}
#endregion
#region Divide
#region Int
[TestMethod]
public void IntDivideHugeInt()
{
using (var a = new HugeInt("234052834524092854092874502983745029345723098457209305983434345"))
using (var b = new HugeInt("394580293847502987609283945873594873409587"))
{
a.Value = a / b;
Assert.AreEqual("593169091750307653294", a.ToString());
}
}
[TestMethod]
public void IntDivideHugeIntCeiling()
{
using (var a = new HugeInt("234052834524092854092874502983745029345723098457209305983434345"))
using (var b = new HugeInt("394580293847502987609283945873594873409587"))
{
a.Value = (a / b).Rounding(RoundingModes.Ceiling);
Assert.AreEqual("593169091750307653295", a.ToString());
}
}
[TestMethod]
public void IntDivideHugeIntNegativeCeiling()
{
using (var a = new HugeInt("-234052834524092854092874502983745029345723098457209305983434345"))
using (var b = new HugeInt("394580293847502987609283945873594873409587"))
{
a.Value = (a / b).Rounding(RoundingModes.Ceiling);
Assert.AreEqual("-593169091750307653294", a.ToString());
}
}
[TestMethod]
public void IntDivideHugeIntFloor()
{
using (var a = new HugeInt("234052834524092854092874502983745029345723098457209305983434345"))
using (var b = new HugeInt("394580293847502987609283945873594873409587"))
{
a.Value = (a / b).Rounding(RoundingModes.Floor);
Assert.AreEqual("593169091750307653294", a.ToString());
}
}
[TestMethod]
public void IntDivideHugeIntNegativeFloor()
{
using (var a = new HugeInt("-234052834524092854092874502983745029345723098457209305983434345"))
using (var b = new HugeInt("394580293847502987609283945873594873409587"))
{
a.Value = (a / b).Rounding(RoundingModes.Floor);
Assert.AreEqual("-593169091750307653295", a.ToString());
}
}
[TestMethod]
public void IntDivideHugeIntTruncate()
{
using (var a = new HugeInt("234052834524092854092874502983745029345723098457209305983434345"))
using (var b = new HugeInt("394580293847502987609283945873594873409587"))
{
a.Value = (a / b).Rounding(RoundingModes.Truncate);
Assert.AreEqual("593169091750307653294", a.ToString());
}
}
[TestMethod]
public void IntDivideHugeIntNegativeTruncate()
{
using (var a = new HugeInt("-234052834524092854092874502983745029345723098457209305983434345"))
using (var b = new HugeInt("394580293847502987609283945873594873409587"))
{
a.Value = (a / b).Rounding(RoundingModes.Truncate);
Assert.AreEqual("-593169091750307653294", a.ToString());
}
}
#endregion
#region Int with mod
[TestMethod]
public void IntDivideHugeIntCeilingWithMod()
{
using (var a = new HugeInt("234052834524092854092874502983745029345723098457209305983434345"))
using (var b = new HugeInt("394580293847502987609283945873594873409587"))
using (var c = new HugeInt())
{
a.Value = (a / b).SavingRemainderTo(c).Rounding(RoundingModes.Ceiling);
Assert.AreEqual("593169091750307653295", a.ToString());
Assert.AreEqual("-280211579611742400636461191697511341704820", c.ToString());
}
}
[TestMethod]
public void IntDivideHugeIntNegativeCeilingWithMod()
{
using (var a = new HugeInt("-234052834524092854092874502983745029345723098457209305983434345"))
using (var b = new HugeInt("394580293847502987609283945873594873409587"))
using (var c = new HugeInt())
{
a.Value = (a / b).SavingRemainderTo(c).Rounding(RoundingModes.Ceiling);
Assert.AreEqual("-593169091750307653294", a.ToString());
Assert.AreEqual("-114368714235760586972822754176083531704767", c.ToString());
}
}
[TestMethod]
public void IntDivideHugeIntFloorWithMod()
{
using (var a = new HugeInt("234052834524092854092874502983745029345723098457209305983434345"))
using (var b = new HugeInt("394580293847502987609283945873594873409587"))
using (var c = new HugeInt())
{
a.Value = (a / b).SavingRemainderTo(c).Rounding(RoundingModes.Floor);
Assert.AreEqual("593169091750307653294", a.ToString());
Assert.AreEqual("114368714235760586972822754176083531704767", c.ToString());
}
}
[TestMethod]
public void IntDivideHugeIntNegativeFloorWithMod()
{
using (var a = new HugeInt("-234052834524092854092874502983745029345723098457209305983434345"))
using (var b = new HugeInt("394580293847502987609283945873594873409587"))
using (var c = new HugeInt())
{
a.Value = (a / b).SavingRemainderTo(c).Rounding(RoundingModes.Floor);
Assert.AreEqual("-593169091750307653295", a.ToString());
Assert.AreEqual("280211579611742400636461191697511341704820", c.ToString());
}
}
[TestMethod]
public void IntDivideHugeIntTruncateWithMod()
{
using (var a = new HugeInt("234052834524092854092874502983745029345723098457209305983434345"))
using (var b = new HugeInt("394580293847502987609283945873594873409587"))
using (var c = new HugeInt())
{
a.Value = (a / b).SavingRemainderTo(c).Rounding(RoundingModes.Truncate);
Assert.AreEqual("593169091750307653294", a.ToString());
Assert.AreEqual("114368714235760586972822754176083531704767", c.ToString());
}
}
[TestMethod]
public void IntDivideHugeIntNegativeTruncateWithMod()
{
using (var a = new HugeInt("-234052834524092854092874502983745029345723098457209305983434345"))
using (var b = new HugeInt("394580293847502987609283945873594873409587"))
using (var c = new HugeInt())
{
a.Value = (a / b).SavingRemainderTo(c).Rounding(RoundingModes.Truncate);
Assert.AreEqual("-593169091750307653294", a.ToString());
Assert.AreEqual("-114368714235760586972822754176083531704767", c.ToString());
}
}
#endregion
#region Limb
[TestMethod]
public void IntDivideLimb()
{
using (var a = new HugeInt("234052834524092854092874502983745029345723098457209305983434345"))
{
ulong b = 5931690917503076532;
a.Value = a / b;
Assert.AreEqual("39458029384750298767200622330399462537522498", a.ToString());
}
}
[TestMethod]
public void IntDivideLimbCeiling()
{
using (var a = new HugeInt("234052834524092854092874502983745029345723098457209305983434345"))
{
ulong b = 5931690917503076532;
a.Value = (a / b).Rounding(RoundingModes.Ceiling);
Assert.AreEqual("39458029384750298767200622330399462537522499", a.ToString());
}
}
[TestMethod]
public void IntDivideLimbNegativeCeiling()
{
using (var a = new HugeInt("-234052834524092854092874502983745029345723098457209305983434345"))
{
ulong b = 5931690917503076532;
a.Value = (a / b).Rounding(RoundingModes.Ceiling);
Assert.AreEqual("-39458029384750298767200622330399462537522498", a.ToString());
}
}
[TestMethod]
public void IntDivideLimbFloor()
{
using (var a = new HugeInt("234052834524092854092874502983745029345723098457209305983434345"))
{
ulong b = 5931690917503076532;
a.Value = (a / b).Rounding(RoundingModes.Floor);
Assert.AreEqual("39458029384750298767200622330399462537522498", a.ToString());
}
}
[TestMethod]
public void IntDivideLimbNegativeFloor()
{
using (var a = new HugeInt("-234052834524092854092874502983745029345723098457209305983434345"))
{
ulong b = 5931690917503076532;
a.Value = (a / b).Rounding(RoundingModes.Floor);
Assert.AreEqual("-39458029384750298767200622330399462537522499", a.ToString());
}
}
[TestMethod]
public void IntDivideLimbTruncate()
{
using (var a = new HugeInt("234052834524092854092874502983745029345723098457209305983434345"))
{
ulong b = 5931690917503076532;
a.Value = (a / b).Rounding(RoundingModes.Truncate);
Assert.AreEqual("39458029384750298767200622330399462537522498", a.ToString());
}
}
[TestMethod]
public void IntDivideLimbNegativeTruncate()
{
using (var a = new HugeInt("-234052834524092854092874502983745029345723098457209305983434345"))
{
ulong b = 5931690917503076532;
a.Value = (a / b).Rounding(RoundingModes.Truncate);
Assert.AreEqual("-39458029384750298767200622330399462537522498", a.ToString());
}
}
#endregion
#region Limb with Mod
[TestMethod]
public void IntDivideLimbWithMod()
{
using (var a = new HugeInt("234052834524092854092874502983745029345723098457209305983434345"))
using (var c = new HugeInt())
{
ulong b = 5931690917503076532;
a.Value = (a / b).SavingRemainderTo(c);
Assert.AreEqual("39458029384750298767200622330399462537522498", a.ToString());
Assert.AreEqual("5599417901817617409", c.ToString());
}
}
[TestMethod]
public void IntDivideLimbCeilingWithMod()
{
using (var a = new HugeInt("234052834524092854092874502983745029345723098457209305983434345"))
using (var c = new HugeInt())
{
ulong b = 5931690917503076532;
a.Value = (a / b).SavingRemainderTo(c).Rounding(RoundingModes.Ceiling);
Assert.AreEqual("39458029384750298767200622330399462537522499", a.ToString());
Assert.AreEqual("-332273015685459123", c.ToString());
}
}
[TestMethod]
public void IntDivideLimbNegativeCeilingWithMod()
{
using (var a = new HugeInt("-234052834524092854092874502983745029345723098457209305983434345"))
using (var c = new HugeInt())
{
ulong b = 5931690917503076532;
a.Value = (a / b).SavingRemainderTo(c).Rounding(RoundingModes.Ceiling);
Assert.AreEqual("-39458029384750298767200622330399462537522498", a.ToString());
Assert.AreEqual("-5599417901817617409", c.ToString());
}
}
[TestMethod]
public void IntDivideLimbFloorWithMod()
{
using (var a = new HugeInt("234052834524092854092874502983745029345723098457209305983434345"))
using (var c = new HugeInt())
{
ulong b = 5931690917503076532;
a.Value = (a / b).SavingRemainderTo(c).Rounding(RoundingModes.Floor);
Assert.AreEqual("39458029384750298767200622330399462537522498", a.ToString());
Assert.AreEqual("5599417901817617409", c.ToString());
}
}
[TestMethod]
public void IntDivideLimbNegativeFloorWithMod()
{
using (var a = new HugeInt("-234052834524092854092874502983745029345723098457209305983434345"))
using (var c = new HugeInt())
{
ulong b = 5931690917503076532;
a.Value = (a / b).SavingRemainderTo(c).Rounding(RoundingModes.Floor);
Assert.AreEqual("-39458029384750298767200622330399462537522499", a.ToString());
Assert.AreEqual("332273015685459123", c.ToString());
}
}
[TestMethod]
public void IntDivideLimbTruncateWithMod()
{
using (var a = new HugeInt("234052834524092854092874502983745029345723098457209305983434345"))
using (var c = new HugeInt())
{
ulong b = 5931690917503076532;
a.Value = (a / b).SavingRemainderTo(c).Rounding(RoundingModes.Truncate);
Assert.AreEqual("39458029384750298767200622330399462537522498", a.ToString());
Assert.AreEqual("5599417901817617409", c.ToString());
}
}
[TestMethod]
public void IntDivideLimbNegativeTruncateWithMod()
{
using (var a = new HugeInt("-234052834524092854092874502983745029345723098457209305983434345"))
using (var c = new HugeInt())
{
ulong b = 5931690917503076532;
a.Value = (a / b).SavingRemainderTo(c).Rounding(RoundingModes.Truncate);
Assert.AreEqual("-39458029384750298767200622330399462537522498", a.ToString());
Assert.AreEqual("-5599417901817617409", c.ToString());
}
}
#endregion
#region Limb with Mod x 2
[TestMethod]
public void IntDivideLimbWithMod2()
{
using (var a = new HugeInt("234052834524092854092874502983745029345723098457209305983434345"))
using (var c = new HugeInt())
{
ulong b = 5931690917503076532;
ulong d = 0;
a.Value = (a / b).SettingRemainderTo(x => d = x).SavingRemainderTo(c);
Assert.AreEqual("39458029384750298767200622330399462537522498", a.ToString());
Assert.AreEqual("5599417901817617409", c.ToString());
Assert.AreEqual(d.ToString(), c.ToString());
}
}
[TestMethod]
public void IntDivideLimbCeilingWithMod2()
{
using (var a = new HugeInt("234052834524092854092874502983745029345723098457209305983434345"))
using (var c = new HugeInt())
{
ulong b = 5931690917503076532;
ulong d = 0;
a.Value = (a / b).SettingRemainderTo(x => d = x).SavingRemainderTo(c).Rounding(RoundingModes.Ceiling);
Assert.AreEqual("39458029384750298767200622330399462537522499", a.ToString());
Assert.AreEqual("-332273015685459123", c.ToString());
Assert.AreEqual("-" + d.ToString(), c.ToString());
}
}
[TestMethod]
public void IntDivideLimbNegativeCeilingWithMod2()
{
using (var a = new HugeInt("-234052834524092854092874502983745029345723098457209305983434345"))
using (var c = new HugeInt())
{
ulong b = 5931690917503076532;
ulong d = 0;
a.Value = (a / b).SettingRemainderTo(x => d = x).SavingRemainderTo(c).Rounding(RoundingModes.Ceiling);
Assert.AreEqual("-39458029384750298767200622330399462537522498", a.ToString());
Assert.AreEqual("-5599417901817617409", c.ToString());
Assert.AreEqual("-" + d.ToString(), c.ToString());
}
}
[TestMethod]
public void IntDivideLimbFloorWithMod2()
{
using (var a = new HugeInt("234052834524092854092874502983745029345723098457209305983434345"))
using (var c = new HugeInt())
{
ulong b = 5931690917503076532;
ulong d = 0;
a.Value = (a / b).SettingRemainderTo(x => d = x).SavingRemainderTo(c).Rounding(RoundingModes.Floor);
Assert.AreEqual("39458029384750298767200622330399462537522498", a.ToString());
Assert.AreEqual("5599417901817617409", c.ToString());
Assert.AreEqual(d.ToString(), c.ToString());
}
}
[TestMethod]
public void IntDivideLimbNegativeFloorWithMod2()
{
using (var a = new HugeInt("-234052834524092854092874502983745029345723098457209305983434345"))
using (var c = new HugeInt())
{
ulong b = 5931690917503076532;
ulong d = 0;
a.Value = (a / b).SettingRemainderTo(x => d = x).SavingRemainderTo(c).Rounding(RoundingModes.Floor);
Assert.AreEqual("-39458029384750298767200622330399462537522499", a.ToString());
Assert.AreEqual("332273015685459123", c.ToString());
Assert.AreEqual(d.ToString(), c.ToString());
}
}
[TestMethod]
public void IntDivideLimbTruncateWithMod2()
{
using (var a = new HugeInt("234052834524092854092874502983745029345723098457209305983434345"))
using (var c = new HugeInt())
{
ulong b = 5931690917503076532;
ulong d = 0;
a.Value = (a / b).SettingRemainderTo(x => d = x).SavingRemainderTo(c).Rounding(RoundingModes.Truncate);
Assert.AreEqual("39458029384750298767200622330399462537522498", a.ToString());
Assert.AreEqual("5599417901817617409", c.ToString());
Assert.AreEqual(d.ToString(), c.ToString());
}
}
[TestMethod]
public void IntDivideLimbNegativeTruncateWithMod2()
{
using (var a = new HugeInt("-234052834524092854092874502983745029345723098457209305983434345"))
using (var c = new HugeInt())
{
ulong b = 5931690917503076532;
ulong d = 0;
a.Value = (a / b).SettingRemainderTo(x => d = x).SavingRemainderTo(c).Rounding(RoundingModes.Truncate);
Assert.AreEqual("-39458029384750298767200622330399462537522498", a.ToString());
Assert.AreEqual("-5599417901817617409", c.ToString());
Assert.AreEqual("-" + d.ToString(), c.ToString());
}
}
#endregion
#region Limb with Limb Mod
[TestMethod]
public void IntDivideLimbWithMod3()
{
using (var a = new HugeInt("234052834524092854092874502983745029345723098457209305983434345"))
{
ulong b = 5931690917503076532;
ulong d = 0;
a.Value = (a / b).SettingRemainderTo(x => d = x);
Assert.AreEqual("39458029384750298767200622330399462537522498", a.ToString());
Assert.AreEqual("5599417901817617409", d.ToString());
}
}
[TestMethod]
public void IntDivideLimbCeilingWithMod3()
{
using (var a = new HugeInt("234052834524092854092874502983745029345723098457209305983434345"))
{
ulong b = 5931690917503076532;
ulong d = 0;
a.Value = (a / b).SettingRemainderTo(x => d = x).Rounding(RoundingModes.Ceiling);
Assert.AreEqual("39458029384750298767200622330399462537522499", a.ToString());
Assert.AreEqual("332273015685459123", d.ToString());
}
}
[TestMethod]
public void IntDivideLimbNegativeCeilingWithMod3()
{
using (var a = new HugeInt("-234052834524092854092874502983745029345723098457209305983434345"))
{
ulong b = 5931690917503076532;
ulong d = 0;
a.Value = (a / b).SettingRemainderTo(x => d = x).Rounding(RoundingModes.Ceiling);
Assert.AreEqual("-39458029384750298767200622330399462537522498", a.ToString());
Assert.AreEqual("5599417901817617409", d.ToString());
}
}
[TestMethod]
public void IntDivideLimbFloorWithMod3()
{
using (var a = new HugeInt("234052834524092854092874502983745029345723098457209305983434345"))
{
ulong b = 5931690917503076532;
ulong d = 0;
a.Value = (a / b).SettingRemainderTo(x => d = x).Rounding(RoundingModes.Floor);
Assert.AreEqual("39458029384750298767200622330399462537522498", a.ToString());
Assert.AreEqual("5599417901817617409", d.ToString());
}
}
[TestMethod]
public void IntDivideLimbNegativeFloorWithMod3()
{
using (var a = new HugeInt("-234052834524092854092874502983745029345723098457209305983434345"))
{
ulong b = 5931690917503076532;
ulong d = 0;
a.Value = (a / b).SettingRemainderTo(x => d = x).Rounding(RoundingModes.Floor);
Assert.AreEqual("-39458029384750298767200622330399462537522499", a.ToString());
Assert.AreEqual("332273015685459123", d.ToString());
}
}
[TestMethod]
public void IntDivideLimbTruncateWithMod3()
{
using (var a = new HugeInt("234052834524092854092874502983745029345723098457209305983434345"))
{
ulong b = 5931690917503076532;
ulong d = 0;
a.Value = (a / b).SettingRemainderTo(x => d = x).Rounding(RoundingModes.Truncate);
Assert.AreEqual("39458029384750298767200622330399462537522498", a.ToString());
Assert.AreEqual("5599417901817617409", d.ToString());
}
}
[TestMethod]
public void IntDivideLimbNegativeTruncateWithMod3()
{
using (var a = new HugeInt("-234052834524092854092874502983745029345723098457209305983434345"))
{
ulong b = 5931690917503076532;
ulong d = 0;
a.Value = (a / b).SettingRemainderTo(x => d = x).Rounding(RoundingModes.Truncate);
Assert.AreEqual("-39458029384750298767200622330399462537522498", a.ToString());
Assert.AreEqual("5599417901817617409", d.ToString());
}
}
#endregion
#region Exact
[TestMethod]
public void IntDivideExactlyHugeInt()
{
using (var a = new HugeInt("234052834524092854092874502983745029345723098457209305983434345"))
using (var b = new HugeInt("394580293847502987609283945873594873409587"))
using (var c = new HugeInt())
{
c.Value = (a * b).DivideExactly(b);
Assert.AreEqual(a.ToString(), c.ToString());
}
}
[TestMethod]
public void IntDivideExactlyLimb()
{
using (var a = new HugeInt("234052834524092854092874502983745029345723098457209305983434345"))
using (var c = new HugeInt())
{
ulong b = 5931690917503076532;
c.Value = (a * b).DivideExactly(b);
Assert.AreEqual(a.ToString(), c.ToString());
}
}
#endregion
#region IsDivisible
[TestMethod]
public void IntIsDivisibleByHugeInt()
{
using (var a = new HugeInt("234052834524092854092874502983745029345723098457209305983434345"))
using (var b = new HugeInt("394580293847502987609283945873594873409587"))
{
a.Value = (a * b);
Assert.IsTrue(a.IsDivisibleBy(b));
a.Value = a + 1;
Assert.IsFalse(a.IsDivisibleBy(b));
}
}
[TestMethod]
public void IntIsDivisibleByLimb()
{
using (var a = new HugeInt("234052834524092854092874502983745029345723098457209305983434345"))
{
ulong b = 5931690917503076532;
a.Value = (a * b);
Assert.IsTrue(a.IsDivisibleBy(b));
a.Value = a + 1;
Assert.IsFalse(a.IsDivisibleBy(b));
}
}
[TestMethod]
public void IntIsDivisibleByPowerOf2()
{
using (var a = new HugeInt("234052834524092854092874502983745029345723098457209305983434345"))
{
ulong b = 40;
a.Value = (a << b);
Assert.IsTrue(a.IsDivisibleByPowerOf2(b));
Assert.IsFalse(a.IsDivisibleByPowerOf2(b + 1));
}
}
#endregion
#region IsCongruent
[TestMethod]
public void IntIsCongruentToHugeInt()
{
using (var a = new HugeInt("234052834524092854092874502983745029345723098457209305983434345"))
using (var b = new HugeInt("394580293847502987609283945873594873409587"))
using (var c = new HugeInt("293847502987609283945873594873409587"))
{
a.Value = (a * b) + c;
Assert.IsTrue(a.IsCongruentTo(c, b));
a.Value = a + 1;
Assert.IsFalse(a.IsCongruentTo(c, b));
}
}
[TestMethod]
public void IntIsCongruentToLimb()
{
using (var a = new HugeInt("234052834524092854092874502983745029345723098457209305983434345"))
{
ulong b = 5931690917503076532;
ulong c = 98764938475983745;
a.Value = (a * b) + c;
Assert.IsTrue(a.IsCongruentTo(c, b));
a.Value = a + 1;
Assert.IsFalse(a.IsCongruentTo(c, b));
}
}
[TestMethod]
public void IntIsCongruentToPowerOf2()
{
using (var a = new HugeInt("234052834524092854092874502983745029345723098457209305983434345"))
using (var c = new HugeInt("293847502987609283945873594873409587"))
{
ulong b = 120;
a.Value = (a << b) + c;
Assert.IsTrue(a.IsCongruentToModPowerOf2(c, b));
Assert.IsFalse(a.IsCongruentToModPowerOf2(c, b + 3));
c.Value = c + 1;
Assert.IsFalse(a.IsCongruentToModPowerOf2(c, b));
}
}
#endregion
#endregion
#region Mod
#region Int
[TestMethod]
public void IntModHugeInt()
{
using (var a = new HugeInt("234052834524092854092874502983745029345723098457209305983434345"))
using (var b = new HugeInt("394580293847502987609283945873594873409587"))
{
a.Value = a % b;
Assert.AreEqual("114368714235760586972822754176083531704767", a.ToString());
}
}
[TestMethod]
public void IntModHugeIntCeiling()
{
using (var a = new HugeInt("234052834524092854092874502983745029345723098457209305983434345"))
using (var b = new HugeInt("394580293847502987609283945873594873409587"))
{
a.Value = (a % b).Rounding(RoundingModes.Ceiling);
Assert.AreEqual("-280211579611742400636461191697511341704820", a.ToString());
}
}
[TestMethod]
public void IntModHugeIntNegativeCeiling()
{
using (var a = new HugeInt("-234052834524092854092874502983745029345723098457209305983434345"))
using (var b = new HugeInt("394580293847502987609283945873594873409587"))
{
a.Value = (a % b).Rounding(RoundingModes.Ceiling);
Assert.AreEqual("-114368714235760586972822754176083531704767", a.ToString());
}
}
[TestMethod]
public void IntModHugeIntFloor()
{
using (var a = new HugeInt("234052834524092854092874502983745029345723098457209305983434345"))
using (var b = new HugeInt("394580293847502987609283945873594873409587"))
{
a.Value = (a % b).Rounding(RoundingModes.Floor);
Assert.AreEqual("114368714235760586972822754176083531704767", a.ToString());
}
}
[TestMethod]
public void IntModHugeIntNegativeFloor()
{
using (var a = new HugeInt("-234052834524092854092874502983745029345723098457209305983434345"))
using (var b = new HugeInt("394580293847502987609283945873594873409587"))
{
a.Value = (a % b).Rounding(RoundingModes.Floor);
Assert.AreEqual("280211579611742400636461191697511341704820", a.ToString());
}
}
[TestMethod]
public void IntModHugeIntTruncate()
{
using (var a = new HugeInt("234052834524092854092874502983745029345723098457209305983434345"))
using (var b = new HugeInt("394580293847502987609283945873594873409587"))
{
a.Value = (a % b).Rounding(RoundingModes.Truncate);
Assert.AreEqual("114368714235760586972822754176083531704767", a.ToString());
}
}
[TestMethod]
public void IntModHugeIntNegativeTruncate()
{
using (var a = new HugeInt("-234052834524092854092874502983745029345723098457209305983434345"))
using (var b = new HugeInt("394580293847502987609283945873594873409587"))
{
a.Value = (a % b).Rounding(RoundingModes.Truncate);
Assert.AreEqual("-114368714235760586972822754176083531704767", a.ToString());
}
}
#endregion
#region Int with quotient
[TestMethod]
public void IntModHugeIntCeilingWithQuotient()
{
using (var a = new HugeInt("234052834524092854092874502983745029345723098457209305983434345"))
using (var b = new HugeInt("394580293847502987609283945873594873409587"))
using (var c = new HugeInt())
{
c.Value = (a % b).SavingQuotientTo(a).Rounding(RoundingModes.Ceiling);
Assert.AreEqual("593169091750307653295", a.ToString());
Assert.AreEqual("-280211579611742400636461191697511341704820", c.ToString());
}
}
[TestMethod]
public void IntModHugeIntNegativeCeilingWithQuotient()
{
using (var a = new HugeInt("-234052834524092854092874502983745029345723098457209305983434345"))
using (var b = new HugeInt("394580293847502987609283945873594873409587"))
using (var c = new HugeInt())
{
c.Value = (a % b).SavingQuotientTo(a).Rounding(RoundingModes.Ceiling);
Assert.AreEqual("-593169091750307653294", a.ToString());
Assert.AreEqual("-114368714235760586972822754176083531704767", c.ToString());
}
}
[TestMethod]
public void IntModHugeIntFloorWithQuotient()
{
using (var a = new HugeInt("234052834524092854092874502983745029345723098457209305983434345"))
using (var b = new HugeInt("394580293847502987609283945873594873409587"))
using (var c = new HugeInt())
{
c.Value = (a % b).SavingQuotientTo(a).Rounding(RoundingModes.Floor);
Assert.AreEqual("593169091750307653294", a.ToString());
Assert.AreEqual("114368714235760586972822754176083531704767", c.ToString());
}
}
[TestMethod]
public void IntModHugeIntNegativeFloorWithQuotient()
{
using (var a = new HugeInt("-234052834524092854092874502983745029345723098457209305983434345"))
using (var b = new HugeInt("394580293847502987609283945873594873409587"))
using (var c = new HugeInt())
{
c.Value = (a % b).SavingQuotientTo(a).Rounding(RoundingModes.Floor);
Assert.AreEqual("-593169091750307653295", a.ToString());
Assert.AreEqual("280211579611742400636461191697511341704820", c.ToString());
}
}
[TestMethod]
public void IntModHugeIntTruncateWithQuotient()
{
using (var a = new HugeInt("234052834524092854092874502983745029345723098457209305983434345"))
using (var b = new HugeInt("394580293847502987609283945873594873409587"))
using (var c = new HugeInt())
{
c.Value = (a % b).SavingQuotientTo(a).Rounding(RoundingModes.Truncate);
Assert.AreEqual("593169091750307653294", a.ToString());
Assert.AreEqual("114368714235760586972822754176083531704767", c.ToString());
}
}
[TestMethod]
public void IntModHugeIntNegativeTruncateWithQuotient()
{
using (var a = new HugeInt("-234052834524092854092874502983745029345723098457209305983434345"))
using (var b = new HugeInt("394580293847502987609283945873594873409587"))
using (var c = new HugeInt())
{
c.Value = (a % b).SavingQuotientTo(a).Rounding(RoundingModes.Truncate);
Assert.AreEqual("-593169091750307653294", a.ToString());
Assert.AreEqual("-114368714235760586972822754176083531704767", c.ToString());
}
}
#endregion
#region Limb
[TestMethod]
public void IntModLimb()
{
using (var a = new HugeInt("234052834524092854092874502983745029345723098457209305983434345"))
{
ulong b = 5931690917503076532;
a.Value = (a % b);
Assert.AreEqual("5599417901817617409", a.ToString());
}
}
[TestMethod]
public void IntModLimbCeiling()
{
using (var a = new HugeInt("234052834524092854092874502983745029345723098457209305983434345"))
{
ulong b = 5931690917503076532;
a.Value = (a % b).Rounding(RoundingModes.Ceiling);
Assert.AreEqual("-332273015685459123", a.ToString());
}
}
[TestMethod]
public void IntModLimbNegativeCeiling()
{
using (var a = new HugeInt("-234052834524092854092874502983745029345723098457209305983434345"))
{
ulong b = 5931690917503076532;
a.Value = (a % b).Rounding(RoundingModes.Ceiling);
Assert.AreEqual("-5599417901817617409", a.ToString());
}
}
[TestMethod]
public void IntModLimbFloor()
{
using (var a = new HugeInt("234052834524092854092874502983745029345723098457209305983434345"))
{
ulong b = 5931690917503076532;
a.Value = (a % b).Rounding(RoundingModes.Floor);
Assert.AreEqual("5599417901817617409", a.ToString());
}
}
[TestMethod]
public void IntModLimbNegativeFloor()
{
using (var a = new HugeInt("-234052834524092854092874502983745029345723098457209305983434345"))
{
ulong b = 5931690917503076532;
a.Value = (a % b).Rounding(RoundingModes.Floor);
Assert.AreEqual("332273015685459123", a.ToString());
}
}
[TestMethod]
public void IntModLimbTruncate()
{
using (var a = new HugeInt("234052834524092854092874502983745029345723098457209305983434345"))
{
ulong b = 5931690917503076532;
a.Value = (a % b).Rounding(RoundingModes.Truncate);
Assert.AreEqual("5599417901817617409", a.ToString());
}
}
[TestMethod]
public void IntModLimbNegativeTruncate()
{
using (var a = new HugeInt("-234052834524092854092874502983745029345723098457209305983434345"))
{
ulong b = 5931690917503076532;
a.Value = (a % b).Rounding(RoundingModes.Truncate);
Assert.AreEqual("-5599417901817617409", a.ToString());
}
}
#endregion
#region Limb With Quotient
[TestMethod]
public void IntModLimbWithQuotient()
{
using (var a = new HugeInt("234052834524092854092874502983745029345723098457209305983434345"))
using (var c = new HugeInt())
{
ulong b = 5931690917503076532;
a.Value = (a % b).SavingQuotientTo(c);
Assert.AreEqual("39458029384750298767200622330399462537522498", c.ToString());
Assert.AreEqual("5599417901817617409", a.ToString());
}
}
[TestMethod]
public void IntModLimbCeilingWithQuotient()
{
using (var a = new HugeInt("234052834524092854092874502983745029345723098457209305983434345"))
using (var c = new HugeInt())
{
ulong b = 5931690917503076532;
a.Value = (a % b).SavingQuotientTo(c).Rounding(RoundingModes.Ceiling);
Assert.AreEqual("39458029384750298767200622330399462537522499", c.ToString());
Assert.AreEqual("-332273015685459123", a.ToString());
}
}
[TestMethod]
public void IntModLimbNegativeCeilingWithQuotient()
{
using (var a = new HugeInt("-234052834524092854092874502983745029345723098457209305983434345"))
using (var c = new HugeInt())
{
ulong b = 5931690917503076532;
a.Value = (a % b).SavingQuotientTo(c).Rounding(RoundingModes.Ceiling);
Assert.AreEqual("-39458029384750298767200622330399462537522498", c.ToString());
Assert.AreEqual("-5599417901817617409", a.ToString());
}
}
[TestMethod]
public void IntModLimbFloorWithQuotient()
{
using (var a = new HugeInt("234052834524092854092874502983745029345723098457209305983434345"))
using (var c = new HugeInt())
{
ulong b = 5931690917503076532;
a.Value = (a % b).SavingQuotientTo(c).Rounding(RoundingModes.Floor);
Assert.AreEqual("39458029384750298767200622330399462537522498", c.ToString());
Assert.AreEqual("5599417901817617409", a.ToString());
}
}
[TestMethod]
public void IntModLimbNegativeFloorWithQuotient()
{
using (var a = new HugeInt("-234052834524092854092874502983745029345723098457209305983434345"))
using (var c = new HugeInt())
{
ulong b = 5931690917503076532;
a.Value = (a % b).SavingQuotientTo(c).Rounding(RoundingModes.Floor);
Assert.AreEqual("-39458029384750298767200622330399462537522499", c.ToString());
Assert.AreEqual("332273015685459123", a.ToString());
}
}
[TestMethod]
public void IntModLimbTruncateWithQuotient()
{
using (var a = new HugeInt("234052834524092854092874502983745029345723098457209305983434345"))
using (var c = new HugeInt())
{
ulong b = 5931690917503076532;
a.Value = (a % b).SavingQuotientTo(c).Rounding(RoundingModes.Truncate);
Assert.AreEqual("39458029384750298767200622330399462537522498", c.ToString());
Assert.AreEqual("5599417901817617409", a.ToString());
}
}
[TestMethod]
public void IntModLimbNegativeTruncateWithQuotient()
{
using (var a = new HugeInt("-234052834524092854092874502983745029345723098457209305983434345"))
using (var c = new HugeInt())
{
ulong b = 5931690917503076532;
a.Value = (a % b).SavingQuotientTo(c).Rounding(RoundingModes.Truncate);
Assert.AreEqual("-39458029384750298767200622330399462537522498", c.ToString());
Assert.AreEqual("-5599417901817617409", a.ToString());
}
}
#endregion
#region Limb With Quotient and Limb Mod
[TestMethod]
public void IntModLimbWithQuotient2()
{
using (var a = new HugeInt("234052834524092854092874502983745029345723098457209305983434345"))
using (var c = new HugeInt())
{
ulong b = 5931690917503076532;
ulong d = 0;
a.Value = (a % b).SettingRemainderTo(x => d = x).SavingQuotientTo(c);
Assert.AreEqual("39458029384750298767200622330399462537522498", c.ToString());
Assert.AreEqual("5599417901817617409", a.ToString());
Assert.AreEqual(d.ToString(), a.ToString());
}
}
[TestMethod]
public void IntModLimbCeilingWithQuotient2()
{
using (var a = new HugeInt("234052834524092854092874502983745029345723098457209305983434345"))
using (var c = new HugeInt())
{
ulong b = 5931690917503076532;
ulong d = 0;
a.Value = (a % b).SettingRemainderTo(x => d = x).SavingQuotientTo(c).Rounding(RoundingModes.Ceiling);
Assert.AreEqual("39458029384750298767200622330399462537522499", c.ToString());
Assert.AreEqual("-332273015685459123", a.ToString());
Assert.AreEqual("-" + d.ToString(), a.ToString());
}
}
[TestMethod]
public void IntModLimbNegativeCeilingWithQuotient2()
{
using (var a = new HugeInt("-234052834524092854092874502983745029345723098457209305983434345"))
using (var c = new HugeInt())
{
ulong b = 5931690917503076532;
ulong d = 0;
a.Value = (a % b).SettingRemainderTo(x => d = x).SavingQuotientTo(c).Rounding(RoundingModes.Ceiling);
Assert.AreEqual("-39458029384750298767200622330399462537522498", c.ToString());
Assert.AreEqual("-5599417901817617409", a.ToString());
Assert.AreEqual("-" + d.ToString(), a.ToString());
}
}
[TestMethod]
public void IntModLimbFloorWithQuotient2()
{
using (var a = new HugeInt("234052834524092854092874502983745029345723098457209305983434345"))
using (var c = new HugeInt())
{
ulong b = 5931690917503076532;
ulong d = 0;
a.Value = (a % b).SettingRemainderTo(x => d = x).SavingQuotientTo(c).Rounding(RoundingModes.Floor);
Assert.AreEqual("39458029384750298767200622330399462537522498", c.ToString());
Assert.AreEqual("5599417901817617409", a.ToString());
Assert.AreEqual(d.ToString(), a.ToString());
}
}
[TestMethod]
public void IntModLimbNegativeFloorWithQuotient2()
{
using (var a = new HugeInt("-234052834524092854092874502983745029345723098457209305983434345"))
using (var c = new HugeInt())
{
ulong b = 5931690917503076532;
ulong d = 0;
a.Value = (a % b).SettingRemainderTo(x => d = x).SavingQuotientTo(c).Rounding(RoundingModes.Floor);
Assert.AreEqual("-39458029384750298767200622330399462537522499", c.ToString());
Assert.AreEqual("332273015685459123", a.ToString());
Assert.AreEqual(d.ToString(), a.ToString());
}
}
[TestMethod]
public void IntModLimbTruncateWithQuotient2()
{
using (var a = new HugeInt("234052834524092854092874502983745029345723098457209305983434345"))
using (var c = new HugeInt())
{
ulong b = 5931690917503076532;
ulong d = 0;
a.Value = (a % b).SettingRemainderTo(x => d = x).SavingQuotientTo(c).Rounding(RoundingModes.Truncate);
Assert.AreEqual("39458029384750298767200622330399462537522498", c.ToString());
Assert.AreEqual("5599417901817617409", a.ToString());
Assert.AreEqual(d.ToString(), a.ToString());
}
}
[TestMethod]
public void IntModLimbNegativeTruncateWithQuotient2()
{
using (var a = new HugeInt("-234052834524092854092874502983745029345723098457209305983434345"))
using (var c = new HugeInt())
{
ulong b = 5931690917503076532;
ulong d = 0;
a.Value = (a % b).SettingRemainderTo(x => d = x).SavingQuotientTo(c).Rounding(RoundingModes.Truncate);
Assert.AreEqual("-39458029384750298767200622330399462537522498", c.ToString());
Assert.AreEqual("-5599417901817617409", a.ToString());
Assert.AreEqual("-" + d.ToString(), a.ToString());
}
}
#endregion
#region Limb With Limb Mod
[TestMethod]
public void IntModLimbWithQuotient3()
{
using (var a = new HugeInt("234052834524092854092874502983745029345723098457209305983434345"))
{
ulong b = 5931690917503076532;
ulong d = 0;
a.Value = (a % b).SettingRemainderTo(x => d = x);
Assert.AreEqual("5599417901817617409", a.ToString());
Assert.AreEqual(d.ToString(), a.ToString());
}
}
[TestMethod]
public void IntModLimbCeilingWithQuotient3()
{
using (var a = new HugeInt("234052834524092854092874502983745029345723098457209305983434345"))
{
ulong b = 5931690917503076532;
ulong d = 0;
a.Value = (a % b).SettingRemainderTo(x => d = x).Rounding(RoundingModes.Ceiling);
Assert.AreEqual("-332273015685459123", a.ToString());
Assert.AreEqual("-" + d.ToString(), a.ToString());
}
}
[TestMethod]
public void IntModLimbNegativeCeilingWithQuotient3()
{
using (var a = new HugeInt("-234052834524092854092874502983745029345723098457209305983434345"))
{
ulong b = 5931690917503076532;
ulong d = 0;
a.Value = (a % b).SettingRemainderTo(x => d = x).Rounding(RoundingModes.Ceiling);
Assert.AreEqual("-5599417901817617409", a.ToString());
Assert.AreEqual("-" + d.ToString(), a.ToString());
}
}
[TestMethod]
public void IntModLimbFloorWithQuotient3()
{
using (var a = new HugeInt("234052834524092854092874502983745029345723098457209305983434345"))
{
ulong b = 5931690917503076532;
ulong d = 0;
a.Value = (a % b).SettingRemainderTo(x => d = x).Rounding(RoundingModes.Floor);
Assert.AreEqual("5599417901817617409", a.ToString());
Assert.AreEqual(d.ToString(), a.ToString());
}
}
[TestMethod]
public void IntModLimbNegativeFloorWithQuotient3()
{
using (var a = new HugeInt("-234052834524092854092874502983745029345723098457209305983434345"))
{
ulong b = 5931690917503076532;
ulong d = 0;
a.Value = (a % b).SettingRemainderTo(x => d = x).Rounding(RoundingModes.Floor);
Assert.AreEqual("332273015685459123", a.ToString());
Assert.AreEqual(d.ToString(), a.ToString());
}
}
[TestMethod]
public void IntModLimbTruncateWithQuotient3()
{
using (var a = new HugeInt("234052834524092854092874502983745029345723098457209305983434345"))
{
ulong b = 5931690917503076532;
ulong d = 0;
a.Value = (a % b).SettingRemainderTo(x => d = x).Rounding(RoundingModes.Truncate);
Assert.AreEqual("5599417901817617409", a.ToString());
Assert.AreEqual(d.ToString(), a.ToString());
}
}
[TestMethod]
public void IntModLimbNegativeTruncateWithQuotient3()
{
using (var a = new HugeInt("-234052834524092854092874502983745029345723098457209305983434345"))
{
ulong b = 5931690917503076532;
ulong d = 0;
a.Value = (a % b).SettingRemainderTo(x => d = x).Rounding(RoundingModes.Truncate);
Assert.AreEqual("-5599417901817617409", a.ToString());
Assert.AreEqual("-" + d.ToString(), a.ToString());
}
}
#endregion
#region Mod Limb function
[TestMethod]
public void IntModLimbFunction()
{
using (var a = new HugeInt("234052834524092854092874502983745029345723098457209305983434345"))
{
ulong b = 5931690917503076532;
ulong d = a.Mod(b);
Assert.AreEqual("5599417901817617409", d.ToString());
}
}
[TestMethod]
public void IntModLimbFunctionCeiling()
{
using (var a = new HugeInt("234052834524092854092874502983745029345723098457209305983434345"))
{
ulong b = 5931690917503076532;
ulong d = a.Mod(b, RoundingModes.Ceiling);
Assert.AreEqual("332273015685459123", d.ToString());
}
}
[TestMethod]
public void IntModLimbFunctionNegativeCeiling()
{
using (var a = new HugeInt("-234052834524092854092874502983745029345723098457209305983434345"))
{
ulong b = 5931690917503076532;
ulong d = a.Mod(b, RoundingModes.Ceiling);
Assert.AreEqual("5599417901817617409", d.ToString());
}
}
[TestMethod]
public void IntModLimbFunctionFloor()
{
using (var a = new HugeInt("234052834524092854092874502983745029345723098457209305983434345"))
{
ulong b = 5931690917503076532;
ulong d = a.Mod(b, RoundingModes.Floor);
Assert.AreEqual("5599417901817617409", d.ToString());
}
}
[TestMethod]
public void IntModLimbFunctionNegativeFloor()
{
using (var a = new HugeInt("-234052834524092854092874502983745029345723098457209305983434345"))
{
ulong b = 5931690917503076532;
ulong d = a.Mod(b, RoundingModes.Floor);
Assert.AreEqual("332273015685459123", d.ToString());
}
}
[TestMethod]
public void IntModLimbFunctionTruncate()
{
using (var a = new HugeInt("234052834524092854092874502983745029345723098457209305983434345"))
{
ulong b = 5931690917503076532;
ulong d = a.Mod(b, RoundingModes.Truncate);
Assert.AreEqual("5599417901817617409", d.ToString());
}
}
[TestMethod]
public void IntModLimbFunctionNegativeTruncate()
{
using (var a = new HugeInt("-234052834524092854092874502983745029345723098457209305983434345"))
{
ulong b = 5931690917503076532;
ulong d = a.Mod(b, RoundingModes.Truncate);
Assert.AreEqual("5599417901817617409", d.ToString());
}
}
#endregion
#region Shift Right Remainder
[TestMethod]
public void IntShiftRightRemainder()
{
using (var a = new HugeInt("ABCDEF052834524092854092874502983745029345723098457209305983434345", 16))
{
ulong b = 96;
a.Value = (a >> b).Remainder();
Assert.AreEqual("723098457209305983434345", a.ToString(16));
}
}
[TestMethod]
public void IntShiftRightRemainderCeiling()
{
using (var a = new HugeInt("ABCDEF052834524092854092874502983745029345723098457209305983434345", 16))
{
ulong b = 96;
a.Value = (a >> b).Remainder().Rounding(RoundingModes.Ceiling);
Assert.AreEqual("-8DCF67BA8DF6CFA67CBCBCBB", a.ToString(16));
}
}
[TestMethod]
public void IntShiftRightRemainderNegativeCeiling()
{
using (var a = new HugeInt("-ABCDEF052834524092854092874502983745029345723098457209305983434345", 16))
{
ulong b = 96;
a.Value = (a >> b).Remainder().Rounding(RoundingModes.Ceiling);
Assert.AreEqual("-723098457209305983434345", a.ToString(16));
}
}
[TestMethod]
public void IntShiftRightRemainderFloor()
{
using (var a = new HugeInt("ABCDEF052834524092854092874502983745029345723098457209305983434345", 16))
{
ulong b = 96;
a.Value = (a >> b).Remainder().Rounding(RoundingModes.Floor);
Assert.AreEqual("723098457209305983434345", a.ToString(16));
}
}
[TestMethod]
public void IntShiftRightRemainderNegativeFloor()
{
using (var a = new HugeInt("-ABCDEF052834524092854092874502983745029345723098457209305983434345", 16))
{
ulong b = 96;
a.Value = (a >> b).Remainder().Rounding(RoundingModes.Floor);
Assert.AreEqual("8DCF67BA8DF6CFA67CBCBCBB", a.ToString(16));
}
}
[TestMethod]
public void IntShiftRightRemainderTruncate()
{
using (var a = new HugeInt("ABCDEF052834524092854092874502983745029345723098457209305983434345", 16))
{
ulong b = 96;
a.Value = (a >> b).Remainder().Rounding(RoundingModes.Truncate);
Assert.AreEqual("723098457209305983434345", a.ToString(16));
}
}
[TestMethod]
public void IntShiftRightRemainderNegativeTruncate()
{
using (var a = new HugeInt("-ABCDEF052834524092854092874502983745029345723098457209305983434345", 16))
{
ulong b = 96;
a.Value = (a >> b).Remainder().Rounding(RoundingModes.Truncate);
Assert.AreEqual("-723098457209305983434345", a.ToString(16));
}
}
#endregion
#endregion
}
}