- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
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
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
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 );
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
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" );
);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Condition error
abs(-0.4 - 0.3 ) = 0.7
abs(-0.4) - abs(0.3) = 0.1
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
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 );
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
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 );
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
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!