Opened 10 years ago
Closed 7 years ago
#3097 closed defect (wontfix)
Relational operators give inconsistent results
Reported by: | Owned by: | somebody | |
---|---|---|---|
Priority: | high | Milestone: | Future |
Component: | *unknown* | Version: | trunk |
Keywords: | Cc: |
Description (last modified by )
In the following model, relational operators give inconsistent results when the compared variable is set using an "if-expression":
model Test Real y; Boolean b1 = y < 100.0; Boolean b2 = y <= 100.0; Boolean b3 = y == 100.0; Boolean b4 = y >= 100.0; Boolean b5 = y > 100.0; equation y = if time > 2 then 100 else 0; end Test;
The results show that b1 b2 and b3 are all true at the same time, which is illogical.
Change History (3)
comment:1 by , 10 years ago
Description: | modified (diff) |
---|
comment:2 by , 10 years ago
Thanks for the precision. The code I posted here was for debugging purpose only.
I'm actually expecting b2 and b4 to be true when the value of y becomes 100. Since == should be disregarded, the better description of the issue is that >= and <= don't return the right result when the value is set using if-expressions.
In my original model, I was using a Limiter block with a maximum value, and then checking if that maximum value was reached using a GreaterEqual block. These blocks have Real inputs/outputs, and I can't change them to Integer. The only temporary workaround I see is to subtract a small number from the max in the GreaterEqual block, but that's not really proper.
comment:3 by , 7 years ago
Resolution: | → wontfix |
---|---|
Status: | new → closed |
I would classify this model as numerically ill-conditioned. When y jumps from 0.0 to 100.0, which among b1 to b5 becomes true ultimately depends on equality comparisons among Real number in finite double precision, which is not reliable.
Please not, == on Real numbers is only allowed inside function.
If the type of the discrete variable y is changed to Integer, then everything works fine.