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

BackpressureUtils capped add/multiply methods + tests #3177

Merged
merged 1 commit into from Aug 24, 2015

Conversation

akarnokd
Copy link
Member

Common methods to add and multiply longs and cap the result at Long.MAX_VALUE in case of an overflow.

*/
public static long addCap(long a, long b) {
long u = a + b;
if (u < 0L) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this negative check necessary? long has 2^63 -1 capacity and let's assume that we will accumulate 10^9 every second we would still need 106 752 days to overflow (roughly 292 years).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, because negative requests are not allowed and two large longs can overflow to a negative value.

akarnokd added a commit that referenced this pull request Aug 24, 2015
BackpressureUtils capped add/multiply methods + tests
@akarnokd akarnokd merged commit 7a77072 into ReactiveX:1.x Aug 24, 2015
@akarnokd akarnokd deleted the BackpressureUtilsExtra branch September 9, 2015 15:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants