Exemple #1
0
        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)));
            }
        }
Exemple #2
0
        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)));
                        }
        }
Exemple #3
0
 public void RationalCompareToLimb()
 {
     using (var a = new HugeRational("-222509821"))
     {
         var b = Platform.Ui(222509820, 222509820);
         Assert.AreEqual(-1, System.Math.Sign(a.CompareTo(b)));
         Assert.AreEqual(-1, System.Math.Sign(a.CompareTo(b + 1)));
         Assert.AreEqual(0, System.Math.Sign((-(a + 1)).CompareTo(b)));
         Assert.AreEqual(1, System.Math.Sign((-a).CompareTo(b)));
     }
 }
Exemple #4
0
 public void RationalCompareToHugeRational()
 {
     using (var a = new HugeRational("-222509832503450298345029835740293845721/115756986668303657898962467957"))
     using (var b = new HugeRational("222509832503450298345029835740293845720/115756986668303657898962467957"))
     using (var c = new HugeRational("1/115756986668303657898962467957"))
     {
         Assert.AreEqual(1, System.Math.Sign(b.CompareTo(a)));
         Assert.AreEqual(-1, System.Math.Sign(a.CompareTo(b + 1)));
         Assert.AreEqual(0, System.Math.Sign((a + c).CompareTo(-b)));
         Assert.AreEqual(1, System.Math.Sign(a.CompareTo(null)));
     }
 }
Exemple #5
0
 public void RationalCompareToHugeRational()
 {
     using (var a = new HugeRational("-222509832503450298345029835740293845721/115756986668303657898962467957"))
         using (var b = new HugeRational("222509832503450298345029835740293845720/115756986668303657898962467957"))
             using (var c = new HugeRational("1/115756986668303657898962467957"))
             {
                 Assert.AreEqual(1, System.Math.Sign(b.CompareTo(a)));
                 Assert.AreEqual(-1, System.Math.Sign(a.CompareTo(b + 1)));
                 Assert.AreEqual(0, System.Math.Sign((a + c).CompareTo(-b)));
                 Assert.AreEqual(1, System.Math.Sign(a.CompareTo(null)));
             }
 }
Exemple #6
0
 public void RationalCompareToSignedDouble()
 {
     using (var a = new HugeRational("-222509821"))
     {
         double b = -222509820;
         Assert.AreEqual(-1, System.Math.Sign(a.CompareTo(b)));
         Assert.AreEqual(-1, System.Math.Sign(a.CompareTo(b + 1)));
         Assert.AreEqual(0, System.Math.Sign((a + 1).CompareTo(b)));
         Assert.AreEqual(0, System.Math.Sign(a.CompareTo(b - 1)));
         Assert.AreEqual(1, System.Math.Sign(a.CompareTo(b - 1.1)));
     }
 }
Exemple #7
0
 public void RationalCompareToSignedLimb()
 {
     using (var a = new HugeRational("-222509821"))
     {
         var b = Platform.Si(-222509820, -222509820);
         Assert.AreEqual(-1, System.Math.Sign(a.CompareTo(b)));
         Assert.AreEqual(-1, System.Math.Sign(a.CompareTo(b + 1)));
         Assert.AreEqual(0, System.Math.Sign((a + 1).CompareTo(b)));
         Assert.AreEqual(0, System.Math.Sign(a.CompareTo(b - 1)));
         Assert.AreEqual(1, System.Math.Sign(a.CompareTo(b - 2)));
     }
 }
Exemple #8
0
 public void RationalCompareToLimb2()
 {
     using (var a = new HugeRational("-222509947/127"))
     {
         uint b = 222509820;
         uint d = 127;
         Assert.AreEqual(-1, System.Math.Sign(a.CompareTo(b, d)));
         Assert.AreEqual(-1, System.Math.Sign(a.CompareTo(b + 1, d)));
         Assert.AreEqual(0, System.Math.Sign((-(a + 1)).CompareTo(b, d)));
         Assert.AreEqual(0, System.Math.Sign((-a).CompareTo(b + d, d)));
         Assert.AreEqual(1, System.Math.Sign((-a).CompareTo(b, d)));
     }
 }
Exemple #9
0
 public void RationalCompareToSignedLimb2()
 {
     using (var a = new HugeRational("-222509947/127"))
     {
         int b = -222509820;
         int d = 127;
         Assert.AreEqual(-1, System.Math.Sign(a.CompareTo(b, (uint)d)));
         Assert.AreEqual(-1, System.Math.Sign(a.CompareTo(b + 1, (uint)d)));
         Assert.AreEqual(0, System.Math.Sign((a + 1).CompareTo(b, (uint)d)));
         Assert.AreEqual(-1, System.Math.Sign(a.CompareTo(b - d + 1, (uint)d)));
         Assert.AreEqual(0, System.Math.Sign(a.CompareTo(b - d, (uint)d)));
         Assert.AreEqual(1, System.Math.Sign(a.CompareTo(b - d - 1, (uint)d)));
     }
 }
Exemple #10
0
 public void RationalCompareToNonExpression()
 {
     using (var a = new HugeRational("-222509832503450298345029835740293845721/115756986668303657898962467957"))
     {
         a.CompareTo("abc");
     }
 }
Exemple #11
0
 public void RationalCompareToLimb()
 {
     using (var a = new HugeRational("-222509821"))
     {
         var b = Platform.Ui(222509820, 222509820);
         Assert.AreEqual(-1, System.Math.Sign(a.CompareTo(b)));
         Assert.AreEqual(-1, System.Math.Sign(a.CompareTo(b + 1)));
         Assert.AreEqual(0, System.Math.Sign((-(a + 1)).CompareTo(b)));
         Assert.AreEqual(1, System.Math.Sign((-a).CompareTo(b)));
     }
 }
Exemple #12
0
 public void RationalCompareToSignedLimb2()
 {
     using(var a = new HugeRational("-222509947/127"))
     {
         int b = -222509820;
         int d = 127;
         Assert.AreEqual(-1, System.Math.Sign(a.CompareTo(b, (uint)d)));
         Assert.AreEqual(-1, System.Math.Sign(a.CompareTo(b + 1, (uint) d)));
         Assert.AreEqual(0, System.Math.Sign((a + 1).CompareTo(b, (uint) d)));
         Assert.AreEqual(-1, System.Math.Sign(a.CompareTo(b - d + 1, (uint) d)));
         Assert.AreEqual(0, System.Math.Sign(a.CompareTo(b - d, (uint) d)));
         Assert.AreEqual(1, System.Math.Sign(a.CompareTo(b - d - 1, (uint) d)));
     }
 }
Exemple #13
0
 public void RationalCompareToSignedLimb()
 {
     using (var a = new HugeRational("-222509821"))
     {
         var b = Platform.Si(-222509820, -222509820);
         Assert.AreEqual(-1, System.Math.Sign(a.CompareTo(b)));
         Assert.AreEqual(-1, System.Math.Sign(a.CompareTo(b + 1)));
         Assert.AreEqual(0, System.Math.Sign((a + 1).CompareTo(b)));
         Assert.AreEqual(0, System.Math.Sign(a.CompareTo(b - 1)));
         Assert.AreEqual(1, System.Math.Sign(a.CompareTo(b - 2)));
     }
 }
Exemple #14
0
 public void RationalCompareToSignedDouble()
 {
     using (var a = new HugeRational("-222509821"))
     {
         double b = -222509820;
         Assert.AreEqual(-1, System.Math.Sign(a.CompareTo(b)));
         Assert.AreEqual(-1, System.Math.Sign(a.CompareTo(b + 1)));
         Assert.AreEqual(0, System.Math.Sign((a + 1).CompareTo(b)));
         Assert.AreEqual(0, System.Math.Sign(a.CompareTo(b - 1)));
         Assert.AreEqual(1, System.Math.Sign(a.CompareTo(b - 1.1)));
     }
 }
Exemple #15
0
 public void RationalCompareToNonExpression()
 {
     using (var a = new HugeRational("-222509832503450298345029835740293845721/115756986668303657898962467957"))
     {
         a.CompareTo("abc");
     }
 }
Exemple #16
0
 public void RationalCompareToLimb2()
 {
     using(var a = new HugeRational("-222509947/127"))
     {
         uint b = 222509820;
         uint d = 127;
         Assert.AreEqual(-1, System.Math.Sign(a.CompareTo(b, d)));
         Assert.AreEqual(-1, System.Math.Sign(a.CompareTo(b + 1, d)));
         Assert.AreEqual(0, System.Math.Sign((-(a + 1)).CompareTo(b, d)));
         Assert.AreEqual(0, System.Math.Sign((-a).CompareTo(b + d, d)));
         Assert.AreEqual(1, System.Math.Sign((-a).CompareTo(b, d)));
     }
 }