本文整理汇总了C#中HugeInt.SetTo方法的典型用法代码示例。如果您正苦于以下问题:C# HugeInt.SetTo方法的具体用法?C# HugeInt.SetTo怎么用?C# HugeInt.SetTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HugeInt
的用法示例。
在下文中一共展示了HugeInt.SetTo方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: IntAssignRational
public void IntAssignRational()
{
using (var a = new HugeRational("222509832503450298345029835740293845720/7"))
using (var b = new HugeInt())
{
b.SetTo(a);
Assert.AreEqual("31787118929064328335004262248613406531", b.ToString());
}
}
示例2: IntFitsShort
public void IntFitsShort()
{
using (var a = new HugeInt(short.MaxValue))
{
Assert.IsTrue(a.FitsShort());
a.Value = a + 1;
Assert.IsFalse(a.FitsShort());
a.SetTo(short.MinValue);
Assert.IsTrue(a.FitsShort());
a.Value = a - 1;
Assert.IsFalse(a.FitsShort());
}
}
示例3: IntImportExport
public void IntImportExport()
{
using (var a = new HugeInt("0x10123456789ABCDEF0123456789ABCDEF0123456789ABCDEF"))
using (var b = new HugeInt())
{
var bytes = new byte[1000];
foreach (var order in Enum.GetValues(typeof(LimbOrder)).Cast<LimbOrder>())
foreach (var endianness in Enum.GetValues(typeof(Endianness)).Cast<Endianness>())
foreach (var nails in new[] { 0, 5, 10, 16 })
foreach (var size in new[] { 8, 11, 16 })
{
var words = a.Export(bytes, size, order, endianness, nails);
var expected = (ulong)System.Math.Ceiling(193m / (size * 8 - nails));
Assert.AreEqual(expected, words);
b.SetTo(0);
b.Import(bytes, words, size, order, endianness, nails);
Assert.AreEqual(a, b);
}
}
}
示例4: IntImportExportAllocating
public void IntImportExportAllocating()
{
using (var a = new HugeInt("0x10123456789ABCDEF0123456789ABCDEF0123456789ABCDEF"))
using (var b = new HugeInt())
{
foreach (var order in Enum.GetValues(typeof(LimbOrder)).Cast<LimbOrder>())
foreach (var endianness in Enum.GetValues(typeof(Endianness)).Cast<Endianness>())
foreach (var nails in new[] { 0, 5, 10, 16 })
foreach (var size in new[] { 8, 11, 16 })
{
var bytes = a.Export<byte>(size, order, endianness, nails);
var expected = (int)System.Math.Ceiling(193m / (size * 8 - nails));
Assert.AreEqual(expected, bytes.Length / size);
b.SetTo(0);
b.Import(bytes, (uint)(bytes.Length / size), size, order, endianness, nails);
Assert.AreEqual(a, b);
}
}
}
示例5: IntImportExportAllocatingZero
public void IntImportExportAllocatingZero()
{
using (var a = new HugeInt())
using (var b = new HugeInt())
{
var order = LimbOrder.LeastSignificantFirst;
var endianness = Endianness.Native;
var nails = 5;
var size = 4;
var bytes = a.Export<byte>(size, order, endianness, nails);
Assert.AreEqual(0, bytes.Length);
b.SetTo(1);
b.Import(bytes, 0, size, order, endianness, nails);
Assert.AreEqual(a, b);
}
}
示例6: IntSquareRoot
public void IntSquareRoot()
{
var n = "8984948281360922385394772450147012613851354303";
using (var a = new HugeInt(n))
using (var b = new HugeInt())
using (var c = new HugeInt())
{
a.Value = a * a;
b.Value = a.SquareRoot();
Assert.AreEqual(n, b.ToString());
b.SetTo(0);
b.Value = (a + 123).SquareRoot().SavingRemainderTo(c);
Assert.AreEqual(n, b.ToString());
Assert.AreEqual("123", c.ToString());
}
}
示例7: HugeIntSetToPerformedToDefaultPrecision
public void HugeIntSetToPerformedToDefaultPrecision()
{
using (var a = new HugeFloat(14))
using (var b = new HugeFloat(13))
using (var c = new HugeFloat("1234523458923405982347445029384572323"))
using (var d = new HugeInt())
{
ShiftLeftBy62(c);
ShiftLeftBy62(c);
var expr = a / b + c - c;
d.SetTo(expr);
Assert.IsTrue(d == 0);
HugeFloat.DefaultPrecision = 256;
d.SetTo(expr);
Assert.IsTrue(d == 1);
HugeFloat.DefaultPrecision = 128;
}
}
示例8: IntFitsUint
public void IntFitsUint()
{
using (var a = new HugeInt(uint.MaxValue))
{
Assert.IsTrue(a.FitsUint());
a.Value = a + 1;
Assert.IsFalse(a.FitsUint());
a.SetTo(0);
Assert.IsTrue(a.FitsUint());
a.Value = a - 1;
Assert.IsFalse(a.FitsUint());
}
}
示例9: IntToAndFromUint
public void IntToAndFromUint()
{
using (var a = new HugeInt())
{
uint b = 0xF84739AB;
a.SetTo(b);
Assert.AreEqual(b.ToString(), a.ToString());
a.Value = -a;
uint c = a.ToUint();
Assert.AreEqual(b.ToString(), c.ToString());
}
}
示例10: IntToAndFromInt
public void IntToAndFromInt()
{
using (var a = new HugeInt())
{
int b = -0x784739AB;
a.SetTo(b);
Assert.AreEqual(b.ToString(), a.ToString());
long c = a.ToInt();
Assert.AreEqual(b.ToString(), c.ToString());
}
}
示例11: IntToAndFromUlong
public void IntToAndFromUlong()
{
using (var a = new HugeInt())
{
ulong b = 0xF84739ABCDEF4876;
a.SetTo(b);
Assert.AreEqual(b.ToString(), a.ToString());
a.Value = -a;
ulong c = a.ToUlong();
Assert.AreEqual(b.ToString(), c.ToString());
}
}
示例12: IntToAndFromLong
public void IntToAndFromLong()
{
using (var a = new HugeInt())
{
long b = -0x784739ABCDEF4876;
a.SetTo(b);
Assert.AreEqual(b.ToString(), a.ToString());
long c = a.ToLong();
Assert.AreEqual(b.ToString(), c.ToString());
}
}
示例13: IntToAndFromDouble
public void IntToAndFromDouble()
{
using (var a = new HugeInt())
using (var lo = new HugeInt())
using (var hi = new HugeInt())
{
var source = Platform.Select(-123.45e20, -123.45e19);
var zillion = Platform.Ui(10000000000U, 1000000000U);
var factor = Platform.Ui(1, 10);
var exp = Platform.Si(0, 0);
a.SetTo(source);
lo.Value = (a/zillion).Rounding(RoundingModes.Floor);
hi.Value = (a/zillion).Rounding(RoundingModes.Ceiling);
Assert.IsTrue(lo.ToString() == "-1234500000000" || hi.ToString() == "-1234500000000");
double c = a.ToDouble();
Assert.AreEqual(source, c);
a.Value = (a + a) * factor;
c = a.ToDouble(out exp);
Assert.AreEqual(75, exp);
c *= System.Math.Pow(2, exp);
Assert.IsTrue(a + zillion >= c);
Assert.IsTrue(a - zillion <= c);
}
}
示例14: IntFromString
public void IntFromString()
{
using (var a = new HugeInt())
{
var n = "98762934876529834765234123984761";
a.SetTo(n);
Assert.AreEqual(n, a.ToString());
n = "-98ABCDEF876529834765234123984761";
a.SetTo(n, 16);
Assert.AreEqual(n, a.ToString(16));
}
}
示例15: IntFromInvalidString
public void IntFromInvalidString()
{
using (var a = new HugeInt())
{
a.SetTo("12345A");
}
}