diff --git a/X10D/src/Math/BinaryIntegerExtensions.cs b/X10D/src/Math/BinaryIntegerExtensions.cs
index 5b460c9..786c52a 100644
--- a/X10D/src/Math/BinaryIntegerExtensions.cs
+++ b/X10D/src/Math/BinaryIntegerExtensions.cs
@@ -48,5 +48,35 @@ public static class BinaryIntegerExtensions
TInteger root = TInteger.Abs(value).Mod(nine);
return int.CreateChecked(root == TInteger.Zero ? nine : root);
}
+
+ ///
+ /// Returns the factorial of the current binary integer.
+ ///
+ /// The value whose factorial to compute.
+ /// The factorial of .
+ /// is less than 0.
+ [Pure]
+ [MethodImpl(CompilerResources.MaxOptimization)]
+ public static long Factorial(this TInteger value)
+ where TInteger : IBinaryInteger
+ {
+ 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;
+ }
}
#endif
diff --git a/X10D/src/Math/ByteExtensions.cs b/X10D/src/Math/ByteExtensions.cs
index 500988d..157994e 100644
--- a/X10D/src/Math/ByteExtensions.cs
+++ b/X10D/src/Math/ByteExtensions.cs
@@ -42,7 +42,6 @@ public static class ByteExtensions
int root = value % 9;
return (byte)(root == 0 ? 9 : root);
}
-#endif
///
/// Returns the factorial of the current 8-bit unsigned integer.
@@ -66,6 +65,7 @@ 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.
diff --git a/X10D/src/Math/Int16Extensions.cs b/X10D/src/Math/Int16Extensions.cs
index dc3cf96..40d633f 100644
--- a/X10D/src/Math/Int16Extensions.cs
+++ b/X10D/src/Math/Int16Extensions.cs
@@ -41,7 +41,6 @@ public static class Int16Extensions
short root = System.Math.Abs(value).Mod(9);
return root < 1 ? (short)(9 - root) : root;
}
-#endif
///
/// Returns the factorial of the current 16-bit signed integer.
@@ -71,6 +70,7 @@ 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.
diff --git a/X10D/src/Math/Int32Extensions.cs b/X10D/src/Math/Int32Extensions.cs
index 7ed6535..3d2c858 100644
--- a/X10D/src/Math/Int32Extensions.cs
+++ b/X10D/src/Math/Int32Extensions.cs
@@ -41,7 +41,6 @@ public static class Int32Extensions
int root = System.Math.Abs(value).Mod(9);
return root < 1 ? 9 - root : root;
}
-#endif
///
/// Returns the factorial of the current 32-bit signed integer.
@@ -71,6 +70,7 @@ 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.
diff --git a/X10D/src/Math/Int64Extensions.cs b/X10D/src/Math/Int64Extensions.cs
index 64b94e0..0dcc43f 100644
--- a/X10D/src/Math/Int64Extensions.cs
+++ b/X10D/src/Math/Int64Extensions.cs
@@ -41,7 +41,6 @@ public static class Int64Extensions
long root = System.Math.Abs(value).Mod(9L);
return root < 1L ? 9L - root : root;
}
-#endif
///
/// Returns the factorial of the current 64-bit signed integer.
@@ -71,6 +70,7 @@ 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.
diff --git a/X10D/src/Math/SByteExtensions.cs b/X10D/src/Math/SByteExtensions.cs
index 00cfa04..17e536b 100644
--- a/X10D/src/Math/SByteExtensions.cs
+++ b/X10D/src/Math/SByteExtensions.cs
@@ -42,7 +42,6 @@ public static class SByteExtensions
int root = System.Math.Abs(value).Mod(9);
return (sbyte)(root < 1 ? 9 - root : root);
}
-#endif
///
/// Returns the factorial of the current 8-bit signed integer.
@@ -72,6 +71,7 @@ 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.
diff --git a/X10D/src/Math/UInt16Extensions.cs b/X10D/src/Math/UInt16Extensions.cs
index 8479cb2..090808a 100644
--- a/X10D/src/Math/UInt16Extensions.cs
+++ b/X10D/src/Math/UInt16Extensions.cs
@@ -42,7 +42,6 @@ public static class UInt16Extensions
var root = (ushort)(value % 9);
return (ushort)(root == 0 ? 9 : root);
}
-#endif
///
/// Returns the factorial of the current 16-bit unsigned integer.
@@ -66,6 +65,7 @@ public static class UInt16Extensions
return result;
}
+#endif
///
/// Calculates the greatest common factor between the current 16-bit unsigned integer, and another 16-bit unsigned
diff --git a/X10D/src/Math/UInt32Extensions.cs b/X10D/src/Math/UInt32Extensions.cs
index 6684e4f..700e32b 100644
--- a/X10D/src/Math/UInt32Extensions.cs
+++ b/X10D/src/Math/UInt32Extensions.cs
@@ -42,7 +42,6 @@ public static class UInt32Extensions
uint root = value % 9;
return root == 0 ? 9 : root;
}
-#endif
///
/// Returns the factorial of the current 32-bit unsigned integer.
@@ -66,6 +65,7 @@ public static class UInt32Extensions
return result;
}
+#endif
///
/// Calculates the greatest common factor between the current 32-bit unsigned integer, and another 32-bit unsigned
diff --git a/X10D/src/Math/UInt64Extensions.cs b/X10D/src/Math/UInt64Extensions.cs
index dc1e6f1..3353ab9 100644
--- a/X10D/src/Math/UInt64Extensions.cs
+++ b/X10D/src/Math/UInt64Extensions.cs
@@ -42,7 +42,6 @@ public static class UInt64Extensions
ulong root = value % 9;
return root == 0 ? 9 : root;
}
-#endif
///
/// Returns the factorial of the current 64-bit unsigned integer.
@@ -66,6 +65,7 @@ public static class UInt64Extensions
return result;
}
+#endif
///
/// Calculates the greatest common factor between the current 64-bit unsigned integer, and another 64-bit unsigned