0

Sorry if this is repetative but still struggling with this.

i wish to multiply 2 long integers together.

if the result is outside of int64 range i want the loop to break
otherwise i want to keep the result and increment the second number.

have tested this, but when the result is out of range it returns a garbage value.
is there any way of making this result 0 for example when this is the case.

thanks.

2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by frogboy77
1

I would say it isn't garbage but a wrap around of the variable, what you can do is to take the maximum integer your variable can hold. (should be in std::numeric limits) and divide the maximum integer number by your first int. this is basically saying how many times can i multiply this int and it will fit into the 64bit integer. If the result of that operation is smaller than your second int the multiplication will be out of range.

Hope this helps.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.