cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Check out the JMP® Marketplace featured Capability Explorer add-in
Choose Language Hide Translation Bar
AdamChoen
Level IV

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
2 ACCEPTED SOLUTIONS

Accepted Solutions

Re: Condition error

I confirm this error with the follow code (view results in Log):

 

/* Abs( 0.4 - 0.3) == 0.1; returns 0 or false */

y = 0.1; x1 = 0.4; x2 = 0.3; diff = x1 - x2;
Show( y, x1, x2, diff, diff == 0.1 );

View solution in original post

pmroz
Super User

Re: Condition error

That's your basic floating point roundoff error.  Add an epsilon and it works:

Deltai = 0.3;
Deltai1 = 0.4;
epsilon = .000000001;
print(abs(Deltai - Deltai1));	// = 0.1;
print(abs(Deltai - Deltai1) <= 0.1);
print(abs(Deltai - Deltai1) <= 0.1 + epsilon);

From the log:

0.1
0
1

View solution in original post

11 REPLIES 11

Re: Condition error

If I understand what you are trying to do, then this simplified version might work:

 

For Each Row(
	dtB:Check = If( Abs( :Delta - Lag(:Delta) ) <= 0.1, "Pass", "Fail" );
);
AdamChoen
Level IV

Re: Condition error

I like to check the cell value matching (up to 0.1) from both "sides" n+1 and n-1 in this column. 1st and last rows on one side.
thank you 

Thanks, Adam
txnelson
Super User

Re: Condition error

abs(-0.4 - 0.3 ) = 0.7

abs(-0.4) - abs(0.3) = 0.1

Jim
AdamChoen
Level IV

Re: Condition error

sorry, didn't get it.

 

i = 5;
:Delta[i] = 0.3;
:Delta[i+1] = 0.4;
abs(:Delta[i] - :Delta[i+1]) = 0.1;
// but 
abs(:Delta[i] - :Delta[i+1]) <= 0.1 // give me 0

 

 why is that? also == give me 0, >= give 1.

 

Thanks, Adam

Re: Condition error

I confirm this error with the follow code (view results in Log):

 

/* Abs( 0.4 - 0.3) == 0.1; returns 0 or false */

y = 0.1; x1 = 0.4; x2 = 0.3; diff = x1 - x2;
Show( y, x1, x2, diff, diff == 0.1 );
jthi
Super User

Re: Condition error

One more thing to check would be the difference between diff and 0.1

diff - 0.1 = 2.77555756156289e-17;

so floating number accuracy "problem"?

 

Round(diff, 1) == Round(0.1, 1) = 1;
-Jarmo
pmroz
Super User

Re: Condition error

That's your basic floating point roundoff error.  Add an epsilon and it works:

Deltai = 0.3;
Deltai1 = 0.4;
epsilon = .000000001;
print(abs(Deltai - Deltai1));	// = 0.1;
print(abs(Deltai - Deltai1) <= 0.1);
print(abs(Deltai - Deltai1) <= 0.1 + epsilon);

From the log:

0.1
0
1

Re: Condition error

JMP Development confirmed that this is simply a finite precision numerical problem. Users are disturbed by floating point numbers that do not follow the math (e.g., subtraction). JMP tries to present the result as it is expected, but not the actual result in cases like yours (i.e., 0.4 - 0.3). They suggested also using this approach if you want a better view of the actual result:

 

Format( 0.1, "Fixed Dec", 20, 22 );
Format( 0.4-0.3, "Fixed Dec", 20, 22 );
txnelson
Super User

Re: Condition error

The issue is that the difference from minus .4 to a positive .3 is .7.  The Absolute of the values are taken after the calculation!

Jim