Skip to content
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

Cast one of the operands of this addition operation to a "long". #5883

Closed
MinaQin opened this issue May 12, 2022 · 1 comment · Fixed by #5889
Closed

Cast one of the operands of this addition operation to a "long". #5883

MinaQin opened this issue May 12, 2022 · 1 comment · Fixed by #5889

Comments

@MinaQin
Copy link
Contributor

MinaQin commented May 12, 2022

Code Path:consensus/src/main/java/org/apache/iotdb/consensus/ratis/Utils.java
image
When arithmetic is performed on integers, the result will always be an integer. You can assign that result to a long, double, or float with automatic type conversion, but having started as an int or long, the result will likely not be what you expect.

For instance, if the result of int division is assigned to a floating-point variable, precision will have been lost before the assignment. Likewise, if the result of multiplication is assigned to a long, it may have already overflowed before the assignment.

In either case, the result will not be what was expected. Instead, at least one operand should be cast or promoted to the final type before the operation takes place.

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

Successfully merging a pull request may close this issue.

3 participants