-
Notifications
You must be signed in to change notification settings - Fork 168
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Modelica.Constants.Inf should be consistent with the Modelica Language Specification #4503
Comments
No, that only indicates that tools shouldn't use nominal in such a bad way. The goal with nominal is to get values closer to "1" - if that introduces an overflow, it's clearly not working and the code should be rewritten - without updating the models. |
I largely agree. Regarding the MWE, I would say that it is the users responsibility to think carefully about how the model should work when there are no bounds. In this case, I think there is a fundamental mistake in the equation which does not have to do with exactly how big "a very large number" is: when there are no bounds one wants to always end up in the I also agree that it is not good that the specification speaks of some pseudo code |
Oh, I didn't realize that I think that the reason the specification used both pseudo code used |
I would rather go in the other direction and make the MLS more self-contained instead of becoming even more dependent upon the MSL. |
I see that one of the options I gave: Use the same definition for both, i.e., sort of "inline the Modelica.Constants.inf" definition in the specification in those two places (or once and referring to the other). That makes it consistent without having a dependency. |
Good. If we do that, then it might also be a good idea to relate the |
Follow-up of #4479.
I scanned the current MLS 3.6 for "inf" (relative to Real variables) and I found two places where it is mentioned. The first is the definition of the Real type, Section 4.8.1:
In the definition of the defaults for
RealType.min
andRealType.max
,Inf
"denotes a large value". This definition is a bit vague, but one could reasonably argue that this definition is some kind of meta-Modelica or pseudo-Modelica code, since the Real type is built-in, so a compiler developer could interpret theassert
statement in the following waywhich is, BTW, the most efficient way to handle that. So, there is really no need to have a numerical representation of
Inf
to support the definition of Real type. In fact, the elephant in the room here is that there is actually no definition of what RealType actually means. But that is not an issue for MAP-Lib to discuss.The second is in Section 10.3.4.1 (reduction expressions). The caption for Table 10.3 reads:
In this case, the MLS mentions explicitly
-Modelica.Constants.inf
andModelica.Constants.inf
as the least and greatest value of Real (whatever Real means). So, unless we change the MLS, it is not entirely up to MAP-Lib to decide what these constants actually mean - they should be consistent with this definition. Note the interesting similarity (but not the identity) between the default min and max attributes of Real and the default value for empty min and max reductions.Now, consider the following MWE, describing the deformation of a MEMS device, that has a certain stiffness
k
within certain bounds, but becomess
times stiffer outside those bounds. The model is implicit and requires some iterations to figure out the displacement, given the force amplitude.Suppose now that the tool is using the nominal attribute for scaling purposes, as suggested by MLS 4.8.1, so it generates two scaled zero-crossing functions
for improved precision in determining the exact point in time when the event should be triggered.
With the previous definition
Modelica.Constant.inf = 1e60
this would work fine, assuming the code is eventually compiled into double-precision IEEE 754-compliant executable code. With the new definition ofModelica.Constant.inf = 1.7976931348623157E+308
there would be overflow and the behaviour would be undefined.However, the new definition of
Modelica.Constants.inf
in #4042 is "Maximum representable finite floating-point number", which is finally assigned toModelicaServices.Machine.inf
also defined as "Maximum representable finite floating-point number". The actual value provided byModelicaServices.Machine.inf
is by definition "machine-dependent", where I understand that "machine" means the combination of the tool(s) that generate(s) the code and the hw architecture on which it runs. There is no explicit reference to IEEE 745 MAXVAL in these definitions.So, when using
Modelica.Constants.inf
, a user of the MSL should not assume that it will get any specific numerical value. That will be an internal decision of the tool, based on whatever code generation methods and target architectures are selected. The only expectation of a MSL user is that eventually the tool should handle that value properly in all meaningful contexts.Do I understand this correctly and do we have an agreement on that?
@HansOlsson, @dzimmer, @henrikt-ma
The text was updated successfully, but these errors were encountered: