本文整理汇总了C#中HugeFloat类的典型用法代码示例。如果您正苦于以下问题:C# HugeFloat类的具体用法?C# HugeFloat怎么用?C# HugeFloat使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
HugeFloat类属于命名空间,在下文中一共展示了HugeFloat类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: FloatCompareToNonExpression
public void FloatCompareToNonExpression()
{
using (var a = new HugeFloat("-222509832503450298345029835740293845721.57898962467957"))
{
a.CompareTo("abc");
}
}
开发者ID:BrianGladman,项目名称:mpir,代码行数:7,代码来源:Comparisons.cs
示例2: CompareToCalculatedToDefaultPrecision
public void CompareToCalculatedToDefaultPrecision()
{
using (var a = new HugeFloat(1))
using (var b = new HugeFloat(13))
using (var c = new HugeFloat("12345234589234059823475029384572323"))
using (var d = HugeFloat.Allocate(256))
{
ShiftLeftBy62(c);
d.Value = c;
var expr = a / b + c;
Assert.AreEqual(0, c.CompareTo(expr)); //to precision of c
Assert.AreEqual(0, expr.CompareTo(c)); //to precision of c
Assert.IsFalse(expr > c); //to precision of c
Assert.IsTrue(c == expr); //to precision of c
Assert.AreEqual(0, (c + 0).CompareTo(expr)); //to default precision
Assert.AreEqual(0, expr.CompareTo(c + 0)); //to default precision
Assert.IsFalse(expr > c + 0); //to default precision
Assert.IsTrue(c + 0 == expr); //to default precision
HugeFloat.DefaultPrecision = 256;
Assert.AreEqual(0, c.CompareTo(expr)); //to precision of c
Assert.AreEqual(0, expr.CompareTo(c)); //to precision of c
Assert.IsTrue(c == expr); //to precision of c
Assert.IsFalse(expr > c); //to precision of c
Assert.AreEqual(-1, d.CompareTo(expr)); //to precision of d
Assert.AreEqual(1, expr.CompareTo(d)); //to precision of d
Assert.IsFalse(d == expr); //to precision of d
Assert.IsTrue(expr > d); //to precision of d
Assert.AreEqual(-1, (c * 1).CompareTo(expr)); //to default precision
Assert.AreEqual(1, expr.CompareTo(c + 0)); //to default precision
Assert.IsFalse(c + 0 == expr); //to default precision
Assert.IsTrue(expr > c + 0); //to default precision
HugeFloat.DefaultPrecision = 128;
}
}
开发者ID:wbhart,项目名称:mpir,代码行数:34,代码来源:Precision.cs
示例3: FloatAssignDouble
public void FloatAssignDouble()
{
using(var a = new HugeFloat())
{
a.SetTo(22250983250345.125);
Assert.IsTrue(a == 22250983250345.125);
}
}
开发者ID:wbhart,项目名称:mpir,代码行数:8,代码来源:Assignment.cs
示例4: RationalAssignFloat
public void RationalAssignFloat()
{
using (var a = new HugeFloat("9363833093638312937.25"))
using (var b = new HugeRational())
{
b.SetTo(a);
Assert.AreEqual("37455332374553251749/4", b.ToString());
}
}
开发者ID:wbhart,项目名称:mpir,代码行数:9,代码来源:Assignment.cs
示例5: FloatAssignRational
public void FloatAssignRational()
{
using (var a = new HugeRational(1, 3))
using (var b = new HugeFloat())
{
b.SetTo(a);
FloatAssert.AreEqual(".33333333333333333333333333333333333333333333333333333333333333333333333333333333333", b);
}
}
开发者ID:wbhart,项目名称:mpir,代码行数:9,代码来源:Assignment.cs
示例6: FloatAssignInt
public void FloatAssignInt()
{
using (var a = new HugeInt("222509832503450298345029835740293845720"))
using (var b = new HugeFloat())
{
b.SetTo(a);
FloatAssert.AreEqual("222509832503450298345029835740293845720.", b);
}
}
开发者ID:wbhart,项目名称:mpir,代码行数:9,代码来源:Assignment.cs
示例7: RationalAssignFloat2
public void RationalAssignFloat2()
{
using(var a = new HugeFloat("222509832503450298342455029.125"))
using(var b = new HugeRational("1/3"))
{
b.SetTo(a);
Assert.AreEqual("1780078660027602386739640233/8", b.ToString());
}
}
开发者ID:wbhart,项目名称:mpir,代码行数:9,代码来源:Assignment.cs
示例8: FloatAssignCopy
public void FloatAssignCopy()
{
var s = "-1.22250983250345029834502983574029384572";
using (var a = new HugeFloat(s))
using (var b = new HugeFloat())
{
b.Value = a;
FloatAssert.AreEqual(s, b);
}
}
开发者ID:wbhart,项目名称:mpir,代码行数:10,代码来源:Assignment.cs
示例9: FloatCompareToHugeFloat
public void FloatCompareToHugeFloat()
{
using (var a = new HugeFloat("-22250983250345029834503.9835740293845721345345354"))
using (var b = new HugeFloat("22250983250345029834502.9835740293845721345345354"))
{
Assert.AreEqual(1, Math.Sign(b.CompareTo(a)));
Assert.AreEqual(-1,Math.Sign(a.CompareTo(b + 1)));
Assert.AreEqual(0, Math.Sign((a + 1).CompareTo(-b)));
Assert.AreEqual(1, Math.Sign(a.CompareTo(null)));
}
}
开发者ID:BrianGladman,项目名称:mpir,代码行数:11,代码来源:Comparisons.cs
示例10: FloatCompareToExpression
public void FloatCompareToExpression()
{
using (var a = new HugeFloat("-22250983250345029834503.9835740293845721345345354"))
using (var b = new HugeFloat("22250983250345029834502.9835740293845721345345354"))
{
Assert.AreEqual(1, Math.Sign(((IComparable<FloatExpression>)b).CompareTo(a)));
Assert.AreEqual(-1,Math.Sign(((IComparable<FloatExpression>)a).CompareTo(b)));
Assert.AreEqual(1, Math.Sign(((IComparable<FloatExpression>)a).CompareTo(null)));
Assert.AreEqual(0, Math.Sign(((IComparable<FloatExpression>)(a + 1)).CompareTo(-b)));
}
}
开发者ID:BrianGladman,项目名称:mpir,代码行数:11,代码来源:Comparisons.cs
示例11: FloatAddHugeFloat
public void FloatAddHugeFloat()
{
using (var a = new HugeFloat("22250983250345029834502983.5740293845720"))
using (var b = new HugeFloat("2229874359879827.30594288574029879874539"))
using (var c = new HugeFloat(a + b))
{
FloatAssert.AreEqual("22250983252574904194382810.87997227031229879874539", c);
c.Value = a + (b + 1);
FloatAssert.AreEqual("22250983252574904194382811.87997227031229879874539", c);
}
}
开发者ID:BrianGladman,项目名称:mpir,代码行数:11,代码来源:Arithmetic.cs
示例12: FloatTruncate
public void FloatTruncate()
{
using(var a = new HugeFloat("-9023409872309847509847.9385345098345"))
using(var b = new HugeFloat())
{
b.Value = a.Truncate();
FloatAssert.AreEqual("-9023409872309847509847", b);
b.Value = (-a).Truncate();
FloatAssert.AreEqual("9023409872309847509847", b);
}
}
开发者ID:wbhart,项目名称:mpir,代码行数:11,代码来源:Math.cs
示例13: FloatCompareToLimb
public void FloatCompareToLimb()
{
using (var a = new HugeFloat(Platform.Select("-22250982876541", "-222509821")))
{
var b = Platform.Ui(22250982876540, 222509820);
Assert.AreEqual(-1,Math.Sign(a.CompareTo(b)));
Assert.AreEqual(-1,Math.Sign(a.CompareTo(b + 1)));
Assert.AreEqual(0, Math.Sign((-(a + 1)).CompareTo(b)));
Assert.AreEqual(0, Math.Sign((-a).CompareTo(b + 1)));
Assert.AreEqual(1, Math.Sign((-a).CompareTo(b)));
}
}
开发者ID:BrianGladman,项目名称:mpir,代码行数:12,代码来源:Comparisons.cs
示例14: FloatAddSignedLimb
public void FloatAddSignedLimb()
{
using (var a = new HugeFloat("22250983250345029834502983.5740293845720"))
using (var c = new HugeFloat())
{
var b = Platform.Si(-4288574029879874539, -1288574029);
var expected = Platform.Select("22250978961770999954628444.5740293845720", "22250983250345028545928954.5740293845720");
c.Value = a + b;
FloatAssert.AreEqual(expected, c);
c.Value = b + a;
FloatAssert.AreEqual(expected, c);
}
}
开发者ID:BrianGladman,项目名称:mpir,代码行数:13,代码来源:Arithmetic.cs
示例15: FloatAddLimb
public void FloatAddLimb()
{
using (var a = new HugeFloat("22250983250345029834502983.5740293845720"))
using (var c = new HugeFloat())
{
var b = Platform.Ui(4288574029879874539UL, 4288574029U);
var expected = Platform.Select("22250987538919059714377522.5740293845720", "22250983250345034123077012.5740293845720");
c.Value = a + b;
FloatAssert.AreEqual(expected, c);
c.Value = b + a;
FloatAssert.AreEqual(expected, c);
}
}
开发者ID:BrianGladman,项目名称:mpir,代码行数:13,代码来源:Arithmetic.cs
示例16: FloatTestAllExpressions
public void FloatTestAllExpressions()
{
var baseExpr = typeof(FloatExpression);
var allExpressions =
baseExpr.Assembly.GetTypes()
.Where(x => baseExpr.IsAssignableFrom(x) && !x.IsAbstract)
.ToList();
var one = Platform.Ui(1UL, 1U);
using (var a = new HugeFloat(-9))
using (var b = new HugeFloat(4))
using (var c = new HugeInt(3))
using(var r = MpirRandom.Default())
{
var expr = a + (-a * 2) * 3 * (a.Abs() * -2 + -64 + a * a) + (one * 116U) + a;
VerifyPartialResult(r, expr, 44);
expr = expr + a * 5 + (a+b) * (b + 1) * (b + -3) * b + (b * -a) - (b * (one * 25U)) - a + (b << 3) - ((a*b) << 1);
VerifyPartialResult(r, expr, -52);
expr = expr - 2 - 3U + (b - (a << 1)) + (b * b - 15U) * (b - a) * (a - 11) * (b - (one * 3U)) - (-340 - a) + ((one * 20U) - b);
VerifyPartialResult(r, expr, 52);
expr = expr + (-7 - 2 * a) + (28U - 4 * b) + -(a + b * 2) + (3 * a).Abs();
VerifyPartialResult(r, expr, 103);
expr = 36 * (expr / a + expr / (3 * b) - a / b) - b / (a + 10) + 6;
VerifyPartialResult(r, expr, -20);
expr = expr + (b >> 1) + ((b / -7) + (a / (one * 7U))) * 7 + (7 / a) - ((one * 2U) / (b + 5));
VerifyPartialResult(r, expr, -32);
expr = expr - (b + 13 + 64) / a / -3;
VerifyPartialResult(r, expr, -35);
expr = expr + b.SquareRoot() + HugeFloat.SquareRoot(25) + ((b - 2) ^ 3) - (-b).RelativeDifferenceFrom(a + 1);
VerifyPartialResult(r, expr, -19);
expr = expr - (a / 4).Floor() + (b / 3).Ceiling() - (a / b).Truncate();
VerifyPartialResult(r, expr, -12);
expr = expr + (r.GetFloatBits(64) * 10).Ceiling();
VerifyPartialResult(r, expr, -10);
//float random generation seems to give different results in Win32 and Win64. Thus, we're having to adjust the results for Win32.
expr = expr + (r.GetFloatLimbsChunky(128 / MpirSettings.BITS_PER_LIMB, 256 / MpirSettings.BITS_PER_LIMB) << 233 >> Platform.Ui(0, 480)).Ceiling();
VerifyPartialResult(r, expr, -6);
expr = expr + (r.GetFloat() * 10).Floor() - Platform.Ui(0, 3);
VerifyPartialResult(r, expr, -2);
expr = expr + (r.GetFloatChunky(3) << 101 >> Platform.Ui(177, 23)).Truncate();
VerifyPartialResult(r, expr, 13);
MarkExpressionsUsed(allExpressions, expr);
}
Assert.AreEqual(0, allExpressions.Count, "Expression types not exercised: " + string.Join("",
allExpressions.Select(x => Environment.NewLine + x.Name).OrderBy(x => x)));
}
开发者ID:BrianGladman,项目名称:mpir,代码行数:49,代码来源:ExpressionTests.cs
示例17: FloatInputOutputStr62
public void FloatInputOutputStr62()
{
using(var a = new HugeFloat("10123456789ABCDEF012345.6789ABCDE", 16))
using(var b = HugeFloat.Allocate(12800))
using(var ms = new MemoryStream())
{
a.Reallocate(12800);
a.Value = a ^ 100;
using(var writer = new StreamWriter(ms, Encoding.UTF8, 1024, true))
a.Write(writer, 62, 0, false, false);
ms.Position = 0;
using(var reader = new StreamReader(ms, Encoding.UTF8, false, 1024, true))
b.Read(reader, 62, false);
Assert.AreEqual(a.ToString(62), b.ToString(62));
Assert.AreEqual(ms.Length, ms.Position);
Assert.AreEqual((char)0xFEFF + a.ToString(62), Encoding.UTF8.GetString(ms.ToArray()));
}
}
开发者ID:wbhart,项目名称:mpir,代码行数:21,代码来源:IO.cs
示例18: FloatSubtractSignedLimb
public void FloatSubtractSignedLimb()
{
using(var a = new HugeFloat("22250983250345029834502983.5740293845720"))
using(var c = new HugeFloat())
{
var b = Platform.Si(-4288574029879874539, -1885740298);
var expected = Platform.Select("22250987538919059714377522.5740293845720", "22250983250345031720243281.5740293845720");
c.Value = a - b;
FloatAssert.AreEqual(expected, c);
c.Value = b - a;
FloatAssert.AreEqual("-" + expected, c);
}
}
开发者ID:BrianGladman,项目名称:mpir,代码行数:13,代码来源:Arithmetic.cs
示例19: AreEqual
public static void AreEqual(string expected, HugeFloat actual)
{
var actualStr = actual.ToString();
if(expected[0] == '-')
{
Assert.AreEqual(expected[0], actualStr[0]);
actualStr = actualStr.TrimStart('-');
expected = expected.TrimStart('-');
}
var exponent = expected.IndexOf('.');
if(exponent < 0) exponent = expected.Length;
expected = expected.Replace(".", "");
var exponentStr = "@" + exponent;
Assert.IsTrue(actualStr.StartsWith("0."));
actualStr = actualStr.Substring(2);
Assert.IsTrue(actualStr.EndsWith(exponentStr));
actualStr = actualStr.Substring(0, actualStr.Length - exponentStr.Length);
if (expected.Length > actualStr.Length)
{
var roundedUp = expected[actualStr.Length] >= '5';
expected = expected.Substring(0, actualStr.Length);
if(roundedUp)
{
using (var a = new HugeInt(expected))
{
a.Value += 1;
expected = a.ToString(10);
}
}
}
Assert.AreEqual(expected, actualStr);
}
开发者ID:BrianGladman,项目名称:mpir,代码行数:37,代码来源:Arithmetic.cs
示例20: FloatSubtractHugeFloat
public void FloatSubtractHugeFloat()
{
using (var a = new HugeFloat("22250983250345029834502983.5740293845720"))
using (var b = new HugeFloat("2229874359879827.30594288574029879874539"))
using (var c = new HugeFloat(a - b))
{
FloatAssert.AreEqual("22250983248115155474623156.26808649883170120125461", c);
c.Value = b - (a + 1);
FloatAssert.AreEqual("-22250983248115155474623157.26808649883170120125461", c);
}
}
开发者ID:BrianGladman,项目名称:mpir,代码行数:11,代码来源:Arithmetic.cs
注:本文中的HugeFloat类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论