I am coding a little calculator in C for my exam preparation. I understand that double is more precise than float since it has 11 bits reserved for the exponent and 53 bits for the significand. When it comes to integers, I can do the following to catch Over/underflows.
int sum(int a, int b, int *res){
if((b > 0) && (a > INT_MAX + b)){
return OVERFLOW_ERROR;
}
else if((b < 0) && (a < INT_MAX + b)){
return UNDERFLOW_ERROR;
}else {
*res = a + b;
}
return (EXIT_SUCCESS);
}
When it comes to double, if the number is too high, the console will give you "inf" or "-inf", which in any case isn´t too bad.
AFAIK, floating numbers overflow, when they lose precision
So, my question is, how do you handle the loss of precision? Can you make them "precise"? When do they lose precision?