cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Choose Language Hide Translation Bar
AdamChoen
Level III

Condition error

hello

I'm trying to do a delta check between neighboring cells value on the same column.

For( i = 1, i <= N Row( dtB ), i++,
    If(
        i == 1,
            If( Abs( :Delta[i] - :Delta[i + 1] ) <= 0.1,
                dtB:Check[i] = "Pass",
                dtB:Check[i] = "Fail"
            ),
        i == N Row( dtB ),
            If( Abs( :Delta[i] - :Delta[i - 1] ) <= 0.1,
                dtB:Check[i] = "Pass",
                dtB:Check[i] = "Fail"
            ),
        If( Abs( :Delta[i] - :Delta[i + 1] ) <= 0.1 | Abs( :Delta[i] - :Delta[i - 1] ) <= 0.1,
            dtB:Check[i] = "Pass",
            dtB:Check[i] = "Fail"
        )
    )
);


i get this result

but line 5 should not fail
when I check it thru the log it seems like a bug or I'm missing something
appreciate your inputs

i
/*:

5
//:*/
:Delta[i]
/*:

0.3
//:*/
:Delta[i+1]
/*:

0.4
//:*/
abs(:Delta[i] - :Delta[i+1])
/*:

0.1
//:*/
abs(:Delta[i] - :Delta[i+1]) <= 0.1
/*:

0

Thanks, Adam
11 REPLIES 11
AdamChoen
Level III

Re: Condition error

it's not an issue for me, i like to do that 

Thanks, Adam
Craige_Hales
Super User

Re: Condition error

0.1 is a repeating fraction in binary. In IEEE floating point, it is rounded at 52 or 53 bits, so it must be either a bit too big or a bit too small.

Good binary fractions are sums of  1/2, 1/4, 1/8, 1/16, 1/32, ... 1/2^53 which are the individual bits of the fraction. 

Sometimes the "bit too big" or "bit too small" works out the way you want, and sometimes not.

 

The second example shows an epsilon chosen for numbers near 1, which have about 14 places after the decimal (thus 1e-12).

If( .3 - .2 == .1, // "no"
    "yes"
, // else
    "no"
);


If( Abs( (.3 - .2) - .1 ) < 1e-12, // "yes"
    "yes"
, // else
    "no"
);

 

Old post 

 

Craige