The accuracy to which real number calculations can be carried out using a particular real type is determined by the precision, i.e. the maximum number of decimal places that the floating value carries. The standard header file <float.h> provides details on the range and precision of real numbers enabling programs to determine if the specific implementation can support the application.
The following program determines the precision in decimal digits for type float, double and long double.
CODE
#include <stdio.h>
#include <float.h>
int main()
{
printf("float precision %d \n", FLT_DIG);
printf("double precision %d \n", DBL_DIG);
printf("long double precision %d \n", LDBL_DIG);
getchar();
}
Run using DEV-C++ I get:
float precision 6
double precision 15
long double precision 18
Try running the program and see what the precision of your float variables is. If insufficent use double or long double. However, the greater the precision the larger the storage requirements and longer it takes to execute instructions.