-
Notifications
You must be signed in to change notification settings - Fork 44
Unitful literals #3688
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
Open
henrikt-ma
wants to merge
4
commits into
modelica:master
Choose a base branch
from
henrikt-ma:unitful-literal
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Unitful literals #3688
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -104,3 +104,34 @@ \section{The Syntax of Unit Expressions}\label{the-syntax-of-unit-expressions} | |||||||||||||
|
||||||||||||||
The unit expression \lstinline!"T"! means tesla, but note that the letter \lstinline!T! is also the symbol for the prefix tera which has a multiplier value of 10\textsuperscript{12}. | ||||||||||||||
\end{example} | ||||||||||||||
|
||||||||||||||
|
||||||||||||||
\section{Unitful Literals} | ||||||||||||||
|
||||||||||||||
The \lstinline[language=grammar]!numeric! in the grammar allows a unit to be attached to a numeric value. | ||||||||||||||
In this case, the unit is given as a \lstinline[language=grammar]!Q-IDENT! rather than a string, since the use of a string could be ambiguously interpreted as \lstinline[language=grammar]!description-string! in some contexts. | ||||||||||||||
|
||||||||||||||
\begin{example} | ||||||||||||||
An acceleration of 9.8 meters per square second can be expressed as \lstinline!9.8'm/s2'!. | ||||||||||||||
\end{example} | ||||||||||||||
|
||||||||||||||
\begin{example} | ||||||||||||||
Adding 2~centimeters to a length. | ||||||||||||||
A user has set \lstinline!x! to 10~centimeters with the use of \lstinline!displayUnit!, and intends to make \lstinline!y! 2~centimeters bigger than \lstinline!x!: | ||||||||||||||
\begin{lstlisting}[language=modelica] | ||||||||||||||
parameter Real x(unit = "m", displayUnit = "cm") = 0.1; | ||||||||||||||
equation | ||||||||||||||
y = x + 2; /* Intention: Add 2 centimeters to x. */ | ||||||||||||||
henrikt-ma marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||
\end{lstlisting} | ||||||||||||||
The result is that 2~meters instead of 2~centimeters is being added to \lstinline!x!. | ||||||||||||||
|
||||||||||||||
Using a unitful literal makes the intention clear: | ||||||||||||||
\begin{lstlisting}[language=modelica] | ||||||||||||||
y = x + 2'cm'; | ||||||||||||||
\end{lstlisting} | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To make it clearer that it is just adding lines to clarify, and that the following lines are unchanged. |
||||||||||||||
It is currently not expected that tools will perform an implicit unit conversion to make the addition possible, in which case the addition should be rejected as a unit inconsistency. | ||||||||||||||
HansOlsson marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||
The unit inconsistency can then be resolved by using a unit compatible with the unit of \lstinline!x!: | ||||||||||||||
\begin{lstlisting}[language=modelica] | ||||||||||||||
y = x + 0.02'm'; | ||||||||||||||
\end{lstlisting} | ||||||||||||||
\end{example} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.