예제 #1
0
        public void DivNonCanonicOperator()
        {
            string AsString;

            using mpz_t n0 = new mpz_t("222509832503450298345029835740293845720");
            using mpz_t d0 = new mpz_t("115756986668303657898962467957");

            using mpq_t a = new mpq_t(n0, d0);
            AsString      = a.ToString();
            Assert.AreEqual("222509832503450298345029835740293845720/115756986668303657898962467957", AsString);

            using mpz_t n1 = new mpz_t("590872612825179551336102196593");
            using mpz_t d1 = new mpz_t("222987435987982730594288574029879874539");

            using mpq_t b = new mpq_t(n1, d1);
            AsString      = b.ToString();
            Assert.AreEqual("590872612825179551336102196593/222987435987982730594288574029879874539", AsString);

            using mpz_t n2 = n0 * 2;
            using mpz_t d2 = d0 * 17;

            using mpq_t c = new mpq_t(n2, d2);
            AsString      = c.ToString();
            Assert.AreEqual("445019665006900596690059671480587691440/1967868773361162184282361955269", AsString);

            c.Canonicalize();

            AsString = c.ToString();
            Assert.AreEqual("445019665006900596690059671480587691440/1967868773361162184282361955269", AsString);

            using mpz_t n3 = n1 * 2;
            using mpz_t d3 = d1 * 17;

            using mpq_t d = new mpq_t(n3, d3);
            AsString      = d.ToString();
            Assert.AreEqual("1181745225650359102672204393186/3790786411795706420102905758507957867163", AsString);

            d.Canonicalize();

            AsString = d.ToString();
            Assert.AreEqual("1181745225650359102672204393186/3790786411795706420102905758507957867163", AsString);

            using mpq_t e = c / d;

            AsString = e.ToString();
            Assert.AreEqual("49616897032059882578779559314539403611774953165369490340046561577107422123080/68397633165470058274884361378645822467587248043012077070501", AsString);

            using mpz_t Numerator = c.GetNumerator() * d.GetDenominator();

            AsString = Numerator.ToString();
            Assert.AreNotEqual("49616897032059882578779559314539403611774953165369490340046561577107422123080", AsString);
        }
예제 #2
0
        public void AddNonCanonicOperator()
        {
            string AsString;

            using mpz_t n0 = new mpz_t("222509832503450298345029835740293845720");
            using mpz_t d0 = new mpz_t("115756986668303657898962467957");

            using mpq_t a = new mpq_t(n0, d0);
            AsString      = a.ToString();
            Assert.AreEqual("222509832503450298345029835740293845720/115756986668303657898962467957", AsString);

            using mpz_t n1 = new mpz_t("222987435987982730594288574029879874539");
            using mpz_t d1 = new mpz_t("590872612825179551336102196593");

            using mpq_t b = new mpq_t(n1, d1);
            AsString      = b.ToString();
            Assert.AreEqual("222987435987982730594288574029879874539/590872612825179551336102196593", AsString);

            using mpz_t n2 = n0 * 2;
            using mpz_t d2 = d0 * 17;

            using mpq_t c = new mpq_t(n2, d2);
            AsString      = c.ToString();
            Assert.AreEqual("445019665006900596690059671480587691440/1967868773361162184282361955269", AsString);

            c.Canonicalize();

            AsString = c.ToString();
            Assert.AreEqual("445019665006900596690059671480587691440/1967868773361162184282361955269", AsString);

            using mpz_t n3 = n1 * 2;
            using mpz_t d3 = d1 * 17;

            using mpq_t d = new mpq_t(n3, d3);
            AsString      = d.ToString();
            Assert.AreEqual("445974871975965461188577148059759749078/10044834418028052372713737342081", AsString);

            d.Canonicalize();

            AsString = d.ToString();
            Assert.AreEqual("445974871975965461188577148059759749078/10044834418028052372713737342081", AsString);

            using mpq_t e = c + d;

            AsString = e.ToString();
            Assert.AreEqual("314574639530933745596599719402044828752321603866779219489192838557566/1162759763812990990673034143436978981948983216731205310198517", AsString);

            using mpz_t Numerator = c.GetNumerator() * d.GetDenominator() + d.GetNumerator() * c.GetDenominator();

            AsString = Numerator.ToString();
            Assert.AreNotEqual("314574639530933745596599719402044828752321603866779219489192838557566", AsString);
        }
예제 #3
0
        public void DivCanonic()
        {
            string AsString;

            using mpq_t a = new mpq_t("222509832503450298345029835740293845720/115756986668303657898962467957");
            AsString      = a.ToString();
            Assert.AreEqual("222509832503450298345029835740293845720/115756986668303657898962467957", AsString);

            using mpq_t b = new mpq_t("590872612825179551336102196593/222987435987982730594288574029879874539");
            AsString      = b.ToString();
            Assert.AreEqual("590872612825179551336102196593/222987435987982730594288574029879874539", AsString);

            using mpq_t c = new();
            mpq.div(c, a, b);

            AsString = c.ToString();
            Assert.AreEqual("49616897032059882578779559314539403611774953165369490340046561577107422123080/68397633165470058274884361378645822467587248043012077070501", AsString);

            AsString = c.GetNumerator().ToString();
            Assert.AreEqual("49616897032059882578779559314539403611774953165369490340046561577107422123080", AsString);

            AsString = c.GetDenominator().ToString();
            Assert.AreEqual("68397633165470058274884361378645822467587248043012077070501", AsString);

            using mpz_t Numerator = a.GetNumerator() * b.GetDenominator();

            AsString = Numerator.ToString();
            Assert.AreEqual("49616897032059882578779559314539403611774953165369490340046561577107422123080", AsString);

            using mpz_t Denominator = a.GetDenominator() * b.GetNumerator();

            AsString = Denominator.ToString();
            Assert.AreEqual("68397633165470058274884361378645822467587248043012077070501", AsString);
        }
예제 #4
0
        public void AddCanonic()
        {
            string AsString;

            using mpq_t a = new mpq_t("222509832503450298345029835740293845720/115756986668303657898962467957");
            AsString      = a.ToString();
            Assert.AreEqual("222509832503450298345029835740293845720/115756986668303657898962467957", AsString);

            using mpq_t b = new mpq_t("222987435987982730594288574029879874539/590872612825179551336102196593");
            AsString      = b.ToString();
            Assert.AreEqual("222987435987982730594288574029879874539/590872612825179551336102196593", AsString);

            using mpq_t c = new();
            mpq.add(c, a, b);

            AsString = c.ToString();
            Assert.AreEqual("157287319765466872798299859701022414376160801933389609744596419278783/68397633165470058274884361378645822467587248043012077070501", AsString);

            AsString = c.GetNumerator().ToString();
            Assert.AreEqual("157287319765466872798299859701022414376160801933389609744596419278783", AsString);

            AsString = c.GetDenominator().ToString();
            Assert.AreEqual("68397633165470058274884361378645822467587248043012077070501", AsString);

            using mpz_t Numerator = a.GetNumerator() * b.GetDenominator() + b.GetNumerator() * a.GetDenominator();

            AsString = Numerator.ToString();
            Assert.AreEqual("157287319765466872798299859701022414376160801933389609744596419278783", AsString);

            using mpz_t Denominator = a.GetDenominator() * b.GetDenominator();

            AsString = Denominator.ToString();
            Assert.AreEqual("68397633165470058274884361378645822467587248043012077070501", AsString);
        }
예제 #5
0
        public void SubCanonic()
        {
            string AsString;

            using mpq_t a = new mpq_t("222509832503450298345029835740293845720/115756986668303657898962467957");
            AsString      = a.ToString();
            Assert.AreEqual("222509832503450298345029835740293845720/115756986668303657898962467957", AsString);

            using mpq_t b = new mpq_t("222987435987982730594288574029879874539/590872612825179551336102196593");
            AsString      = b.ToString();
            Assert.AreEqual("222987435987982730594288574029879874539/590872612825179551336102196593", AsString);

            using mpq_t c = new();
            mpq.sub(c, a, b);

            AsString = c.ToString();
            Assert.AreEqual("105662612455746608298450986036810175085932336578065613346946483985137/68397633165470058274884361378645822467587248043012077070501", AsString);

            AsString = c.GetNumerator().ToString();
            Assert.AreEqual("105662612455746608298450986036810175085932336578065613346946483985137", AsString);

            AsString = c.GetDenominator().ToString();
            Assert.AreEqual("68397633165470058274884361378645822467587248043012077070501", AsString);

            using mpz_t Numerator = a.GetNumerator() * b.GetDenominator() - b.GetNumerator() * a.GetDenominator();

            AsString = Numerator.ToString();
            Assert.AreEqual("105662612455746608298450986036810175085932336578065613346946483985137", AsString);

            using mpz_t Denominator = a.GetDenominator() * b.GetDenominator();

            AsString = Denominator.ToString();
            Assert.AreEqual("68397633165470058274884361378645822467587248043012077070501", AsString);
        }
예제 #6
0
        public void Inverse()
        {
            string AsString;

            using mpq_t a = new mpq_t("222509832503450298345029835740293845720/115756986668303657898962467957");
            AsString      = a.ToString();
            Assert.AreEqual("222509832503450298345029835740293845720/115756986668303657898962467957", AsString);

            using mpq_t b = a.Inverse();
            AsString      = b.ToString();
            Assert.AreEqual("115756986668303657898962467957/222509832503450298345029835740293845720", AsString);

            using mpq_t c = b.Inverse();
            AsString      = c.ToString();
            Assert.AreEqual("222509832503450298345029835740293845720/115756986668303657898962467957", AsString);
        }
예제 #7
0
        public void ShiftLeft()
        {
            string AsString;

            using mpq_t a = new mpq_t("222509832503450298345029835740293845720/115756986668303657898962467957");
            AsString      = a.ToString();
            Assert.AreEqual("222509832503450298345029835740293845720/115756986668303657898962467957", AsString);

            using mpq_t b = a << 257;
            AsString      = b.ToString();
            Assert.AreEqual("51529756762839593294198211100314734677817449692818126743552213301752723958667489051678620805933418286778280669347840/115756986668303657898962467957", AsString);

            using mpq_t c = b >> 257;
            AsString      = c.ToString();
            Assert.AreEqual("222509832503450298345029835740293845720/115756986668303657898962467957", AsString);
        }
예제 #8
0
        public void ShiftRight()
        {
            string AsString;

            using mpq_t a = new mpq_t("222509832503450298345029835740293845720/115756986668303657898962467957");
            AsString      = a.ToString();
            Assert.AreEqual("222509832503450298345029835740293845720/115756986668303657898962467957", AsString);

            using mpq_t b = a >> 257;
            AsString      = b.ToString();
            Assert.AreEqual("27813729062931287293128729467536730715/3350935832534759576070266789807748551319412728141912585771923360591451658754903229238641121083138336882688", AsString);

            using mpq_t c = b << 257;
            AsString      = c.ToString();
            Assert.AreEqual("222509832503450298345029835740293845720/115756986668303657898962467957", AsString);
        }
예제 #9
0
        public void DivRational()
        {
            string AsString;

            Assert.IsTrue(mpfr_t.LiveObjectCount() == 0);

            ulong DefaultPrecision = mpfr_t.DefaultPrecision;

            mpfr_t.DefaultPrecision = 128;

            using mpfr_t a = new mpfr_t("22250983250345029834502983.5740293845720");
            AsString       = a.ToString();
            Assert.AreEqual("2.2250983250345029834502983574029384571986156515777111053466796875E+25", AsString);

            using mpq_t b = new mpq_t("-222987435987982730594288574029879874539/590872612825179551336102196593");
            AsString      = b.ToString();
            Assert.AreEqual("-222987435987982730594288574029879874539/590872612825179551336102196593", AsString);

            using mpfr_t c = a / b;

            AsString = c.ToString();
            Assert.AreEqual("-5.8960705803035560895114797706756890241890293308767156954530719303875230252742767333984375E+16", AsString);

            using mpfr_t d = b / a;

            AsString = d.ToString();
            Assert.AreEqual("-1.6960448257532824963330331211823807141349784251806416314369913931833001298969603911424991542549574129508512989808951689388685259E-17", AsString);

            using mpfr_t bF = new mpfr_t(b);
            AsString        = bF.ToString();
            Assert.AreEqual("-3.77386650096706435239638030739606963153305132554456961429446650350093273029727924949838779866695404052734375E+8", AsString);

            using mpfr_t e = a / c;

            AsString = e.ToString();
            Assert.AreEqual("-3.77386650096706435239638030739606963153305132554456961429446650350093273029727924949838779866695404052734375E+8", AsString);

            using mpfr_t f = d * a;

            AsString = f.ToString();
            Assert.AreEqual("-3.77386650096706435239638030739606963153305132554456961429446650350093273029727924949838779866695404052734375E+8", AsString);

            mpfr_t.DefaultPrecision = DefaultPrecision;
        }
예제 #10
0
        public void GreaterThan()
        {
            string AsString;
            bool   IsGreaterThan;

            using mpq_t a = new mpq_t("222509832503450298345029835740293845720/115756986668303657898962467957");
            AsString      = a.ToString();
            Assert.AreEqual("222509832503450298345029835740293845720/115756986668303657898962467957", AsString);

            using mpq_t b = new mpq_t("222987435987982730594288574029879874539/590872612825179551336102196593");
            AsString      = b.ToString();
            Assert.AreEqual("222987435987982730594288574029879874539/590872612825179551336102196593", AsString);

            IsGreaterThan = a > b;
            Assert.IsTrue(IsGreaterThan);

            IsGreaterThan = mpq.cmp_ui(a, 1922215141, 1) > 0;
            Assert.IsTrue(IsGreaterThan);
        }
예제 #11
0
        public void Create()
        {
            string AsString;

            using mpq_t a = new mpq_t("222509832503450298345029835740293845720/115756986668303657898962467957");
            AsString      = a.ToString();
            Assert.AreEqual("222509832503450298345029835740293845720/115756986668303657898962467957", AsString);

            using mpq_t b = new mpq_t(a);
            AsString      = b.ToString();
            Assert.AreEqual("222509832503450298345029835740293845720/115756986668303657898962467957", AsString);

            using mpq_t c = new(a.GetNumerator());
            AsString      = c.ToString();
            Assert.AreEqual("222509832503450298345029835740293845720", AsString);

            using mpq_t d = new(30, 10);
            AsString      = d.ToString();
            Assert.AreEqual("30/10", AsString);

            using mpq_t e = new(30, 10, true);
            AsString      = e.ToString();
            Assert.AreEqual("3", AsString);

            using mpq_t f = new(-30, 10);
            AsString      = f.ToString();
            Assert.AreEqual("-30/10", AsString);

            using mpq_t g = new(-30, 10, true);
            AsString      = g.ToString();
            Assert.AreEqual("-3", AsString);

            using mpq_t h = new(0.25);
            AsString      = h.ToString();
            Assert.AreEqual("1/4", AsString);

            using mpz_t n0 = new mpz_t("222509832503450298345029835740293845720");
            using mpz_t d0 = new mpz_t("115756986668303657898962467957");
            using mpq_t q0 = new mpq_t(n0, d0);
            AsString       = q0.ToString();
            Assert.AreEqual("222509832503450298345029835740293845720/115756986668303657898962467957", AsString);
        }
예제 #12
0
        public void Abs()
        {
            string AsString;

            using mpq_t a = new mpq_t("222509832503450298345029835740293845720/115756986668303657898962467957");
            AsString      = a.ToString();
            Assert.AreEqual("222509832503450298345029835740293845720/115756986668303657898962467957", AsString);

            using mpq_t b = a.Abs();
            AsString      = b.ToString();
            Assert.AreEqual("222509832503450298345029835740293845720/115756986668303657898962467957", AsString);

            using mpq_t c = new mpq_t("-222509832503450298345029835740293845720/115756986668303657898962467957");
            AsString      = c.ToString();
            Assert.AreEqual("-222509832503450298345029835740293845720/115756986668303657898962467957", AsString);

            using mpq_t d = c.Abs();
            AsString      = d.ToString();
            Assert.AreEqual("222509832503450298345029835740293845720/115756986668303657898962467957", AsString);
        }
예제 #13
0
        public void IsEqual()
        {
            string AsString;
            bool   IsEqualTo;
            bool   IsDifferentThan;

            using mpq_t a = new mpq_t("222509832503450298345029835740293845720/115756986668303657898962467957");
            AsString      = a.ToString();
            Assert.AreEqual("222509832503450298345029835740293845720/115756986668303657898962467957", AsString);

            using mpq_t b = new mpq_t("222987435987982730594288574029879874539/590872612825179551336102196593");
            AsString      = b.ToString();
            Assert.AreEqual("222987435987982730594288574029879874539/590872612825179551336102196593", AsString);

            using mpq_t c = a;

            IsEqualTo = a == c;
            Assert.IsTrue(IsEqualTo);

            IsDifferentThan = a != b;
            Assert.IsTrue(IsDifferentThan);
        }
예제 #14
0
        public void MulRational()
        {
            string AsString;

            Assert.IsTrue(mpfr_t.LiveObjectCount() == 0);

            using mpfr_t a = new mpfr_t("22250983250345029834502983.5740293845720");
            AsString       = a.ToString();
            Assert.AreEqual("2.225098325034502799228928E+25", AsString);

            using mpq_t b = new mpq_t("222987435987982730594288574029879874539/590872612825179551336102196593");
            AsString      = b.ToString();
            Assert.AreEqual("222987435987982730594288574029879874539/590872612825179551336102196593", AsString);

            using mpfr_t c = a * b;

            AsString = c.ToString();
            Assert.AreEqual("8.397224030205634932062496799850496E+33", AsString);

            using mpfr_t d = b * a;

            AsString = d.ToString();
            Assert.AreEqual("8.397224030205634932062496799850496E+33", AsString);
        }
예제 #15
0
        public void SubRational()
        {
            string AsString;

            Assert.IsTrue(mpfr_t.LiveObjectCount() == 0);

            using mpfr_t a = new mpfr_t("22250983250345029834502983.5740293845720");
            AsString       = a.ToString();
            Assert.AreEqual("2.225098325034502799228928E+25", AsString);

            using mpq_t b = new mpq_t("222987435987982730594288574029879874539/590872612825179551336102196593");
            AsString      = b.ToString();
            Assert.AreEqual("222987435987982730594288574029879874539/590872612825179551336102196593", AsString);

            using mpfr_t c = a - b;

            AsString = c.ToString();
            Assert.AreEqual("2.225098325034502799228928E+25", AsString);

            using mpfr_t d = b - a;

            AsString = d.ToString();
            Assert.AreEqual("-2.225098325034502799228928E+25", AsString);
        }
예제 #16
0
        public void GreaterEqual()
        {
            string AsString;
            bool   IsGreaterThan;

            Assert.IsTrue(mpfr_t.LiveObjectCount() == 0);

            using mpfr_t a = new mpfr_t("22250983250345029834502983.5740293845720");
            AsString       = a.ToString();
            Assert.AreEqual("2.225098325034502799228928E+25", AsString);

            using mpfr_t b = new mpfr_t("2229874359879827.30594288574029879874539");
            AsString       = b.ToString();
            Assert.AreEqual("2.22987435987982725E+15", AsString);

            IsGreaterThan = a >= b;
            Assert.IsTrue(IsGreaterThan);

            IsGreaterThan = b >= a;
            Assert.IsFalse(IsGreaterThan);

            IsGreaterThan = a >= 1UL;
            Assert.IsTrue(IsGreaterThan);

            IsGreaterThan = 1UL >= a;
            Assert.IsFalse(IsGreaterThan);

            IsGreaterThan = a >= 1L;
            Assert.IsTrue(IsGreaterThan);

            IsGreaterThan = 1L >= a;
            Assert.IsFalse(IsGreaterThan);

            IsGreaterThan = a >= 1.0;
            Assert.IsTrue(IsGreaterThan);

            IsGreaterThan = 1.0 >= a;
            Assert.IsFalse(IsGreaterThan);

            using mpz_t c = new mpz_t("222509832503450298345029");
            AsString      = c.ToString();
            Assert.AreEqual("222509832503450298345029", AsString);

            IsGreaterThan = a >= c;
            Assert.IsTrue(IsGreaterThan);

            IsGreaterThan = c >= a;
            Assert.IsFalse(IsGreaterThan);

            using mpq_t d = new mpq_t("222509832503450298345029835740293845720/115756986668303657898962467957");
            AsString      = d.ToString();
            Assert.AreEqual("222509832503450298345029835740293845720/115756986668303657898962467957", AsString);

            IsGreaterThan = a >= d;
            Assert.IsTrue(IsGreaterThan);

            IsGreaterThan = d >= a;
            Assert.IsFalse(IsGreaterThan);

            using mpf_t e = new mpf_t("222583250345029834502983.5");
            AsString      = e.ToString();
            Assert.AreEqual("2.22583250345029834503E+23", AsString);

            IsGreaterThan = a >= e;
            Assert.IsTrue(IsGreaterThan);

            IsGreaterThan = e >= a;
            Assert.IsFalse(IsGreaterThan);
        }
예제 #17
0
        public void Different()
        {
            string AsString;
            bool   IsEqualTo;

            Assert.IsTrue(mpfr_t.LiveObjectCount() == 0);

            using mpfr_t a = new mpfr_t("22250983250345029834502983.5740293845720");
            AsString       = a.ToString();
            Assert.AreEqual("2.225098325034502799228928E+25", AsString);

            using mpfr_t b = new mpfr_t("2229874359879827.30594288574029879874539");
            AsString       = b.ToString();
            Assert.AreEqual("2.22987435987982725E+15", AsString);

            IsEqualTo = a != b;
            Assert.IsTrue(IsEqualTo);

            IsEqualTo = b != a;
            Assert.IsTrue(IsEqualTo);

            IsEqualTo = a != 1UL;
            Assert.IsTrue(IsEqualTo);

            IsEqualTo = 1UL != a;
            Assert.IsTrue(IsEqualTo);

            IsEqualTo = a != 1L;
            Assert.IsTrue(IsEqualTo);

            IsEqualTo = 1L != a;
            Assert.IsTrue(IsEqualTo);

            IsEqualTo = a != 1.0;
            Assert.IsTrue(IsEqualTo);

            IsEqualTo = 1.0 != a;
            Assert.IsTrue(IsEqualTo);

            using mpz_t c = new mpz_t("222509832503450298345029");
            AsString      = c.ToString();
            Assert.AreEqual("222509832503450298345029", AsString);

            IsEqualTo = a != c;
            Assert.IsTrue(IsEqualTo);

            IsEqualTo = c != a;
            Assert.IsTrue(IsEqualTo);

            using mpq_t d = new mpq_t("222509832503450298345029835740293845720/115756986668303657898962467957");
            AsString      = d.ToString();
            Assert.AreEqual("222509832503450298345029835740293845720/115756986668303657898962467957", AsString);

            IsEqualTo = a != d;
            Assert.IsTrue(IsEqualTo);

            IsEqualTo = d != a;
            Assert.IsTrue(IsEqualTo);

            using mpf_t e = new mpf_t("222583250345029834502983.5");
            AsString      = e.ToString();
            Assert.AreEqual("2.22583250345029834503E+23", AsString);

            IsEqualTo = a != e;
            Assert.IsTrue(IsEqualTo);

            IsEqualTo = e != a;
            Assert.IsTrue(IsEqualTo);
        }
예제 #18
0
        public void GreaterThan()
        {
            string AsString;
            bool   IsGreaterThan;

            Assert.IsTrue(mpfr_t.LiveObjectCount() == 0);

            ulong DefaultPrecision = mpfr_t.DefaultPrecision;

            mpfr_t.DefaultPrecision = 128;

            using mpfr_t a = new mpfr_t("8720124937520142.5");
            AsString       = a.ToString();
            Assert.AreEqual("8.7201249375201425E+15", AsString);

            using mpfr_t b = new mpfr_t("22298.125");
            AsString       = b.ToString();
            Assert.AreEqual("2.2298125E+4", AsString);

            IsGreaterThan = a > b;
            Assert.IsTrue(IsGreaterThan);

            IsGreaterThan = b > a;
            Assert.IsFalse(IsGreaterThan);

            IsGreaterThan = a > 8720124937520142UL;
            Assert.IsTrue(IsGreaterThan);

            IsGreaterThan = a > 8720124937520143UL;
            Assert.IsFalse(IsGreaterThan);

            IsGreaterThan = 8720124937520142UL > a;
            Assert.IsFalse(IsGreaterThan);

            IsGreaterThan = 8720124937520143UL > a;
            Assert.IsTrue(IsGreaterThan);

            IsGreaterThan = a > 8720124937520142L;
            Assert.IsTrue(IsGreaterThan);

            IsGreaterThan = a > 8720124937520143L;
            Assert.IsFalse(IsGreaterThan);

            IsGreaterThan = 8720124937520142L > a;
            Assert.IsFalse(IsGreaterThan);

            IsGreaterThan = 8720124937520143L > a;
            Assert.IsTrue(IsGreaterThan);

            IsGreaterThan = a > 8720124937520142.1;
            Assert.IsTrue(IsGreaterThan);

            IsGreaterThan = 8720124937520142.9 > a;
            Assert.IsTrue(IsGreaterThan);

            using mpz_t c = new mpz_t("1720124937520142");
            AsString      = c.ToString();
            Assert.AreEqual("1720124937520142", AsString);

            IsGreaterThan = a > c;
            Assert.IsTrue(IsGreaterThan);

            IsGreaterThan = c > a;
            Assert.IsFalse(IsGreaterThan);

            using mpq_t d = new mpq_t("222509832503450298345029835740293845720/115756986668303657898962467957");
            AsString      = d.ToString();
            Assert.AreEqual("222509832503450298345029835740293845720/115756986668303657898962467957", AsString);

            IsGreaterThan = a > d;
            Assert.IsTrue(IsGreaterThan);

            IsGreaterThan = d > a;
            Assert.IsFalse(IsGreaterThan);

            using mpf_t e = new mpf_t("8720124937520142.1");
            AsString      = e.ToString();
            Assert.AreEqual("8.7201249375201421E+15", AsString);

            IsGreaterThan = a > e;
            Assert.IsTrue(IsGreaterThan);

            IsGreaterThan = e > a;
            Assert.IsFalse(IsGreaterThan);

            mpfr_t.DefaultPrecision = DefaultPrecision;
        }
예제 #19
0
        public void CreateFrom()
        {
            string AsString;

            Assert.IsTrue(mpfr_t.LiveObjectCount() == 0);

            using mpfr_t NaN = new mpfr_t();
            AsString         = NaN.ToString();
            Assert.AreEqual("@NaN@", AsString);

            using mpfr_t PositiveInfinite = mpfr_t.Infinite();
            AsString = PositiveInfinite.ToString();
            Assert.AreEqual("@Inf@", AsString);

            using mpfr_t NegativeInfinite = mpfr_t.Infinite(-1);
            AsString = NegativeInfinite.ToString();
            Assert.AreEqual("-@Inf@", AsString);

            using mpfr_t Zero = mpfr_t.Zero();
            AsString          = Zero.ToString();
            Assert.AreEqual("0", AsString);

            using mpfr_t NegativeZero = mpfr_t.Zero(-1);
            AsString = NegativeZero.ToString();
            Assert.AreEqual("-0", AsString);

            using mpfr_t b = new mpfr_t(10);
            AsString       = b.ToString();
            Assert.AreEqual("1E+1", AsString);

            using mpfr_t c = new mpfr_t(b);
            AsString       = c.ToString();
            Assert.AreEqual("1E+1", AsString);

            using mpfr_t d = new mpfr_t(100UL);
            AsString       = d.ToString();
            Assert.AreEqual("1E+2", AsString);

            using mpfr_t e = new mpfr_t(-100L);
            AsString       = e.ToString();
            Assert.AreEqual("-1E+2", AsString);

            using mpfr_t f = new mpfr_t(100U);
            AsString       = f.ToString();
            Assert.AreEqual("1E+2", AsString);

            using mpfr_t g = new mpfr_t(200.1F);
            AsString       = g.ToString();
            Assert.AreEqual("2.00100006103515625E+2", AsString);

            using mpfr_t h = new mpfr_t(-200.1);
            AsString       = h.ToString();
            Assert.AreEqual("-2.00099999999999994315658113919198513031005859375E+2", AsString);

            using mpz_t iz = new mpz_t("10123456789ABCDEF0123456789ABCDEF0123456789ABCDEF", 16);
            AsString       = iz.ToString(16).ToUpper();
            Assert.AreEqual("10123456789ABCDEF0123456789ABCDEF0123456789ABCDEF", AsString);

            using mpfr_t i = new mpfr_t(iz);
            AsString       = i.ToString();
            Assert.AreEqual("6.3049999653217328579866181421408313514338742205512312E+57", AsString);

            using mpq_t jq = new mpq_t("222509832503450298345029835740293845720/115756986668303657898962467957");
            AsString       = jq.ToString();
            Assert.AreEqual("222509832503450298345029835740293845720/115756986668303657898962467957", AsString);

            using mpfr_t j = new mpfr_t(jq);
            AsString       = j.ToString();
            Assert.AreEqual("1.9222151414587357044219970703125E+9", AsString);

            using mpf_t kf = new mpf_t("22250983250345029834502983.5740293845720");
            AsString       = kf.ToString();
            Assert.AreEqual("2.22509832503450298345E+25", AsString);

            using mpfr_t k = new mpfr_t(kf);
            AsString       = k.ToString();
            Assert.AreEqual("2.225098325034502799228928E+25", AsString);

            using mpfr_t l = new mpfr_t("22250983250345029834502983.5740293845720");
            AsString       = l.ToString();
            Assert.AreEqual("2.225098325034502799228928E+25", AsString);
        }