mirror of
https://github.com/oliverbooth/X10D
synced 2024-11-09 23:25:43 +00:00
Compare commits
2 Commits
eb46257b75
...
3e0853d102
Author | SHA1 | Date | |
---|---|---|---|
3e0853d102 | |||
30f158e861 |
@ -48,5 +48,54 @@ public static class BinaryIntegerExtensions
|
||||
TInteger root = TInteger.Abs(value).Mod(nine);
|
||||
return int.CreateChecked(root == TInteger.Zero ? nine : root);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the factorial of the current binary integer.
|
||||
/// </summary>
|
||||
/// <param name="value">The value whose factorial to compute.</param>
|
||||
/// <returns>The factorial of <paramref name="value" />.</returns>
|
||||
/// <exception cref="ArithmeticException"><paramref name="value" /> is less than 0.</exception>
|
||||
[Pure]
|
||||
[MethodImpl(CompilerResources.MaxOptimization)]
|
||||
public static long Factorial<TInteger>(this TInteger value)
|
||||
where TInteger : IBinaryInteger<TInteger>
|
||||
{
|
||||
if (value < TInteger.Zero)
|
||||
{
|
||||
throw new ArithmeticException(nameof(value));
|
||||
}
|
||||
|
||||
if (value == TInteger.Zero)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
var result = 1L;
|
||||
for (TInteger i = TInteger.One; i <= value; i++)
|
||||
{
|
||||
result *= long.CreateChecked(i);
|
||||
}
|
||||
|
||||
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
|
||||
|
@ -42,7 +42,6 @@ public static class ByteExtensions
|
||||
int root = value % 9;
|
||||
return (byte)(root == 0 ? 9 : root);
|
||||
}
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// Returns the factorial of the current 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.
|
||||
|
@ -41,7 +41,6 @@ public static class Int16Extensions
|
||||
short root = System.Math.Abs(value).Mod(9);
|
||||
return root < 1 ? (short)(9 - root) : root;
|
||||
}
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// Returns the factorial of the current 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.
|
||||
|
@ -41,7 +41,6 @@ public static class Int32Extensions
|
||||
int root = System.Math.Abs(value).Mod(9);
|
||||
return root < 1 ? 9 - root : root;
|
||||
}
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// Returns the factorial of the current 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.
|
||||
|
@ -41,7 +41,6 @@ public static class Int64Extensions
|
||||
long root = System.Math.Abs(value).Mod(9L);
|
||||
return root < 1L ? 9L - root : root;
|
||||
}
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// Returns the factorial of the current 64-bit signed 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.
|
||||
|
@ -42,7 +42,6 @@ public static class SByteExtensions
|
||||
int root = System.Math.Abs(value).Mod(9);
|
||||
return (sbyte)(root < 1 ? 9 - root : root);
|
||||
}
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// Returns the factorial of the current 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.
|
||||
|
@ -42,7 +42,6 @@ public static class UInt16Extensions
|
||||
var root = (ushort)(value % 9);
|
||||
return (ushort)(root == 0 ? 9 : root);
|
||||
}
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// Returns the factorial of the current 16-bit unsigned integer.
|
||||
@ -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.
|
||||
|
@ -42,7 +42,6 @@ public static class UInt32Extensions
|
||||
uint root = value % 9;
|
||||
return root == 0 ? 9 : root;
|
||||
}
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// Returns the factorial of the current 32-bit unsigned integer.
|
||||
@ -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.
|
||||
|
@ -42,7 +42,6 @@ public static class UInt64Extensions
|
||||
ulong root = value % 9;
|
||||
return root == 0 ? 9 : root;
|
||||
}
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// Returns the factorial of the current 64-bit unsigned integer.
|
||||
@ -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.
|
||||
|
Loading…
Reference in New Issue
Block a user