Beispiel #1
0
        /**
         * Returns the greatest common divider of
         * two TRNs, ignoring signs (Unsigned GCD).
         * Uses euclid's algorithm
         *
         * @return GCD
         */
        public static TruncatableRealNumber gcd(TruncatableRealNumber one, TruncatableRealNumber two)
        {
            TruncatableRealNumber zero = new TruncatableRealNumber(0);
            TruncatableRealNumber u = new TruncatableRealNumber(one).getAbs();
            TruncatableRealNumber v = new TruncatableRealNumber(two).getAbs();
            TruncatableRealNumber temp = null;

            //		System.Console.WriteLine("GCD( " + one + " , " + two + " ) ");
            do
            {
                if (u < v)
                {
                    temp = u;
                    u = v;
                    v = temp;
                }

                u = u.getDifference(v);

            }
            while (u != zero);

            return v;
        }
Beispiel #2
0
 public static TruncatableRealNumber lcm(TruncatableRealNumber one, TruncatableRealNumber two)
 {
     return one.getAbs().getProduct(two.getAbs()).getQuotient( LSMath.gcd(one, two) );
 }