diff --git a/X10D/src/Math/BinaryIntegerExtensions.cs b/X10D/src/Math/BinaryIntegerExtensions.cs index 786c52a..ce10a7e 100644 --- a/X10D/src/Math/BinaryIntegerExtensions.cs +++ b/X10D/src/Math/BinaryIntegerExtensions.cs @@ -78,5 +78,24 @@ public static class BinaryIntegerExtensions return result; } + + /// + /// Calculates the greatest common factor between the current binary integer, and another binary integer. + /// + /// The first value. + /// The second value. + /// The greatest common factor between and . + [Pure] + [MethodImpl(CompilerResources.MaxOptimization)] + public static TInteger GreatestCommonFactor(this TInteger value, TInteger other) + where TInteger : IBinaryInteger + { + while (other != TInteger.Zero) + { + (value, other) = (other, value % other); + } + + return value; + } } #endif diff --git a/X10D/src/Math/ByteExtensions.cs b/X10D/src/Math/ByteExtensions.cs index 157994e..f6a0007 100644 --- a/X10D/src/Math/ByteExtensions.cs +++ b/X10D/src/Math/ByteExtensions.cs @@ -65,7 +65,6 @@ public static class ByteExtensions return result; } -#endif /// /// Calculates the greatest common factor between the current 8-bit unsigned integer, and another 8-bit unsigned integer. @@ -79,6 +78,7 @@ public static class ByteExtensions { return (byte)((long)value).GreatestCommonFactor(other); } +#endif /// /// Returns a value indicating whether the current value is evenly divisible by 2. diff --git a/X10D/src/Math/Int16Extensions.cs b/X10D/src/Math/Int16Extensions.cs index 40d633f..2cf6494 100644 --- a/X10D/src/Math/Int16Extensions.cs +++ b/X10D/src/Math/Int16Extensions.cs @@ -70,7 +70,6 @@ public static class Int16Extensions return result; } -#endif /// /// Calculates the greatest common factor between the current 16-bit signed integer, and another 16-bit signed integer. @@ -84,6 +83,7 @@ public static class Int16Extensions { return (short)((long)value).GreatestCommonFactor(other); } +#endif /// /// Returns a value indicating whether the current value is evenly divisible by 2. diff --git a/X10D/src/Math/Int32Extensions.cs b/X10D/src/Math/Int32Extensions.cs index 3d2c858..bc59f55 100644 --- a/X10D/src/Math/Int32Extensions.cs +++ b/X10D/src/Math/Int32Extensions.cs @@ -70,7 +70,6 @@ public static class Int32Extensions return result; } -#endif /// /// Calculates the greatest common factor between the current 32-bit signed integer, and another 32-bit signed integer. @@ -84,6 +83,7 @@ public static class Int32Extensions { return (int)((long)value).GreatestCommonFactor(other); } +#endif /// /// Returns a value indicating whether the current value is evenly divisible by 2. diff --git a/X10D/src/Math/Int64Extensions.cs b/X10D/src/Math/Int64Extensions.cs index 0dcc43f..4153174 100644 --- a/X10D/src/Math/Int64Extensions.cs +++ b/X10D/src/Math/Int64Extensions.cs @@ -70,7 +70,6 @@ public static class Int64Extensions return result; } -#endif /// /// Calculates the greatest common factor between the current 64-bit signed integer, and another 64-bit unsigned integer. @@ -89,6 +88,7 @@ public static class Int64Extensions return value; } +#endif /// /// Returns a value indicating whether the current value is evenly divisible by 2. diff --git a/X10D/src/Math/SByteExtensions.cs b/X10D/src/Math/SByteExtensions.cs index 17e536b..ae5c63b 100644 --- a/X10D/src/Math/SByteExtensions.cs +++ b/X10D/src/Math/SByteExtensions.cs @@ -71,7 +71,6 @@ public static class SByteExtensions return result; } -#endif /// /// Calculates the greatest common factor between the current 8-bit signed integer, and another 8-bit signed integer. @@ -85,6 +84,7 @@ public static class SByteExtensions { return (sbyte)((long)value).GreatestCommonFactor(other); } +#endif /// /// Returns a value indicating whether the current value is evenly divisible by 2. diff --git a/X10D/src/Math/UInt16Extensions.cs b/X10D/src/Math/UInt16Extensions.cs index 090808a..9db0e10 100644 --- a/X10D/src/Math/UInt16Extensions.cs +++ b/X10D/src/Math/UInt16Extensions.cs @@ -65,7 +65,6 @@ public static class UInt16Extensions return result; } -#endif /// /// Calculates the greatest common factor between the current 16-bit unsigned integer, and another 16-bit unsigned @@ -80,6 +79,7 @@ public static class UInt16Extensions { return (ushort)((long)value).GreatestCommonFactor(other); } +#endif /// /// Returns a value indicating whether the current value is evenly divisible by 2. diff --git a/X10D/src/Math/UInt32Extensions.cs b/X10D/src/Math/UInt32Extensions.cs index 700e32b..d57fad3 100644 --- a/X10D/src/Math/UInt32Extensions.cs +++ b/X10D/src/Math/UInt32Extensions.cs @@ -65,7 +65,6 @@ public static class UInt32Extensions return result; } -#endif /// /// Calculates the greatest common factor between the current 32-bit unsigned integer, and another 32-bit unsigned @@ -80,6 +79,7 @@ public static class UInt32Extensions { return (uint)((long)value).GreatestCommonFactor(other); } +#endif /// /// Returns a value indicating whether the current value is evenly divisible by 2. diff --git a/X10D/src/Math/UInt64Extensions.cs b/X10D/src/Math/UInt64Extensions.cs index 3353ab9..890d703 100644 --- a/X10D/src/Math/UInt64Extensions.cs +++ b/X10D/src/Math/UInt64Extensions.cs @@ -65,7 +65,6 @@ public static class UInt64Extensions return result; } -#endif /// /// Calculates the greatest common factor between the current 64-bit unsigned integer, and another 64-bit unsigned @@ -85,6 +84,7 @@ public static class UInt64Extensions return value; } +#endif /// /// Returns a value indicating whether the current value is evenly divisible by 2.