Skip to content

Commit

Permalink
refactor: fix logic for IBinaryInteger<T>.Factorial
Browse files Browse the repository at this point in the history
The algorithm now starts at IBinaryInteger<T>.MultiplicativeIdentity rather than IBinaryInteger<T>.One
  • Loading branch information
oliverbooth committed Nov 14, 2024
1 parent 024f6db commit c7e78f5
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed

- X1OD: `IBinaryInteger<T>.Factorial` now starts at `IBinaryInteger<T>.MultiplicativeIdentity` not
`IBinaryInteger<T>.One`.
- X10D: Removed `byte.Product`, `short.Product`, `ushort.Product`, `int.Product`, `uint.Product`, `long.Product`,
and `ulong.Product`, in favour of `INumber<T>.Product`.
- X10D: Removed `byte.RangeTo`, `short.RangeTo`, `ushort.RangeTo`, `int.RangeTo`, `uint.RangeTo`, `long.RangeTo`,
Expand Down
6 changes: 3 additions & 3 deletions X10D/src/Math/BinaryIntegerExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,13 @@ public static long Factorial<TInteger>(this TInteger value)
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);
}

/// <summary>
Expand Down

0 comments on commit c7e78f5

Please sign in to comment.