Testing for exceeding the limits of a long
Posted on 2005-05-03
I am in a situation where I can not use unsigned long or any other variable type.
I must use long.
My problem is that I ran into a situation where I may have two extremly large long values that need to be added together with the result put into another long variable.
long x = 1178610030
long y = 1115152266
x + y = ?
I think a long has a limit of 2147483647 so if I add x + y my results are not what I should expect.
I actually get a negative number. This means I can't check to see if the result is larger than the limit of a long type.
Is there an easy way to check to see if the sum is larger than the limit of a long?