I need to write program that will take two float values a and b from the user and multiply them and keep it in variable let's be c, if overflow occurs send signal. Then take product c and multiply it by 1 billion, then check again if overflow occurs, send signal if overflow occured. I am trying to figure out how to do this to overflow float data type number must be very big (more than 3.40282347 × 10^38). Code must be in C language. Please provide test cases when overflow occurs.
I need to write
Code I did:
float test = FLT_MAX / 2.0;
float product = fl1 * fl2;
printf("Result of product two float values : %f\n", product);
if (product > test || product < -test) {
raise(SIGFPE);
}
product *= 1000000000;
if (product > test || product < -test) {
raise(SIGFPE);
}
printf("Result of product after multiplication by 1 billion: %f\n", product);
but it seems I did something wrong in calculation.
Step by step
Solved in 4 steps with 1 images