forked from abacusmodeling/abacus-develop
-
Notifications
You must be signed in to change notification settings - Fork 189
2026 PKUCourseHW5: more precise log for Fcoef::create #7126
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,18 +27,19 @@ void Fcoef::create(const int i1, const int i2, const int i3) | |
| } | ||
| else | ||
| { | ||
| std::cout << "not allowed!" << std::endl; | ||
| std::cout << "Fcoef::create: not allowed!" << std::endl; | ||
| if (!(i1 * i2 * i3 > 0)){ | ||
| std::cout << "i1*i2*i3 must be positive! i1*i2*i3 is " << i1 * i2 * i3 << std::endl; | ||
| unsigned long long product = static_cast<unsigned long long>(i1) * static_cast<unsigned long long>(i2) * static_cast<unsigned long long>(i3); | ||
| std::cout << "Fcoef::create: possible integer overflow in product i1*i2*i3! i1 is " << i1 << ", i2 is " << i2 << ", i3 is " << i3 << ", product is " << product << std::endl; | ||
| } | ||
| if (!(i1 > 0)){ | ||
| std::cout << "i1 must be positive! i1 is " << i1 << std::endl; | ||
| std::cout << "Fcoef::create: i1 must be positive! i1 is " << i1 << std::endl; | ||
| } | ||
| if (!(i2 > 0)){ | ||
| std::cout << "i2 must be positive! i2 is " << i2 << std::endl; | ||
| std::cout << "Fcoef::create: i2 must be positive! i2 is " << i2 << std::endl; | ||
| } | ||
| if (!(i3 > 0)){ | ||
| std::cout << "i3 must be positive! i3 is " << i3 << std::endl; | ||
| std::cout << "Fcoef::create: i3 must be positive! i3 is " << i3 << std::endl; | ||
|
Comment on lines
+30
to
+42
|
||
| } | ||
|
|
||
| } | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The condition
i1 * i2 * i3 > 0can itself trigger signed integer overflow (undefined behavior) before you get to the diagnostic, which defeats the purpose of detecting overflow. Also, casting negativeintvalues tounsigned long longwill produce very large values, so the printedproductcan be misleading when the real problem is simply a negative input. A safer approach is to checki1/i2/i3positivity without multiplying, and only compute a product using a wide signed type (e.g.,long long/__int128) after confirming all are positive (or perform overflow-checked multiplication).