refactor!: move GCF to BinaryIntegerExtensions for .net>=7

This commit is contained in:
Oliver Booth 2024-02-17 18:17:12 +00:00
parent 30f158e861
commit 3e0853d102
Signed by: oliverbooth
GPG Key ID: E60B570D1B7557B5
9 changed files with 27 additions and 8 deletions

View File

@ -78,5 +78,24 @@ public static class BinaryIntegerExtensions
return result;
}
/// <summary>
/// Calculates the greatest common factor between the current binary integer, and another binary integer.
/// </summary>
/// <param name="value">The first value.</param>
/// <param name="other">The second value.</param>
/// <returns>The greatest common factor between <paramref name="value" /> and <paramref name="other" />.</returns>
[Pure]
[MethodImpl(CompilerResources.MaxOptimization)]
public static TInteger GreatestCommonFactor<TInteger>(this TInteger value, TInteger other)
where TInteger : IBinaryInteger<TInteger>
{
while (other != TInteger.Zero)
{
(value, other) = (other, value % other);
}
return value;
}
}
#endif

View File

@ -65,7 +65,6 @@ public static class ByteExtensions
return result;
}
#endif
/// <summary>
/// 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
/// <summary>
/// Returns a value indicating whether the current value is evenly divisible by 2.

View File

@ -70,7 +70,6 @@ public static class Int16Extensions
return result;
}
#endif
/// <summary>
/// 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
/// <summary>
/// Returns a value indicating whether the current value is evenly divisible by 2.

View File

@ -70,7 +70,6 @@ public static class Int32Extensions
return result;
}
#endif
/// <summary>
/// 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
/// <summary>
/// Returns a value indicating whether the current value is evenly divisible by 2.

View File

@ -70,7 +70,6 @@ public static class Int64Extensions
return result;
}
#endif
/// <summary>
/// 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
/// <summary>
/// Returns a value indicating whether the current value is evenly divisible by 2.

View File

@ -71,7 +71,6 @@ public static class SByteExtensions
return result;
}
#endif
/// <summary>
/// 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
/// <summary>
/// Returns a value indicating whether the current value is evenly divisible by 2.

View File

@ -65,7 +65,6 @@ public static class UInt16Extensions
return result;
}
#endif
/// <summary>
/// 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
/// <summary>
/// Returns a value indicating whether the current value is evenly divisible by 2.

View File

@ -65,7 +65,6 @@ public static class UInt32Extensions
return result;
}
#endif
/// <summary>
/// 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
/// <summary>
/// Returns a value indicating whether the current value is evenly divisible by 2.

View File

@ -65,7 +65,6 @@ public static class UInt64Extensions
return result;
}
#endif
/// <summary>
/// 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
/// <summary>
/// Returns a value indicating whether the current value is evenly divisible by 2.