-
Notifications
You must be signed in to change notification settings - Fork 231
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
SE: Improve arithmetic handling in loops #8695
Comments
Addition: What about positive+negative? Is that intended to implicitly fall back to "we don't know" scenario? |
We should be able to do multiplication for negative*negative too? |
Why do the multiplication and division needs to work with constants only, and not positive/negative? |
@pavel-mikula-sonarsource
|
That's the gap I'm asking about. If we do it with number (not constants) and we know if they are positive/negative, we never flip the signage. |
We don't, because we don't know what the result will be assigned to:
|
Follow-up to #8474
Specification
Currently, the SE engine is not conducting any calculations for arithmetic operations in loops. The following assumptions are approximations for calculations in a loop and can be added one by one:
positive + positive
=>[left.Min + right.Min, null]
negative + negative
=>[null, left.Max + right.Max]
(partial implementation exists but does not handle 0)number + positive constant
=>[left.Min + right, null]
number + negative constant
=>[null, left.Max + right]
number + 0 constant
=>[left.Min, left.Max]
number - positive constant
=>[null, left.Max - right]
number - negative constant
=>[left.Min - right, null]
number - 0 constant
=>[left.Min, left.Max]
number * 0
=>[0, 0]
positive * positive
=>[left.Min * right.Min, null]
negative * positive constant
=>[null, left.Max * right]
positive / positive constant
=>[0, left.Max / right]
negative / positive constant
=>[left.Min / right, 0]
number / positive constant
=>[-left.Min / right, left.Max / right]
number / negative constant
=>[Max(|left.Min|, |left.Max|) / right, Max(|left.Min|, |left.Max|) / -right]
number % constant
=> same logic as outside a loopnumber & number
=> same logic as outside a loopnumber | number
=> same logic as outside a loopnumber ^ 0 constant
=>[left.Min, left.Max]
positive ^ positive
=>[0, null]
negative ^ positive constant
=>[null, -1]
The text was updated successfully, but these errors were encountered: