Why 0 != 0 and 0 == 0?

Hello!
There is a problem with the code:
SIZE_J = 600;
for (int j = 0; j < SIZE_J; j++) {
 height[j] = TMP_data_0[j];
 if (height[j] == 0) {
 *size = j + 1;
break;
}

 printf("j = %d\ncurrent = %f\n", j, height[j]);

}

printf("size = %d\n", size);

In height starting from 561 element are zeros, but if you look at what is happening in the console:
j = 559
current = 826.784363
j = 560
current = 827.878113
j = 561
current = 0.000000
j = 562
current = 0.000000
...
j = 587
current = 0.000000
j = 588
current = 0.000000
size = 590

ie, size must be equal to 562, I think. Subject height[j] == 0.0 the exact same problem. Don't know what I'm doing wrong.
August 23rd 19 at 10:59
3 answers
August 23rd 19 at 11:01
Solution
replace if(fabs(height[j])<0.0000001) ...
August 23rd 19 at 11:03
Solution
Because of the peculiarities of the machine representation of real numbers to compare them directly is not recommended. Try instead of %f use %e and, most likely, will find that the array is not zero.
I think it will tipo 0.1 e-100, if not zero but near it. I will try - Yasmine74 commented on August 23rd 19 at 11:06
Also increase the accuracy in the output: %.10f, for example. - Savion_Kozey commented on August 23rd 19 at 11:09
: If there is 1*10-30, then what %.30f to put? - Erling.Berni commented on August 23rd 19 at 11:12
: You can. But if you're operating on such numbers, then maybe it'll be on scientific format? %.10e - Savion_Kozey commented on August 23rd 19 at 11:15
:So I originally suggested. Only with automatic precision. - Erling.Berni commented on August 23rd 19 at 11:18
: Sori, something in the morning imagining that you are the author of the question :-)
As far as I know there is no automatic accuracy. The default precision is 6 decimal places, while you in the manual do not specify a different value will be 6 characters - automatics here and does not smell. - Savion_Kozey commented on August 23rd 19 at 11:21
August 23rd 19 at 11:05
Solution
#include <math.h>
int j;
for (j = 0; j < SIZE_J && ceil(TMP_data_0[j])!=0; j++) {
 height[j] = TMP_data_0[j];
 printf("j = %d\ncurrent = %f\n", j, height[j]);
}
*size = j;</math.h>

On future: post the full listing, not the piece - what tpiy variables as they are populated, that all can happen with them.
By the way, what compiler were all bildirici?

Find more questions by tags AlgorithmsCProgramming