Exemplo n.º 1
0
 public void RationalCanonicalize()
 {
     using (var a = new HugeRational(198, 15))
     {
         a.Denominator.Value = -a.Denominator;
         Assert.AreEqual("198/-15", a.ToString());
         a.Canonicalize();
         Assert.AreEqual("-66/5", a.ToString());
     }
 }
 public void RationalCanonicalize()
 {
     using (var a = new HugeRational(198, 15))
     {
         a.Denominator.Value = -a.Denominator;
         Assert.AreEqual("198/-15", a.ToString());
         a.Canonicalize();
         Assert.AreEqual("-66/5", a.ToString());
     }
 }
Exemplo n.º 3
0
        public void RationalToStringHex()
        {
            var n = "-23429abcdef298357462983fedcba345623984756";
            var d = "17607ef654eb9a13ffa163c75";
            var s = n + "/" + d;

            using (var a = new HugeRational(s, 16))
            {
                Assert.AreEqual(s, a.ToString(16, true));
                Assert.AreEqual(s.ToUpper(), a.ToString(16));
            }
        }
Exemplo n.º 4
0
        public void RationalFromLong()
        {
            using (var a = new HugeRational())
            {
                var b = Platform.Si(-0x784739ABCDEF4876, -0xF84776);
                var d = Platform.Ui(12764787846358441471, 3628273133);
                a.SetTo(b, d);
                Assert.AreEqual(b.ToString() + "/" + d.ToString(), a.ToString());

                a.SetTo(b);
                Assert.AreEqual(b.ToString() + "/1", a.ToString());
            }
        }
Exemplo n.º 5
0
        public void RationalFromLong()
        {
            using (var a = new HugeRational())
            {
                var b = Platform.Si(-0x784739ABCDEF4876, -0xF84776);
                var d = Platform.Ui(12764787846358441471, 3628273133);
                a.SetTo(b, d);
                Assert.AreEqual(b.ToString() + "/" + d.ToString(), a.ToString());

                a.SetTo(b);
                Assert.AreEqual(b.ToString() + "/1", a.ToString());
            }
        }
 public void RationalConstructorFromDoubleNegative()
 {
     using (var a = new HugeRational(-123456789123456.75))
     {
         Assert.AreEqual("-493827156493827/4", a.ToString());
     }
 }
Exemplo n.º 7
0
 public void RationalConstructorFromDoubleNegative()
 {
     using (var a = new HugeRational(-123456789123456.75))
     {
         Assert.AreEqual("-493827156493827/4", a.ToString());
     }
 }
 public void RationalStringAssignmentHexPrefix()
 {
     using (var i = new HugeInt("362736035870515331128527330659"))
     {
         var d = i.ToString(16);
         var n = "143210ABCDEF32123457ACDB324598799";
         using (var a = new HugeRational("0x" + n + "/0x" + d))
         {
             Assert.AreEqual(n + "/" + d, a.ToString(16));
             Assert.AreEqual(n + "/" + d, a.ToString(16, false));
             Assert.AreEqual((n + "/" + d).ToLower(), a.ToString(16, true));
             a.SetTo("-0x" + n + "/0x17");
             Assert.AreEqual("-" + n + "/17", a.ToString(16));
         }
     }
 }
Exemplo n.º 9
0
        public void RationalSwap()
        {
            var strA = "-222509832503450298345029835740293845720/115756986668303657898962467957";
            var strB = "2039847290878794872059384789347534534/590872612825179551336102196593";

            using (var a = new HugeRational(strA))
                using (var b = new HugeRational(strB))
                {
                    var aValue = a._value();
                    var bValue = b._value();

                    var an = a.Numerator;
                    var ad = a.Denominator;
                    var bn = b.Numerator;
                    var bd = b.Denominator;

                    a.Swap(b);
                    Assert.AreEqual(aValue, a._value());
                    Assert.AreEqual(bValue, b._value());
                    Assert.AreEqual(strB, a.ToString());
                    Assert.AreEqual(strA, b.ToString());
                    Assert.AreEqual(strB, string.Format("{0}/{1}", an, ad));
                    Assert.AreEqual(strA, string.Format("{0}/{1}", bn, bd));
                }
        }
Exemplo n.º 10
0
 public void RationalConstructorFromIntExpression()
 {
     using (var a = new HugeInt("2340958273409578234095823045723490587"))
         using (var b = new HugeRational(a + 1))
         {
             Assert.AreEqual("2340958273409578234095823045723490588/1", b.ToString());
         }
 }
Exemplo n.º 11
0
        public void RationalFromString()
        {
            using (var a = new HugeRational())
            {
                var n = "98762934876529834765234123984761/115756986668303657898962467957";
                a.SetTo(n);
                Assert.AreEqual(n, a.ToString());

                n = "-98ABCDEF876529834765234123984761/17607EF654EB9A13FFA163C75";
                a.SetTo(n, 16);
                Assert.AreEqual(n, a.ToString(16));

                n = "-98ABCDEF876529834765234123984761";
                a.SetTo(n, 16);
                Assert.AreEqual(n + "/1", a.ToString(16));
            }
        }
Exemplo n.º 12
0
 public void RationalConstructorFromFloatExpression()
 {
     using (var a = new HugeFloat("2340958273409578234.25"))
         using (var b = new HugeRational(a + 1))
         {
             Assert.AreEqual("9363833093638312941/4", b.ToString());
         }
 }
Exemplo n.º 13
0
 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());
     }
 }
Exemplo n.º 14
0
 public void RationalAssignFloat()
 {
     using (var a = new HugeFloat("9363833093638312937.25"))
     using (var b = new HugeRational())
     {
         b.SetTo(a);
         Assert.AreEqual("37455332374553251749/4", b.ToString());
     }
 }
Exemplo n.º 15
0
 public void RationalAssignCopy()
 {
     using (var a = new HugeRational("-222509832503450298345029835740293845720/115756986668303657898962467957"))
     using (var b = new HugeRational())
     {
         b.Value = a;
         Assert.AreEqual("-222509832503450298345029835740293845720/115756986668303657898962467957", b.ToString());
     }
 }
Exemplo n.º 16
0
 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());
         }
 }
Exemplo n.º 17
0
 public void RationalAssignFloat()
 {
     using (var a = new HugeFloat("9363833093638312937.25"))
         using (var b = new HugeRational())
         {
             b.SetTo(a);
             Assert.AreEqual("37455332374553251749/4", b.ToString());
         }
 }
Exemplo n.º 18
0
 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());
     }
 }
Exemplo n.º 19
0
 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());
         }
 }
Exemplo n.º 20
0
        private void VerifyPartialResult(MpirRandom rnd, RationalExpression expr, long expected)
        {
            rnd.Seed(123);

            using (var r = new HugeRational())
            {
                r.Value = expr;
                Assert.AreEqual(expected.ToString() + "/1", r.ToString());
            }
        }
Exemplo n.º 21
0
        public void RationalStringConstructorNumeratorOnly()
        {
            var n = "5432109876543212345789023245987";

            using (var a = new HugeRational(n))
            {
                Assert.AreEqual(128 / MpirSettings.BITS_PER_LIMB, a.NumeratorNumberOfLimbsUsed());
                Assert.AreEqual(n + "/1", a.ToString());
            }
        }
Exemplo n.º 22
0
        public void RationalStringConstructor()
        {
            var n = "5432109876543212345789023245987/362736035870515331128527330659";

            using (var a = new HugeRational(n))
            {
                Assert.AreEqual(128 / MpirSettings.BITS_PER_LIMB, a.NumeratorNumberOfLimbsUsed());
                Assert.AreEqual(n, a.ToString());
            }
        }
Exemplo n.º 23
0
        public void RationalToStringDecimal()
        {
            var n = "-23429384756298357462983476598345623984756";
            var d = "115756986668303657898962467957";
            var s = n + "/" + d;

            using (var a = new HugeRational(s))
            {
                Assert.AreEqual(s, a.ToString());
            }
        }
Exemplo n.º 24
0
 public void RationalDivideLimbBy()
 {
     using (var a = new HugeRational("115756986668303657898962467957/39458029384750298767200622330399462537522498"))
     {
         var b = Platform.Ui(5931690917503076532, 3367900313);
         a.Value = b / a;
         Assert.AreEqual(Platform.Select(
                             "234052834524092854092874502983745029345723092857791404165816936/115756986668303657898962467957",
                             "132890709515263728644898490080347139295153795258741874/115756986668303657898962467957"),
                         a.ToString());
     }
 }
Exemplo n.º 25
0
 public void RationalDivideSignedLimbBy()
 {
     using (var a = new HugeRational("115756986668303657898962467957/39458029384750298767200622330399462537522498"))
     {
         var b = Platform.Si(-5931690917503076532, -1500450271);
         a.Value = b / a;
         Assert.AreEqual(Platform.Select(
                             "-234052834524092854092874502983745029345723092857791404165816936/115756986668303657898962467957",
                             "-59204810883474549052577139687016525102679979792696958/115756986668303657898962467957"),
                         a.ToString());
     }
 }
Exemplo n.º 26
0
 public void RationalMultiplyLimbBy()
 {
     using (var a = new HugeRational("90234098723098475098479385345098345/115756986668303657898962467957"))
     {
         var b = Platform.Ui(17390538260286101342, 1500450271);
         a.Value = b * a;
         Assert.AreEqual(Platform.Select(
                             "1569219546226477273686601978789044606491747469626478990/115756986668303657898962467957",
                             "135391777882513860921200145428966240276901495/115756986668303657898962467957"),
                         a.ToString());
     }
 }
Exemplo n.º 27
0
 public void RationalMultiplySignedLimbBy()
 {
     using (var a = new HugeRational("90234098723098475098479385345098345/115756986668303657898962467957"))
     {
         var b = Platform.Si(-7390538260286101342, -1987450271);
         a.Value = b * a;
         Assert.AreEqual(Platform.Select(
                             "-666878558995492522701808125338061156491747469626478990/115756986668303657898962467957",
                             "-179335783960662818294159606092029134291901495/115756986668303657898962467957"),
                         a.ToString());
     }
 }
Exemplo n.º 28
0
 public void RationalStringConstructorHexPrefix()
 {
     using (var i = new HugeInt("362736035870515331128527330659"))
     {
         var d = i.ToString(16);
         var n = "143210ABCDEF32123457ACDB324598799";
         using (var a = new HugeRational("0x" + n + "/0x" + d))
         {
             Assert.AreEqual(n + "/" + d, a.ToString(16));
             Assert.AreEqual(i, a.Denominator);
         }
     }
 }
Exemplo n.º 29
0
        public void RationalConstructorFromLongNegative()
        {
            var n = Platform.Si(-123456789123456, -1234567891);
            var d = Platform.Ui(12764787846358441471U, 2860486313U);

            using (var a = new HugeRational(n, d))
            {
                Assert.AreEqual(1, a.NumeratorNumberOfLimbsAllocated());
                Assert.AreEqual(-1, a.NumeratorNumberOfLimbsUsed());
                Assert.AreEqual(1, a.DenominatorNumberOfLimbsAllocated());
                Assert.AreEqual(1, a.DenominatorNumberOfLimbsUsed());
                Assert.AreEqual(n + "/" + d, a.ToString());
            }
        }
Exemplo n.º 30
0
        public void RationalConstructorFromULong()
        {
            var n = Platform.Ui(ulong.MaxValue, uint.MaxValue);
            var d = Platform.Ui(12764787846358441471U, 2860486313U);

            using (var a = new HugeRational(n, d))
            {
                Assert.AreEqual(1, a.NumeratorNumberOfLimbsAllocated());
                Assert.AreEqual(1, a.NumeratorNumberOfLimbsUsed());
                Assert.AreEqual(1, a.DenominatorNumberOfLimbsAllocated());
                Assert.AreEqual(1, a.DenominatorNumberOfLimbsUsed());
                Assert.AreEqual(n.ToString(), a.Numerator.ToString());
                Assert.AreEqual(n.ToString() + "/" + d, a.ToString());
            }
        }
Exemplo n.º 31
0
 public void RationalToStringTruncated()
 {
     using (var d = new HugeInt("115756986668303657898962467957"))
         using (var e = new HugeInt(d ^ 10))
         {
             var s = e.ToString(10);
             var n = string.Concat("123456789".Select(c => new string(c, 30)));
             using (var a = new HugeRational(n + "/" + s))
             {
                 Assert.AreEqual(n + "/" + s, a.ToString(10));
                 Assert.AreEqual("..." + n.Substring(n.Length - 256) + "/..." + s.Substring(s.Length - 256), a.ToString());
                 a.Value = -a;
                 Assert.AreEqual("-..." + n.Substring(n.Length - 256) + "/..." + s.Substring(s.Length - 256), a.ToString());
             }
         }
 }
Exemplo n.º 32
0
        public void RationalInputOutputStrHex()
        {
            using (var a = new HugeRational("0x10123456789ABCDEF0123456789ABCDEF0123456789ABCDEF/361720912810755408215708460645842859722715865206816237944587"))
                using (var b = new HugeRational())
                    using (var ms = new MemoryStream())
                    {
                        a.Value = a ^ 100;
                        using (var writer = new StreamWriter(ms, Encoding.UTF8, 1024, true))
                            a.Write(writer, 16);

                        ms.Position = 0;

                        using (var reader = new StreamReader(ms, Encoding.UTF8, false, 1024, true))
                            b.Read(reader, 16);

                        Assert.AreEqual(a, b);
                        Assert.AreEqual(ms.Length, ms.Position);
                        Assert.AreEqual((char)0xFEFF + a.ToString(16), Encoding.UTF8.GetString(ms.ToArray()));
                    }
        }
Exemplo n.º 33
0
 public void RationalCompoundOperators()
 {
     using (var a = new HugeRational("938475092834705928347523452345/115756986668303657898962467957"))
     {
         a.Value += 1;
         a.Value *= 10;
         Assert.AreEqual("10542320795030095862464859203020/115756986668303657898962467957", a.ToString());
     }
 }
Exemplo n.º 34
0
 public void RationalDivideHugeRational()
 {
     using (var a = new HugeRational("115756986668303657898962467957/394580293847502987609283945873594873409587"))
         using (var b = new HugeRational("593169091750307653294"))
         {
             a.Value = a / b;
             Assert.AreEqual("115756986668303657898962467957/234052834524092854092760134269509268758750275703033222451729578", a.ToString());
         }
 }
Exemplo n.º 35
0
 public void RationalConstructorFromFloatExpression()
 {
     using (var a = new HugeFloat("2340958273409578234.25"))
     using (var b = new HugeRational(a + 1))
     {
         Assert.AreEqual("9363833093638312941/4", b.ToString());
     }
 }
Exemplo n.º 36
0
 public void RationalStringAssignmentHexPrefix()
 {
     using (var i = new HugeInt("362736035870515331128527330659"))
     {
         var d = i.ToString(16);
         var n = "143210ABCDEF32123457ACDB324598799";
         using (var a = new HugeRational("0x" + n + "/0x" + d))
         {
             Assert.AreEqual(n + "/" + d, a.ToString(16));
             Assert.AreEqual(n + "/" + d, a.ToString(16, false));
             Assert.AreEqual((n + "/" + d).ToLower(), a.ToString(16, true));
             a.SetTo("-0x" + n + "/0x17");
             Assert.AreEqual("-" + n + "/17", a.ToString(16));
         }
     }
 }
Exemplo n.º 37
0
 public void RationalStringConstructorHexPrefix()
 {
     using (var i = new HugeInt("362736035870515331128527330659"))
     {
         var d = i.ToString(16);
         var n = "143210ABCDEF32123457ACDB324598799";
         using (var a = new HugeRational("0x" + n + "/0x" + d))
         {
             Assert.AreEqual(n + "/" + d, a.ToString(16));
             Assert.AreEqual(i, a.Denominator);
         }
     }
 }
Exemplo n.º 38
0
 public void RationalShiftRight()
 {
     using (var a = new HugeRational("ABCDEF052834524092854092874502983745029345723098457209305983434345/17607EF654EB9A13FFA163C75", 16))
     {
         uint b = 96;
         a.Value = a >> b;
         Assert.AreEqual("ABCDEF052834524092854092874502983745029345723098457209305983434345/17607EF654EB9A13FFA163C75000000000000000000000000", a.ToString(16));
     }
 }
Exemplo n.º 39
0
        public void RationalConstructorFromLongNegative()
        {
            var n = Platform.Si(-123456789123456, -1234567891);
            var d = Platform.Ui(12764787846358441471U, 2860486313U);

            using (var a = new HugeRational(n, d))
            {
                Assert.AreEqual(1, a.NumeratorNumberOfLimbsAllocated());
                Assert.AreEqual(-1, a.NumeratorNumberOfLimbsUsed());
                Assert.AreEqual(1, a.DenominatorNumberOfLimbsAllocated());
                Assert.AreEqual(1, a.DenominatorNumberOfLimbsUsed());
                Assert.AreEqual(n + "/" + d, a.ToString());
            }
        }
Exemplo n.º 40
0
 public void RationalNegate()
 {
     using (var a = new HugeRational("24092854092874502983745029345723098457209/115756986668303657898962467957"))
     {
         a.Value = -a;
         Assert.AreEqual("-24092854092874502983745029345723098457209/115756986668303657898962467957", a.ToString());
         a.Value = -a;
         Assert.AreEqual("24092854092874502983745029345723098457209/115756986668303657898962467957", a.ToString());
     }
 }
Exemplo n.º 41
0
 public void RationalMultiplyLimbBy()
 {
     using (var a = new HugeRational("90234098723098475098479385345098345/115756986668303657898962467957"))
     {
         var b = Platform.Ui(17390538260286101342, 1500450271);
         a.Value = b * a;
         Assert.AreEqual(Platform.Select(
             "1569219546226477273686601978789044606491747469626478990/115756986668303657898962467957",
             "135391777882513860921200145428966240276901495/115756986668303657898962467957"),
             a.ToString());
     }
 }
Exemplo n.º 42
0
 public void RationalAssignInt2()
 {
     using (var a = new HugeInt("222509832503450298345029835740293845719"))
         using (var d = new HugeInt("115756986668303657898962467957"))
             using (var b = new HugeRational("1/3"))
             {
                 b.SetTo(a, d);
                 Assert.AreEqual("222509832503450298345029835740293845719/115756986668303657898962467957", b.ToString());
                 b.SetTo(b.Numerator - b.Denominator, b.Denominator * 5);
                 Assert.AreEqual(a - d, b.Numerator);
                 Assert.AreEqual(d * 5, b.Denominator);
             }
 }
Exemplo n.º 43
0
 public void RationalAssignCopy()
 {
     using (var a = new HugeRational("-222509832503450298345029835740293845720/115756986668303657898962467957"))
         using (var b = new HugeRational())
         {
             b.Value = a;
             Assert.AreEqual("-222509832503450298345029835740293845720/115756986668303657898962467957", b.ToString());
         }
 }
Exemplo n.º 44
0
 public void RationalCompoundOperators()
 {
     using (var a = new HugeRational("938475092834705928347523452345/115756986668303657898962467957"))
     {
         a.Value += 1;
         a.Value *= 10;
         Assert.AreEqual("10542320795030095862464859203020/115756986668303657898962467957", a.ToString());
     }
 }
Exemplo n.º 45
0
 public void RationalMultiplySignedLimbBy()
 {
     using (var a = new HugeRational("90234098723098475098479385345098345/115756986668303657898962467957"))
     {
         var b = Platform.Si(-7390538260286101342, -1987450271);
         a.Value = b * a;
         Assert.AreEqual(Platform.Select(
             "-666878558995492522701808125338061156491747469626478990/115756986668303657898962467957",
             "-179335783960662818294159606092029134291901495/115756986668303657898962467957"),
             a.ToString());
     }
 }
Exemplo n.º 46
0
 public void RationalToStringDecimal()
 {
     var n = "-23429384756298357462983476598345623984756";
     var d = "115756986668303657898962467957";
     var s = n + "/" + d;
     using (var a = new HugeRational(s))
     {
         Assert.AreEqual(s, a.ToString());
     }
 }
Exemplo n.º 47
0
 public void RationalShiftLeft()
 {
     using (var a = new HugeRational("-12345700987ABCDEF2345CBDEFA245230948/17607EF654EB9A13FFA163C75", 16))
     {
         uint b = 40;
         a.Value = a << b;
         Assert.AreEqual("-12345700987ABCDEF2345CBDEFA2452309480000000000/17607EF654EB9A13FFA163C75", a.ToString(16));
     }
 }
Exemplo n.º 48
0
 public void RationalToStringHex()
 {
     var n = "-23429abcdef298357462983fedcba345623984756";
     var d = "17607ef654eb9a13ffa163c75";
     var s = n + "/" + d;
     using (var a = new HugeRational(s, 16))
     {
         Assert.AreEqual(s, a.ToString(16, true));
         Assert.AreEqual(s.ToUpper(), a.ToString(16));
     }
 }
Exemplo n.º 49
0
        public void RationalInputOutputStrBinary()
        {
            using (var a = new HugeRational("0x10123456789ABCDEF0123456789ABCDEF0123456789ABCDEF/361720912810755408215708460645842859722715865206816237944587"))
            using (var b = new HugeRational())
            using (var ms = new MemoryStream())
            {
                a.Value = a ^ 100;
                using (var writer = new StreamWriter(ms, Encoding.UTF8, 1024, true))
                    a.Write(writer, 2);

                ms.Position = 0;

                using (var reader = new StreamReader(ms, Encoding.UTF8, false, 1024, true))
                    b.Read(reader, 2);

                Assert.AreEqual(a, b);
                Assert.AreEqual(ms.Length, ms.Position);
                Assert.AreEqual((char)0xFEFF + a.ToString(2), Encoding.UTF8.GetString(ms.ToArray()));
            }
        }
Exemplo n.º 50
0
 public void RationalToStringTruncated()
 {
     using (var d = new HugeInt("115756986668303657898962467957"))
     using (var e = new HugeInt(d ^ 10))
     {
         var s = e.ToString(10);
         var n = string.Concat("123456789".Select(c => new string(c, 30)));
         using (var a = new HugeRational(n + "/" + s))
         {
             Assert.AreEqual(n + "/" + s, a.ToString(10));
             Assert.AreEqual("..." + n.Substring(n.Length - 256) + "/..." + s.Substring(s.Length - 256), a.ToString());
             a.Value = -a;
             Assert.AreEqual("-..." + n.Substring(n.Length - 256) + "/..." + s.Substring(s.Length - 256), a.ToString());
         }
     }
 }
Exemplo n.º 51
0
        public void RationalConstructorFromULong()
        {
            var n = Platform.Ui(ulong.MaxValue, uint.MaxValue);
            var d = Platform.Ui(12764787846358441471U, 2860486313U);

            using (var a = new HugeRational(n, d))
            {
                Assert.AreEqual(1, a.NumeratorNumberOfLimbsAllocated());
                Assert.AreEqual(1, a.NumeratorNumberOfLimbsUsed());
                Assert.AreEqual(1, a.DenominatorNumberOfLimbsAllocated());
                Assert.AreEqual(1, a.DenominatorNumberOfLimbsUsed());
                Assert.AreEqual(n.ToString(), a.Numerator.ToString());
                Assert.AreEqual(n.ToString() + "/" + d, a.ToString());
            }
        }
Exemplo n.º 52
0
        public void RationalFromString()
        {
            using (var a = new HugeRational())
            {
                var n = "98762934876529834765234123984761/115756986668303657898962467957";
                a.SetTo(n);
                Assert.AreEqual(n, a.ToString());

                n = "-98ABCDEF876529834765234123984761/17607EF654EB9A13FFA163C75";
                a.SetTo(n, 16);
                Assert.AreEqual(n, a.ToString(16));

                n = "-98ABCDEF876529834765234123984761";
                a.SetTo(n, 16);
                Assert.AreEqual(n + "/1", a.ToString(16));
            }
        }
Exemplo n.º 53
0
 public void RationalStringConstructor()
 {
     var n = "5432109876543212345789023245987/362736035870515331128527330659";
     using (var a = new HugeRational(n))
     {
         Assert.AreEqual(128 / MpirSettings.BITS_PER_LIMB, a.NumeratorNumberOfLimbsUsed());
         Assert.AreEqual(n, a.ToString());
     }
 }
Exemplo n.º 54
0
 public void RationalDivideHugeRational()
 {
     using (var a = new HugeRational("115756986668303657898962467957/394580293847502987609283945873594873409587"))
     using (var b = new HugeRational("593169091750307653294"))
     {
         a.Value = a / b;
         Assert.AreEqual("115756986668303657898962467957/234052834524092854092760134269509268758750275703033222451729578", a.ToString());
     }
 }
Exemplo n.º 55
0
 public void RationalStringConstructorNumeratorOnly()
 {
     var n = "5432109876543212345789023245987";
     using(var a = new HugeRational(n))
     {
         Assert.AreEqual(128 / MpirSettings.BITS_PER_LIMB, a.NumeratorNumberOfLimbsUsed());
         Assert.AreEqual(n + "/1", a.ToString());
     }
 }
Exemplo n.º 56
0
 public void RationalDivideLimbBy()
 {
     using(var a = new HugeRational("115756986668303657898962467957/39458029384750298767200622330399462537522498"))
     {
         var b = Platform.Ui(5931690917503076532, 3367900313);
         a.Value = b / a;
         Assert.AreEqual(Platform.Select(
             "234052834524092854092874502983745029345723092857791404165816936/115756986668303657898962467957",
             "132890709515263728644898490080347139295153795258741874/115756986668303657898962467957"),
             a.ToString());
     }
 }
Exemplo n.º 57
0
 public void RationalInvert()
 {
     using (var a = new HugeRational("-24092854092874502983745029345723098457209/115756986668303657898962467957"))
     {
         a.Value = a.Invert();
         Assert.AreEqual("-115756986668303657898962467957/24092854092874502983745029345723098457209", a.ToString());
         a.Value = a.Invert();
         Assert.AreEqual("-24092854092874502983745029345723098457209/115756986668303657898962467957", a.ToString());
     }
 }
Exemplo n.º 58
0
 public void RationalDivideSignedLimbBy()
 {
     using(var a = new HugeRational("115756986668303657898962467957/39458029384750298767200622330399462537522498"))
     {
         var b = Platform.Si(-5931690917503076532, -1500450271);
         a.Value = b / a;
         Assert.AreEqual(Platform.Select(
             "-234052834524092854092874502983745029345723092857791404165816936/115756986668303657898962467957",
             "-59204810883474549052577139687016525102679979792696958/115756986668303657898962467957"),
             a.ToString());
     }
 }
Exemplo n.º 59
0
 public void RationalConstructorFromIntExpression()
 {
     using (var a = new HugeInt("2340958273409578234095823045723490587"))
     using (var b = new HugeRational(a + 1))
     {
         Assert.AreEqual("2340958273409578234095823045723490588/1", b.ToString());
     }
 }
Exemplo n.º 60
0
 public void RationalAssignInt2()
 {
     using (var a = new HugeInt("222509832503450298345029835740293845719"))
     using (var d = new HugeInt("115756986668303657898962467957"))
     using (var b = new HugeRational("1/3"))
     {
         b.SetTo(a, d);
         Assert.AreEqual("222509832503450298345029835740293845719/115756986668303657898962467957", b.ToString());
         b.SetTo(b.Numerator - b.Denominator, b.Denominator * 5);
         Assert.AreEqual(a - d, b.Numerator);
         Assert.AreEqual(d * 5, b.Denominator);
     }
 }