本文整理汇总了C#中HugeInt类的典型用法代码示例。如果您正苦于以下问题:C# HugeInt类的具体用法?C# HugeInt怎么用?C# HugeInt使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
HugeInt类属于命名空间,在下文中一共展示了HugeInt类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: IntFindBit
public void IntFindBit()
{
using (var a = new HugeInt("0xA0000000000000000000800000000001"))
{
var max = Platform.Ui(ulong.MaxValue, uint.MaxValue);
Assert.AreEqual(0UL, a.FindBit(true, 0));
Assert.AreEqual(47UL, a.FindBit(true, 1));
Assert.AreEqual(47UL, a.FindBit(true, 47));
Assert.AreEqual(125UL, a.FindBit(true, 48));
Assert.AreEqual(127UL, a.FindBit(true, 126));
Assert.AreEqual(max, a.FindBit(true, 128));
Assert.AreEqual(1UL, a.FindBit(false, 0));
Assert.AreEqual(1UL, a.FindBit(false, 1));
Assert.AreEqual(9UL, a.FindBit(false, 9));
Assert.AreEqual(128UL, a.FindBit(false, 127));
Assert.AreEqual(227UL, a.FindBit(false, 227));
a.Value = ~a;
Assert.AreEqual(0UL, a.FindBit(false, 0));
Assert.AreEqual(47UL, a.FindBit(false, 1));
Assert.AreEqual(47UL, a.FindBit(false, 47));
Assert.AreEqual(125UL, a.FindBit(false, 48));
Assert.AreEqual(127UL, a.FindBit(false, 126));
Assert.AreEqual(max, a.FindBit(false, 128));
Assert.AreEqual(1UL, a.FindBit(true, 0));
Assert.AreEqual(1UL, a.FindBit(true, 1));
Assert.AreEqual(9UL, a.FindBit(true, 9));
Assert.AreEqual(128UL, a.FindBit(true, 127));
Assert.AreEqual(227UL, a.FindBit(true, 227));
}
}
示例2: RationalCompareToHugeInt
public void RationalCompareToHugeInt()
{
using (var a = new HugeRational("-222509832503450298345029835740293845721/115756986668303657898962467957"))
using (var b = new HugeInt("115756986668303657898962467957"))
using (var c = new HugeRational("115756986668303657898962467957/1"))
using (var d = new HugeInt(1922215141))
{
Assert.AreEqual(-1, System.Math.Sign(a.CompareTo(d)));
Assert.AreEqual(1, System.Math.Sign((-a).CompareTo(d)));
Assert.AreEqual(-1, System.Math.Sign((-a).CompareTo(d + 1)));
Assert.AreEqual(1, System.Math.Sign(d.CompareTo(a)));
Assert.AreEqual(-1, System.Math.Sign(d.CompareTo(-a)));
Assert.AreEqual(1, System.Math.Sign((d + 1).CompareTo(-a)));
Assert.AreEqual(0, System.Math.Sign(b.CompareTo(c)));
Assert.AreEqual(0, System.Math.Sign(c.CompareTo(b)));
Assert.AreEqual(0, System.Math.Sign((-b).CompareTo(-c)));
Assert.AreEqual(0, System.Math.Sign((-c).CompareTo(-b)));
Assert.AreEqual(1, System.Math.Sign(b.CompareTo(c - 1)));
Assert.AreEqual(1, System.Math.Sign(c.CompareTo(b - 1)));
Assert.AreEqual(-1, System.Math.Sign((-b).CompareTo(1 - c)));
Assert.AreEqual(-1, System.Math.Sign((-c).CompareTo(1 - b)));
}
}
示例3: CanAddHugeInt
public void CanAddHugeInt()
{
HugeInt a = new HugeInt(123);
HugeInt b = new HugeInt(456);
HugeInt c = a + b;
Assert.AreEqual("579", c.ToString());
}
示例4: CanSubtractHugeInt
public void CanSubtractHugeInt()
{
HugeInt a = new HugeInt(456);
HugeInt b = new HugeInt(123);
HugeInt c = a - b;
Assert.AreEqual("333", c.ToString());
}
示例5: IntPowerLimb
public void IntPowerLimb()
{
using (var a = new HugeInt("9785412309485720938412983404349"))
{
a.Value = a ^ 4;
Assert.AreEqual("9168884832199547717402442404668238841010784738902226284286664833331445628675177089723224507720724521226586825967635414667601", a.ToString());
}
}
示例6: IntGetLimb
public void IntGetLimb()
{
using (var a = new HugeInt("-0x10123456789ABCDEFA123456789ABCDEF0123456789ABCDEF"))
{
Assert.AreEqual(Platform.Ui(0x0123456789ABCDEFUL, 0x89ABCDEFU), a.GetLimb(0));
Assert.AreEqual(Platform.Ui(0xA123456789ABCDEFUL, 0x01234567U), a.GetLimb(1));
}
}
示例7: FloatAssignInt
public void FloatAssignInt()
{
using (var a = new HugeInt("222509832503450298345029835740293845720"))
using (var b = new HugeFloat())
{
b.SetTo(a);
FloatAssert.AreEqual("222509832503450298345029835740293845720.", b);
}
}
示例8: RationalAssignInt
public void RationalAssignInt()
{
using (var a = new HugeInt("222509832503450298345029835740293845720"))
using (var b = new HugeRational("1/3"))
{
b.SetTo(a);
Assert.AreEqual("222509832503450298345029835740293845720/1", b.ToString());
}
}
示例9: IntCompoundOperators
public void IntCompoundOperators()
{
using (var a = new HugeInt("938475092834705928347523452345"))
{
a.Value += 1;
a.Value *= 10;
Assert.AreEqual("9384750928347059283475234523460", a.ToString());
}
}
示例10: IntAssignRational
public void IntAssignRational()
{
using (var a = new HugeRational("222509832503450298345029835740293845720/7"))
using (var b = new HugeInt())
{
b.SetTo(a);
Assert.AreEqual("31787118929064328335004262248613406531", b.ToString());
}
}
示例11: IntAssignCopy
public void IntAssignCopy()
{
using (var a = new HugeInt("-222509832503450298345029835740293845720"))
using (var b = new HugeInt())
{
b.Value = a;
Assert.AreEqual("-222509832503450298345029835740293845720", b.ToString());
}
}
示例12: IntAddLimb
public void IntAddLimb()
{
using (var a = new HugeInt("222509832503450298345029835740293845720"))
{
var b = Platform.Ui(4288574029879874539UL, 4288574029U);
a.Value = a + b;
Assert.AreEqual(Platform.Select("222509832503450298349318409770173720259", "222509832503450298345029835744582419749"), a.ToString());
}
}
示例13: IntAndHugeInt
public void IntAndHugeInt()
{
using (var a = new HugeInt("0x10123456789ABCDEF0123456789ABCDEF0123456789ABCDEF"))
using (var b = new HugeInt("0x100000000000000000123456789ABCDEFFFFFFFFFFFFFFFFF"))
using (var c = new HugeInt())
{
c.Value = a & b;
Assert.AreEqual("100000000000000000123456789ABCDEF0123456789ABCDEF", c.ToString(16));
}
}
示例14: IntBinomial
public void IntBinomial()
{
using (var a = new HugeInt(HugeInt.Binomial(40, 15)))
using (var b = new HugeInt("41"))
using (var c = new HugeInt(HugeInt.Binomial(b, 15)))
{
Assert.AreEqual(HugeInt.Factorial(40).DivideExactly(HugeInt.Factorial(15) * HugeInt.Factorial(25)), a);
Assert.AreEqual(a * 41 / 26, c);
}
}
示例15: IntAddHugeInt
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());
}
}