As already mentioned, you will not have a problem with subtraction, so if thatโs all you are trying to do, then donโt worry.
But, for example, the addition will overflow, and not one of the relational operators will work properly. If this is a concern, you can write your own relational operating systems or use a better window type than Long.
Solutions: 1. Use BigInteger instead of Long. BigInteger was created to perform calculations with large numbers and can easily support 128-bit calculations.
- Write your own relational operations and eliminate the possibility of using addition or multiplication. Writing your own relational operator is really not that difficult. First you compare the most significant bit. If the most significant bit is the same for both numbers, you can hide it by doing bitwise and (&) with 0X7FFFFFFFFFFFFFFFFF, and then compare the masked values.
source share