Hi
I am building a unit convertor program that uses the MathFP library. Typically unit conversion occurs in the formula of:
U1 (unit1) * K (constant) = U2 (unit2)
I want to be able to detect when the an int has over/underflowed? How can I detect when this has occured and gracefully handle the problem. Ideally I would be looking for a generic solution, as I would want to handle overflow with primitives of type long:
The only idea I have is:
int largeOne = bigNum;
int largeTwo = anotherbigNum;
//complete math operation
long l = largeOne * largeTwo;
if(l > Integer.MAX_SIZE){
System.out.println("Overflow");
//handle error
}
Should I be using a different primitive data type for these conversions, such as double?
Thanks in advance for your help