From c7e78f5d195e0209871515c5332af2e1382f8cec Mon Sep 17 00:00:00 2001 From: Oliver Booth Date: Thu, 14 Nov 2024 16:06:52 +0000 Subject: [PATCH] refactor: fix logic for IBinaryInteger.Factorial The algorithm now starts at IBinaryInteger.MultiplicativeIdentity rather than IBinaryInteger.One --- CHANGELOG.md | 2 ++ X10D/src/Math/BinaryIntegerExtensions.cs | 6 +++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 08abffd..0d2a7ff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed +- X1OD: `IBinaryInteger.Factorial` now starts at `IBinaryInteger.MultiplicativeIdentity` not +`IBinaryInteger.One`. - X10D: Removed `byte.Product`, `short.Product`, `ushort.Product`, `int.Product`, `uint.Product`, `long.Product`, and `ulong.Product`, in favour of `INumber.Product`. - X10D: Removed `byte.RangeTo`, `short.RangeTo`, `ushort.RangeTo`, `int.RangeTo`, `uint.RangeTo`, `long.RangeTo`, diff --git a/X10D/src/Math/BinaryIntegerExtensions.cs b/X10D/src/Math/BinaryIntegerExtensions.cs index 2d09419..cce2bd1 100644 --- a/X10D/src/Math/BinaryIntegerExtensions.cs +++ b/X10D/src/Math/BinaryIntegerExtensions.cs @@ -69,13 +69,13 @@ public static class BinaryIntegerExtensions return 1; } - var result = 1L; + TInteger result = TInteger.MultiplicativeIdentity; for (TInteger i = TInteger.One; i <= value; i++) { - result *= long.CreateChecked(i); + result *= i; } - return result; + return long.CreateChecked(result); } ///