Exemple #1
0
 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;
     }
 }
Exemple #2
0
 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;
                 }
 }
Exemple #3
0
 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)));
         }
 }
Exemple #4
0
 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)));
     }
 }
Exemple #5
0
 public void FloatCompareToSignedDouble()
 {
     using (var a = new HugeFloat("-222509821"))
     {
         double b = -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 - 1.1)));
     }
 }
Exemple #6
0
 public void FloatCompareToSignedLimb()
 {
     using (var a = new HugeFloat(Platform.Select("-222509825551", "-222509821")))
     {
         var b = Platform.Si(-222509825550, -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 - 2)));
     }
 }
Exemple #7
0
 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)));
     }
 }
Exemple #8
0
 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)));
     }
 }
Exemple #9
0
 public void FloatCompareToNonExpression()
 {
     using (var a = new HugeFloat("-222509832503450298345029835740293845721.57898962467957"))
     {
         a.CompareTo("abc");
     }
 }
Exemple #10
0
 public void FloatCompareToNonExpression()
 {
     using (var a = new HugeFloat("-222509832503450298345029835740293845721.57898962467957"))
     {
         a.CompareTo("abc");
     }
 }
Exemple #11
0
        public void FloatCompareToHugeIntExpression()
        {
            var previousDefaultPrecision = HugeFloat.DefaultPrecision;

            HugeFloat.DefaultPrecision = 256;

            using (var a = new HugeFloat("-222509832503450298345039835740293845721345345354"))
                using (var b = new HugeInt("222509832503450298345039835740293845721345345353"))
                {
                    Assert.AreEqual(-1, Math.Sign(a.CompareTo(b)));
                    Assert.AreEqual(-1, Math.Sign(a.CompareTo(-b)));
                    Assert.AreEqual(0, Math.Sign(a.CompareTo(-b - 1)));
                    Assert.AreEqual(1, Math.Sign(a.CompareTo(-b - 2)));

                    Assert.AreEqual(-1, Math.Sign((a + 1).CompareTo(b)));
                    Assert.AreEqual(0, Math.Sign((a + 1).CompareTo(-b)));
                    Assert.AreEqual(-1, Math.Sign((a + 1).CompareTo(1 - b)));
                    Assert.AreEqual(1, Math.Sign((a + 1).CompareTo(-b - 1)));
                }

            HugeFloat.DefaultPrecision = previousDefaultPrecision;
        }
Exemple #12
0
 public void FloatCompareToSignedDouble()
 {
     using (var a = new HugeFloat("-222509821"))
     {
         double b = -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 - 1.1)));
     }
 }
Exemple #13
0
 public void FloatCompareToSignedLimb()
 {
     using (var a = new HugeFloat(Platform.Select("-222509825551", "-222509821")))
     {
         var b = Platform.Si(-222509825550, -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 - 2)));
     }
 }