Computes the accuracy of the floating point numbers in storage and calculations
#include <stdio.h>
int main()
{
float floatNumber1, floatNumber2;
float result;
int counter;
floatNumber1 = 1.0;
floatNumber2 = 1.0;
counter = 0;
while (floatNumber1 + floatNumber2 != floatNumber1) {
++counter;
floatNumber2 = floatNumber2 / 10.0;
}
printf("%2d digits accuracy in calculations\n", counter);
floatNumber2 = 1.0;
counter = 0;
while (1) {
result = floatNumber1 + floatNumber2;
if (result == floatNumber1)
break;
++counter;
floatNumber2 = floatNumber2 / 10.0;
}
printf("%2d digits accuracy in storage\n", counter);
return (0);
}
Related examples in the same category