Skip to content

Guard factorial calculation against overflow - #1

Open
Gorkem-Taha wants to merge 1 commit into
iemirakman:mainfrom
Gorkem-Taha:fix/factorial-overflow
Open

Gorkem-Taha wants to merge 1 commit into
iemirakman:mainfrom
Gorkem-Taha:fix/factorial-overflow

Conversation

@Gorkem-Taha

Copy link
Copy Markdown

Summary

  • Check multiplication against long long limits before updating the factorial result.
  • Report when the input is negative or its factorial cannot fit in long long.

Verification

  • Built with g++ -std=c++17 -Wall -Wextra -Werror.
  • Checked factorial results for -1, 0, 20, 21, and 100 with a focused C++ harness.
  • Ran the CLI with input 21 and confirmed it reports the out-of-range result.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant