Opened 14 years ago
Closed 7 years ago
#1469 closed defect (wontfix)
Bugs related to division by zero
Reported by: | Martin Sjölund | Owned by: | Martin Sjölund |
---|---|---|---|
Priority: | high | Milestone: | Future |
Component: | Backend | Version: | |
Keywords: | Cc: | Martin Sjölund, Patrick Täuber |
Description (last modified by )
class A constant Real x = 0; Real r = x/x; end A;
Gives
r = 0.0
Both wrong result, and no assertion added.
class A Real x = 0; Real r = x/x; end A;
Gives
r = 1.0
No assertion is added.
Change History (6)
follow-up: 5 comment:1 by , 14 years ago
follow-up: 6 comment:2 by , 10 years ago
Cc: | sjoelund.se, → sjoelund.se |
---|---|
Component: | → Backend |
Description: | modified (diff) |
The first example now gives an error and fails in r25153, instead of giving an error and continuing. The second example still behaves the same. It could be fixed by removing the x/x = 1 rule in ExpressionSimplify, but I'm not sure what that will affect. Interesting to note is that Dymola says r = 1.0 in both cases though.
comment:3 by , 9 years ago
Milestone: | → Future |
---|
comment:4 by , 9 years ago
Cc: | added |
---|
comment:5 by , 9 years ago
I don't think equating 1.0/0.0 to inf (i.e. +inf) good.
In fact, the limit of 1/x for x->0 is +inf or -inf depending on whether we consider the right or left limit.
For simulation purposes, I think that Dymola's way to is ok: lim (x/x) for x->0 is actually 1.0.
Replying to sjoelund.se:
Note: 1.0 / 0.0 should become inf, 0.0 / 0.0 nan (if anything)
comment:6 by , 7 years ago
Resolution: | → wontfix |
---|---|
Status: | new → closed |
Replying to perost:
The first example now gives an error and fails in r25153, instead of giving an error and continuing. The second example still behaves the same. It could be fixed by removing the x/x = 1 rule in ExpressionSimplify, but I'm not sure what that will affect. Interesting to note is that Dymola says r = 1.0 in both cases though.
I guess this behaviour makes sense. If x is a constant and is equal to zero the model doesn't make sense. If x is a Real variable (thus in general time-varying) it makes sense to consider x/x = 1 also when x approaches zero.
If there are objections please re-open the ticket and make a concrete proposal
Note: 1.0 / 0.0 should become inf, 0.0 / 0.0 nan (if anything)