-
Notifications
You must be signed in to change notification settings - Fork 194
There are several possibilities how to introduce a constant from Modelica.Constants in a class. E.g. for pi, I have found following in MSL:
- Definition of constant:
constant Real pi = Modelica.Constants.pi;(or alsoconstant SI.Angle pi = Modelica.Constants.pi;) - Qualified import:
Import Modelica.Constants.pi; - Directly in equation, e.g.
phi = 2 * Modelica.Constants.pi * w;
Is there a preferrable way having advantages over others?
All reactions
-
👍 1
One more variant:
final constant pi = Modelica.Constants.pi because otherwise the constant could be modified with a modifier from an extending class.
Replies: 2 comments 1 reply
I would suggest avoiding the first one (new constant). I would prefer Modelica.Constants.pi (or .Modelica.Constants.pi); unless it is used a lot of times and the import would make it easier to reader. The problem with import is that you always have to check that it is imported in the current class.
All reactions
The problem with import is that you always have to check that it is imported in the current class.
This is probably less problematic for common constants, compared to other classes. I mean when there is used pi somewhere in an equation, one can expect it could be an imported variable.
All reactions
One more variant:
final constant pi = Modelica.Constants.pi because otherwise the constant could be modified with a modifier from an extending class.