예제 #1
0
        private static T GreatestCommonDivisor <T>(T one, T two, IArithmetic <T> arithmetic)
        {
            T big       = arithmetic.Max(arithmetic.Abs(one), arithmetic.Abs(two));
            T small     = arithmetic.Min(arithmetic.Abs(one), arithmetic.Abs(two));
            T remainder = arithmetic.Modulo(big, small);

            return(arithmetic.Equals(remainder, arithmetic.Zero) ? small : AdvancedMath.GreatestCommonDivisor(small, remainder, arithmetic));
        }
예제 #2
0
 /// <summary>
 /// Finds the greatest common divisor of two numbers.
 /// The greatest common divisor is the largest positive integer that divides the numbers without a remainder.
 /// </summary>
 /// <param name="one">The one.</param>
 /// <param name="two">The two.</param>
 /// <returns>The greatest common divisor of the two numbers.</returns>
 public static sbyte GreatestCommonDivisor(sbyte one, sbyte two)
 {
     return(AdvancedMath.GreatestCommonDivisor(one, two, Arithmetics.SByte));
 }
예제 #3
0
 /// <summary>
 /// Finds the greatest common divisor of two numbers.
 /// The greatest common divisor is the largest positive integer that divides the numbers without a remainder.
 /// </summary>
 /// <param name="one">The one.</param>
 /// <param name="two">The two.</param>
 /// <returns>The greatest common divisor of the two numbers.</returns>
 public static long GreatestCommonDivisor(long one, long two)
 {
     return(AdvancedMath.GreatestCommonDivisor(one, two, Arithmetics.Int64));
 }
예제 #4
0
 /// <summary>
 /// Finds the greatest common divisor of two numbers.
 /// The greatest common divisor is the largest positive integer that divides the numbers without a remainder.
 /// </summary>
 /// <param name="one">The one.</param>
 /// <param name="two">The two.</param>
 /// <returns>The greatest common divisor of the two numbers.</returns>
 public static int GreatestCommonDivisor(int one, int two)
 {
     return(AdvancedMath.GreatestCommonDivisor(one, two, Arithmetics.Int32));
 }
예제 #5
0
 /// <summary>
 /// Finds the greatest common divisor of two numbers.
 /// The greatest common divisor is the largest positive integer that divides the numbers without a remainder.
 /// </summary>
 /// <param name="one">The one.</param>
 /// <param name="two">The two.</param>
 /// <returns>The greatest common divisor of the two numbers.</returns>
 public static short GreatestCommonDivisor(short one, short two)
 {
     return(AdvancedMath.GreatestCommonDivisor(one, two, Arithmetics.Int16));
 }
예제 #6
0
 /// <summary>
 /// Finds the greatest common divisor of two numbers.
 /// The greatest common divisor is the largest positive integer that divides the numbers without a remainder.
 /// </summary>
 /// <param name="one">The one.</param>
 /// <param name="two">The two.</param>
 /// <returns>The greatest common divisor of the two numbers.</returns>
 public static double GreatestCommonDivisor(double one, double two)
 {
     return(AdvancedMath.GreatestCommonDivisor(one, two, Arithmetics.Double));
 }
예제 #7
0
 /// <summary>
 /// Finds the greatest common divisor of two numbers.
 /// The greatest common divisor is the largest positive integer that divides the numbers without a remainder.
 /// </summary>
 /// <param name="one">The one.</param>
 /// <param name="two">The two.</param>
 /// <returns>The greatest common divisor of the two numbers.</returns>
 public static decimal GreatestCommonDivisor(decimal one, decimal two)
 {
     return(AdvancedMath.GreatestCommonDivisor(one, two, Arithmetics.Decimal));
 }
예제 #8
0
 private static T LeastCommonMultiple <T>(T one, T two, IArithmetic <T> arithmetic)
 {
     return(arithmetic.Divide(arithmetic.Abs(arithmetic.Multiply(one, two)), AdvancedMath.GreatestCommonDivisor(one, two, arithmetic)));
 }
예제 #9
0
 /// <summary>
 /// Finds the least common multiple of two numbers.
 /// The least common multiple is the largest positive integer that divides the numbers without a remainder.
 /// </summary>
 /// <param name="one">The one.</param>
 /// <param name="two">The two.</param>
 /// <returns>The least common multiple of the two numbers.</returns>
 public static ulong LeastCommonMultiple(ulong one, ulong two)
 {
     return(AdvancedMath.LeastCommonMultiple(one, two, Arithmetics.UInt64));
 }
예제 #10
0
 /// <summary>
 /// Finds the least common multiple of two numbers.
 /// The least common multiple is the largest positive integer that divides the numbers without a remainder.
 /// </summary>
 /// <param name="one">The one.</param>
 /// <param name="two">The two.</param>
 /// <returns>The least common multiple of the two numbers.</returns>
 public static uint LeastCommonMultiple(uint one, uint two)
 {
     return(AdvancedMath.LeastCommonMultiple(one, two, Arithmetics.UInt32));
 }
예제 #11
0
 /// <summary>
 /// Finds the least common multiple of two numbers.
 /// The least common multiple is the largest positive integer that divides the numbers without a remainder.
 /// </summary>
 /// <param name="one">The one.</param>
 /// <param name="two">The two.</param>
 /// <returns>The least common multiple of the two numbers.</returns>
 public static ushort LeastCommonMultiple(ushort one, ushort two)
 {
     return(AdvancedMath.LeastCommonMultiple(one, two, Arithmetics.UInt16));
 }
예제 #12
0
 /// <summary>
 /// Finds the least common multiple of two numbers.
 /// The least common multiple is the largest positive integer that divides the numbers without a remainder.
 /// </summary>
 /// <param name="one">The one.</param>
 /// <param name="two">The two.</param>
 /// <returns>The least common multiple of the two numbers.</returns>
 public static float LeastCommonMultiple(float one, float two)
 {
     return(AdvancedMath.LeastCommonMultiple(one, two, Arithmetics.Single));
 }
예제 #13
0
 /// <summary>
 /// Finds the least common multiple of two numbers.
 /// The least common multiple is the largest positive integer that divides the numbers without a remainder.
 /// </summary>
 /// <param name="one">The one.</param>
 /// <param name="two">The two.</param>
 /// <returns>The least common multiple of the two numbers.</returns>
 public static sbyte LeastCommonMultiple(sbyte one, sbyte two)
 {
     return(AdvancedMath.LeastCommonMultiple(one, two, Arithmetics.SByte));
 }
예제 #14
0
 /// <summary>
 /// Finds the least common multiple of two numbers.
 /// The least common multiple is the largest positive integer that divides the numbers without a remainder.
 /// </summary>
 /// <param name="one">The one.</param>
 /// <param name="two">The two.</param>
 /// <returns>The least common multiple of the two numbers.</returns>
 public static double LeastCommonMultiple(double one, double two)
 {
     return(AdvancedMath.LeastCommonMultiple(one, two, Arithmetics.Double));
 }
예제 #15
0
 /// <summary>
 /// Finds the least common multiple of two numbers.
 /// The least common multiple is the largest positive integer that divides the numbers without a remainder.
 /// </summary>
 /// <param name="one">The one.</param>
 /// <param name="two">The two.</param>
 /// <returns>The least common multiple of the two numbers.</returns>
 public static decimal LeastCommonMultiple(decimal one, decimal two)
 {
     return(AdvancedMath.LeastCommonMultiple(one, two, Arithmetics.Decimal));
 }
예제 #16
0
 /// <summary>
 /// Finds the greatest common divisor of two numbers.
 /// The greatest common divisor is the largest positive integer that divides the numbers without a remainder.
 /// </summary>
 /// <param name="one">The one.</param>
 /// <param name="two">The two.</param>
 /// <returns>The greatest common divisor of the two numbers.</returns>
 public static float GreatestCommonDivisor(float one, float two)
 {
     return(AdvancedMath.GreatestCommonDivisor(one, two, Arithmetics.Single));
 }