diff --git a/chapters/classes.tex b/chapters/classes.tex index c8e372eca..dc3277a0e 100644 --- a/chapters/classes.tex +++ b/chapters/classes.tex @@ -1625,11 +1625,10 @@ \subsubsection{Type Conversion of Enumeration Values to String or Integer}\label The type conversion function \lstinline!Integer()! returns the ordinal number of the enumeration value \lstinline!E.enumvalue!, to which the expression is evaluated, -where \lstinline!Integer(E.e1) =1, Integer(E.en) = n!, for an enumeration type -\lstinline!E=enumeration(e1, ..., en)!. +where \lstinline!Integer(E.e1) = 1!, \lstinline!Integer(E.en) = n!, for an enumeration type +\lstinline!E = enumeration(e1, ..., en)!. -\lstinline!String(E.enumvalue)! gives the string representation of the enumeration -value. +\lstinline!String(E.enumvalue)! gives the \lstinline!String! representation of the enumeration value. \begin{example} \lstinline!String(E.Small)! gives \lstinline!"Small"!. diff --git a/chapters/operatorsandexpressions.tex b/chapters/operatorsandexpressions.tex index faa230fbf..749c512cb 100644 --- a/chapters/operatorsandexpressions.tex +++ b/chapters/operatorsandexpressions.tex @@ -377,79 +377,98 @@ \subsection{Numeric Functions and Conversion Functions}\label{numeric-functions- whereas the event-triggering mathematical functions are described in \cref{event-triggering-mathematical-functions}. -\begin{longtable}{|p{4.5cm}|p{10cm}|} \hline -\endhead -\lstinline!abs(v)! & Is expanded into \lstinline!noEvent(if v >= 0 then v else -v)!. Argument v needs to be an Integer or Real expression.\\ \hline -\lstinline!sign(v)! & Is expanded into \lstinline!noEvent(if v>0 then 1 else if v<0 then -1 else 0)!. Argument v needs to be an Integer or Real -expression.\\ \hline -\lstinline!sqrt(v)! & Returns the square root of \lstinline!v if v>=0!, otherwise -an error occurs. Argument v needs to be an Integer or Real -expression.\\ \hline - -\lstinline!Integer(e)! & Returns the ordinal number of the expression \lstinline!e! of -enumeration type that evaluates to the enumeration value \lstinline!E.enumvalue!, -where \lstinline!Integer(E.e1)=1!, \lstinline!Integer(E.en)=n!, for an enumeration type -\lstinline!E=enumeration(e1, ..., en)!. See also \cref{type-conversion-of-enumeration-values-to-string-or-integer}.\\ \hline -\lstinline!EnumTypeName(i)! & -For any enumeration type \lstinline!EnumTypeName!, returns the enumeration -value \lstinline!EnumTypeName!.e such that \lstinline!Integer(EnumTypeName.e) = i!. Refer to the definition of +\begin{operatordefinition}[abs] +\begin{synopsis}\begin{lstlisting}[language=synopsis] +abs(v) +\end{lstlisting}\end{synopsis} +\begin{semantics} +Expands into \lstinline!noEvent(if v >= 0 then v else -v)!. Argument \lstinline!v! needs to be an \lstinline!Integer! or \lstinline!Real! expression. +\end{semantics} +\end{operatordefinition} + +\begin{operatordefinition}[sign] +\begin{synopsis}\begin{lstlisting}[language=synopsis] +sign(v) +\end{lstlisting}\end{synopsis} +\begin{semantics} +Expands into \lstinline!noEvent(if v>0 then 1 else if v<0 then -1 else 0)!. Argument \lstinline!v! needs to be an \lstinline!Integer! or \lstinline!Real! expression. +\end{semantics} +\end{operatordefinition} + +\begin{operatordefinition}[sqrt] +\begin{synopsis}\begin{lstlisting}[language=synopsis] +sqrt(v) +\end{lstlisting}\end{synopsis} +\begin{semantics} +Square root of \lstinline!v! if $\text{\lstinline!v!} \geq 0$, otherwise an error occurs. Argument \lstinline!v! needs to be an \lstinline!Integer! or \lstinline!Real! expression. +\end{semantics} +\end{operatordefinition} + +\begin{operatordefinition}[Integer] +\begin{synopsis}\begin{lstlisting}[language=synopsis] +Integer(e) +\end{lstlisting}\end{synopsis} +\begin{semantics} +Ordinal number of the expression \lstinline!e! of enumeration type that evaluates to the enumeration value \lstinline!E.enumvalue!, where \lstinline!Integer(E.e1) = 1!, \lstinline!Integer(E.en) = n!, +for an enumeration type \lstinline!E = enumeration(e1, ..., en)!. See also \cref{type-conversion-of-enumeration-values-to-string-or-integer}. +\end{semantics} +\end{operatordefinition} + +\begin{operatordefinition}[] +\begin{synopsis}\begin{lstlisting}[language=synopsis] +EnumTypeName(i) +\end{lstlisting}\end{synopsis} +\begin{semantics} +For any enumeration type \lstinline!EnumTypeName!, returns the enumeration value \lstinline!EnumTypeName.e! such that \lstinline!Integer(EnumTypeName.e) = i!. Refer to the definition of \lstinline!Integer! above. -It is an error to attempt to convert values of i that do not correspond -to values of the enumeration type. See also \cref{type-conversion-of-integer-to-enumeration-values}. -\\ \hline - -\begin{tabular}{@{}p{4.5cm}@{}} -\lstinline!String(b, )!\\ -\lstinline!String(i, )!\\ -\lstinline!String(r,! -\hspace*{1ex}\lstinline!significantDigits=d,! -\hspace*{1ex}\lstinline!)!\\ -\lstinline!String(r, format=s)!\\ -\lstinline!String(e, )! -\end{tabular} -& -Convert a scalar non-\lstinline!String! expression to a \lstinline!String! representation. The -first argument may be a \lstinline!Boolean b!, an \lstinline!Integer i!, a \lstinline!Real r! or an -\lstinline!Enumeration e! (\cref{type-conversion-of-enumeration-values-to-string-or-integer}). The other arguments must use named -arguments. The optional \textless{}options\textgreater{} are: - -\lstinline!Integer minimumLength=0!: minimum length of the resulting string. If -necessary, the blank character is used to fill up unused space. - -\lstinline!Boolean leftJustified = true!: if true, the converted result is left -justified in the string; if false it is right justified in the string. - -For \lstinline!Real! expressions the output shall be according to the Modelica -grammar. \lstinline!Integer significantDigits!=6: defines the number of significant -digits in the result string. +It is an error to attempt to convert values of \lstinline!i! that do not correspond to values of the enumeration type. See also \cref{type-conversion-of-integer-to-enumeration-values}. +\end{semantics} +\end{operatordefinition} + +\begin{operatordefinition}[String] +\begin{synopsis}\begin{lstlisting}[language=synopsis] +String(b, ) +String(i, ) +String(r, significantDigits=d, ) +String(r, format=s) +String(e, ) +\end{lstlisting}\end{synopsis} +\begin{semantics} +Convert a scalar non-\lstinline!String! expression to a \lstinline!String! representation. The first argument may be a \lstinline!Boolean b!, an \lstinline!Integer i!, a \lstinline!Real r! or an +enumeration value \lstinline!e! (\cref{type-conversion-of-enumeration-values-to-string-or-integer}). The other arguments must use named arguments. For \lstinline!Real! expressions the output shall be according to the Modelica grammar. + +The optional \lstinline!! are: +\begin{itemize} +\item + \lstinline!Integer minimumLength = 0!: Minimum length of the resulting string. If necessary, the blank character is used to fill up unused space. +\item + \lstinline!Boolean leftJustified = true!: If true, the converted result is left justified in the string; if false it is right justified in the string. +\item + \lstinline!Integer significantDigits = 6!: Number of significant digits in the result string. +\end{itemize} \begin{nonnormative} Examples of \lstinline!Real! values formatted with 6 significant digits: \emph{12.3456}, \emph{0.0123456}, \emph{12345600}, \emph{1.23456E-10}. \end{nonnormative} -The format string corresponding to options is: +The \lstinline!format! string corresponding to \lstinline!! is: \begin{itemize} \item - for Reals: %\newline - \lstinline!(if leftJustified then "-" else "") + String(minimumLength)+"."+ String(signficantDigits)+"g"!, + For \lstinline!Real!: \lstinline!(if leftJustified then "-" else "") + String(minimumLength) + "." + String(signficantDigits) + "g"! \item - for Integers: %\newline - \lstinline!(if leftJustified then "-" else "")+ String(minimumLength)+"d"!. + For \lstinline!Integer!: \lstinline!(if leftJustified then "-" else "") + String(minimumLength) + "d"! \end{itemize} -Format string: According to ANSI-C the format string specifies one -conversion specifier (excluding the leading \%), may not contain length -modifiers, and may not use `\lstinline!*!' for width and/or precision. For all -numeric values the format specifiers `\lstinline!f!', `\lstinline!e!', `\lstinline!E!', `\lstinline!g!', `\lstinline!G!' are allowed. For -integral values it is also allowed to use the `\lstinline!d!', `\lstinline!i!', `\lstinline!o!', `\lstinline!x!', `\lstinline!X!', `\lstinline!u!', and -`\lstinline!c!' format specifiers (for non-integral values a tool may~round, truncate -or use a different format if the integer conversion characters are -used). - -The x,X-formats (hexa-decimal)~and c (character) for Integers does not -lead to input~that agrees with the Modelica-grammar.\\ \hline -\end{longtable} +Form of the \lstinline!format! string: According to ANSI-C the format string specifies one conversion specifier (excluding the leading \%), may not contain length modifiers, and may not use +`\lstinline!*!' for width and/or precision. For all numeric values the format specifiers `\lstinline!f!', `\lstinline!e!', `\lstinline!E!', `\lstinline!g!', `\lstinline!G!' are allowed. For +integral values it is also allowed to use the `\lstinline!d!', `\lstinline!i!', `\lstinline!o!', `\lstinline!x!', `\lstinline!X!', `\lstinline!u!', and `\lstinline!c!' format specifiers (for +non-integral values a tool may round, truncate or use a different format if the integer conversion characters are used). + +The `\lstinline!x!'/`\lstinline!X!' formats (hexa-decimal) and \lstinline!c! (character) for \lstinline!Integer! values give results that do not agree with the Modelica grammar. +\end{semantics} +\end{operatordefinition} + \subsubsection{Event Triggering Mathematical Functions}\label{event-triggering-mathematical-functions}