I hope this question is not duplicated, since I tried to find an answer already. I've seen many similar questions, but none of them was quite helpful.
I'm writing a program where I need to read matrix values from a file. There are three values for each new line, as usual (row index (int), col index (int), value (float)).
From what I understand, the single precision data type (float) in C can represent values from 1.175494351E-38 to 3.402823466E+38. Knowing this, I cannot understand why my program reads strangely rounded up values from the file, instead of the right one.
The program does this:
int d,c;
float val;
for (int i=0; i<nz; i++) {
...
fscanf(f, "%d %d %f\n", &r, &c, &val);
...
}
In the file, I have the line:
1 1 881.41025641026
but the program reads
1 1 881.4102783203125
I also tried to use different format strings to read and print values (such as %g), but the result is the same. When I use double precision the value is correct, so I'm assuming it as something to do with dimension of the data type, but I don't understand exactly how.