예제 #1
0
 public void FloatMakeAbsolute()
 {
     using (var a = new HugeFloat("-9023409872309847509847.9385345098345"))
     {
         a.Value = a.Abs();
         FloatAssert.AreEqual("9023409872309847509847.9385345098345", a);
         a.Value = a.Abs();
         FloatAssert.AreEqual("9023409872309847509847.9385345098345", a);
     }
 }
예제 #2
0
        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)));
        }
예제 #3
0
        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)));
        }
예제 #4
0
 public void FloatMakeAbsolute()
 {
     using(var a = new HugeFloat("-9023409872309847509847.9385345098345"))
     {
         a.Value = a.Abs();
         FloatAssert.AreEqual("9023409872309847509847.9385345098345", a);
         a.Value = a.Abs();
         FloatAssert.AreEqual("9023409872309847509847.9385345098345", a);
     }
 }