-
Notifications
You must be signed in to change notification settings - Fork 409
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
expression: check Overflow int128 #4762
Conversation
[REVIEW NOTIFICATION] This pull request has been approved by:
To complete the pull request process, please ask the reviewers in the list to review by filling The full list of commands accepted by this bot can be found here. Reviewer can indicate their review by submitting an approval review. |
consider port https://github.com/ClickHouse/ClickHouse/blob/master/base/base/arithmeticOverflow.h to TiFlash? |
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.
It'll be nice to explain why muloverflow affects comparasion result.
https://github.com/ClickHouse/ClickHouse/blob/master/base/base/arithmeticOverflow.h#L179 but here needs to checkout overflow. |
a git positive value becomes negective, so the compare resultes are wrong. |
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.
LGTM
unsigned __int128 a = (x > 0) ? x : -x; | ||
unsigned __int128 b = (y > 0) ? y : -y; | ||
return (a * b) / b != a; | ||
return res/x != y; /// whether overflow int128 |
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.
How about add some unit test for this overflow check?
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.
added
/// 2^254 << 1 = 2^255 | ||
is_overflow = common::mulOverflow(int_254, Int256(2), res256); | ||
ASSERT_EQ(is_overflow, true); |
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.
@LittleFall is this as expected?
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.
I think it is expected, the max limit of signed Int256 is (1<<255)-1
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.
According to the boost doc and implement, the Int256
in boost includes 256bit data and 1bit sign, so the max/min value is different from our expectation.
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.
after discussion, this won't affect our current logic. the unexpected common::mulOverflow
only has one caller https://github.com/pingcap/tiflash/blob/master/dbms/src/Core/DecimalComparison.h#L153-L169, and it won't break too.
by the way, we need some comments on this function.
@@ -129,6 +127,6 @@ inline bool mulOverflow(Int256 x, Int256 y, Int256 & res) | |||
{ | |||
return true; | |||
} | |||
return false; | |||
return res >= Int256((Int256(0x1) << 255)); /// whether overflow int256 |
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.
Why need add this?
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.
Why need add this?
please see https://github.com/pingcap/tiflash/pull/4762/files#r873432216
/merge |
@fzhedu: It seems you want to merge this PR, I will help you trigger all the tests: /run-all-tests You only need to trigger If you have any questions about the PR merge process, please refer to pr process. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the ti-community-infra/tichi repository. |
This pull request has been accepted and is ready to merge. Commit hash: d688bb8
|
Coverage for changed files
Coverage summary
full coverage report (for internal network access only) |
Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
In response to a cherrypick label: new pull request created: #4942. |
In response to a cherrypick label: new pull request created: #4943. |
In response to a cherrypick label: new pull request created: #4944. |
Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
In response to a cherrypick label: new pull request created: #4945. |
Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
In response to a cherrypick label: new pull request created: #4946. |
Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
In response to a cherrypick label: new pull request created: #4947. |
What problem does this PR solve?
Issue Number: close #4512
Problem Summary:
What is changed and how it works?
Check List
Tests
Side effects
Documentation
Release note