Exemple #1
0
        public FactoredRational(int n)
        {
            var vv = new int[11];

            for (int jj = 0; jj <= 10; jj++)
            {
                vv[jj] = Power(2, jj);
            }

            Sign = Math.Sign((decimal)n);
            n   *= Sign;

            K = new List <int>();
            int i = 0;

            while (n > 1)
            {
                K.Add(0);
                var p = PrimeNumbers.Get(i);
                while (n % p == 0)
                {
                    K[i]++;
                    n /= p;
                }

                i++;
            }
        }
Exemple #2
0
        public void ToRational(out int top, out int bottom)
        {
            if (K == null || Sign == 0)
            {
                top    = 0;
                bottom = 1;
                return;
            }

            top    = Sign;
            bottom = 1;
            for (int i = 0; i < K.Count; i++)
            {
                if (K[i] > 0)
                {
                    top *= Power(PrimeNumbers.Get(i), K[i]);
                }
                else
                {
                    bottom *= Power(PrimeNumbers.Get(i), -K[i]);
                }
            }
        }