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))); } }
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))); } }
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))); } }
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))); } }
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))); } }
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))); } }
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))); } }
public void RationalCompareToNonExpression() { using (var a = new HugeRational("-222509832503450298345029835740293845721/115756986668303657898962467957")) { a.CompareTo("abc"); } }
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))); } }
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))); } }