N
N
NaName2017-01-22 16:15:42
C++ / C#
NaName, 2017-01-22 16:15:42

Why in C 0 != 0 and 0 == 0?

Hello!
There is a problem with the C 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 element 561, there 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

those. size should be 562 I think. Under condition height[j] == 0.0 the same problem. I don't know what I'm doing wrong.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
ivkol, 2017-01-22
@NaName

replace with if(fabs(height[j])<0.0000001) ...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question