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.

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.

nice logic thanks.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.