Floating-point zeros not caught by comparison

JonathanC jcrapuchettes at gamil.com
Thu Feb 1 10:02:46 PST 2007


I'm having a problem with an if statement not catching some floating-point zeros. I know that there are 9 values in the array, but only 7 are found by the if and outputted by the debug statement. If I remove the if statement and the code in its block, all 9 of the zeros are printed by the debug statement.

Does anyone have any idea what might be the problem?

Thanks,
JonathanC

Code:
------------------------------------------------------------------------------------------
    uint zeros = 0;
    real test = .01;
    uint size = X.Rows;
    for (uint i = 0; i < size; i++)
    {
        real r = X.Data[i];
        debug (calcXHI) writefln("i:", i, ", r:", r);
        if (std.math.abs(r) <= test)
        {
            zeros++;
            size--;
            for (j = i + 1; j < size; j++)
            {
                X.Data[j - 1] = X.Data[j];
            }
        }
    }



More information about the Digitalmars-d mailing list