preprocessor: submodule update and doc update
parent
7efacbc478
commit
b33900b86c
|
@ -10319,7 +10319,7 @@ directives are:
|
||||||
The macro processor maintains its own list of variables (distinct from model
|
The macro processor maintains its own list of variables (distinct from model
|
||||||
variables and MATLAB/Octave variables). These macro-variables are assigned
|
variables and MATLAB/Octave variables). These macro-variables are assigned
|
||||||
using the ``@#define`` directive and can be of the following basic types:
|
using the ``@#define`` directive and can be of the following basic types:
|
||||||
boolean, double, string, tuple, function, and array (of any of the previous
|
boolean, real, string, tuple, function, and array (of any of the previous
|
||||||
types).
|
types).
|
||||||
|
|
||||||
|
|
||||||
|
@ -10337,7 +10337,7 @@ Macro-expressions can be used in two places:
|
||||||
|
|
||||||
It is possible to construct macro-expressions that can be assigned to
|
It is possible to construct macro-expressions that can be assigned to
|
||||||
macro-variables or used within a macro-directive. The expressions are
|
macro-variables or used within a macro-directive. The expressions are
|
||||||
constructed using literals of the basic types (boolean, double, string, tuple,
|
constructed using literals of the basic types (boolean, real, string, tuple,
|
||||||
array), comprehensions, macro-variables, macro-functions, and standard
|
array), comprehensions, macro-variables, macro-functions, and standard
|
||||||
operators.
|
operators.
|
||||||
|
|
||||||
|
@ -10352,25 +10352,21 @@ The following operators can be used on booleans:
|
||||||
* Comparison operators: ``==, !=``
|
* Comparison operators: ``==, !=``
|
||||||
* Logical operators: ``&&, ||, !``
|
* Logical operators: ``&&, ||, !``
|
||||||
|
|
||||||
.. rubric:: Double
|
.. rubric:: Real
|
||||||
|
|
||||||
The following operators can be used on doubles:
|
The following operators can be used on reals:
|
||||||
|
|
||||||
* Arithmetic operators: ``+, -, *, /, ^``
|
* Arithmetic operators: ``+, -, *, /, ^``
|
||||||
* Comparison operators: ``<, >, <=, >=, ==, !=``
|
* Comparison operators: ``<, >, <=, >=, ==, !=``
|
||||||
* Logical operators: ``&&, ||, !``
|
* Logical operators: ``&&, ||, !``
|
||||||
* Integer ranges with an increment of ``1``:
|
* Ranges with an increment of ``1``: ``REAL1:REAL2`` (for example, ``1:4``
|
||||||
``INTEGER1:INTEGER2`` (for example, ``1:4`` is equivalent to
|
is equivalent to real array ``[1, 2, 3, 4]``).
|
||||||
integer array ``[1, 2, 3, 4]``).
|
|
||||||
|
|
||||||
.. versionchanged:: 4.6
|
.. versionchanged:: 4.6 Previously, putting brackets around the arguments
|
||||||
Previously, putting brackets around the arguments to the colon
|
to the colon operator (e.g. ``[1:4]``) had no effect. Now, ``[1:4]``
|
||||||
operator (e.g. ``[1:4]``) had no effect. Now, ``[1:4]`` will create
|
will create an array containing an array (i.e. ``[ [1, 2, 3, 4] ]``).
|
||||||
an array containing a single element, itself an array (i.e. it is
|
* Ranges with user-defined increment: ``REAL1:REAL2:REAL3`` (for example,
|
||||||
equivalent to ``[ [1, 2, 3, 4] ]``)
|
``6:-2.1:-1`` is equivalent to real array ``[6, 3.9, 1.8, -0.3]``).
|
||||||
* Integer ranges with user-defined increment:
|
|
||||||
``INTEGER1:INTEGER2:INTEGER3`` (for example, ``6:-2.1:-1`` is equivalent to
|
|
||||||
integer array ``[6, 3.9, 1.8, -0.3]``).
|
|
||||||
* Functions: ``max, min, mod, exp, log, log10, sin, cos, tan, asin, acos,
|
* Functions: ``max, min, mod, exp, log, log10, sin, cos, tan, asin, acos,
|
||||||
atan, sqrt, cbrt, sign, floor, ceil, trunc, erf, erfc, gamma, lgamma,
|
atan, sqrt, cbrt, sign, floor, ceil, trunc, erf, erfc, gamma, lgamma,
|
||||||
round, normpdf, normcdf``. NB ``ln`` can be used instead of ``log``
|
round, normpdf, normcdf``. NB ``ln`` can be used instead of ``log``
|
||||||
|
@ -10402,7 +10398,7 @@ The following operators can be used on tuples:
|
||||||
.. rubric:: Array
|
.. rubric:: Array
|
||||||
|
|
||||||
Arrays are enclosed by brackets, and their elements are separated
|
Arrays are enclosed by brackets, and their elements are separated
|
||||||
by commas (like ``[1,[2,3],4]`` or ``["US", "EA"]``).
|
by commas (like ``[1,[2,3],4]`` or ``["US", "FR"]``).
|
||||||
|
|
||||||
The following operators can be used on arrays:
|
The following operators can be used on arrays:
|
||||||
|
|
||||||
|
@ -10490,9 +10486,9 @@ can be combined with them depend on their return type.
|
||||||
.. rubric:: Casting between types
|
.. rubric:: Casting between types
|
||||||
|
|
||||||
Variables and literals of one type can be cast into another type. Some type
|
Variables and literals of one type can be cast into another type. Some type
|
||||||
changes are straightforward (e.g. changing a `double` to a `string`) whereas
|
changes are straightforward (e.g. changing a `real` to a `string`) whereas
|
||||||
others have certain requirements (e.g. to cast an `array` to a `double` it must
|
others have certain requirements (e.g. to cast an `array` to a `real` it must
|
||||||
be a one element array containing a type that can be cast to `double`).
|
be a one element array containing a type that can be cast to `real`).
|
||||||
|
|
||||||
*Examples*
|
*Examples*
|
||||||
|
|
||||||
|
@ -10503,17 +10499,17 @@ be a one element array containing a type that can be cast to `double`).
|
||||||
+----------------------------------+------------+
|
+----------------------------------+------------+
|
||||||
| ``(bool) 0`` | ``false`` |
|
| ``(bool) 0`` | ``false`` |
|
||||||
+----------------------------------+------------+
|
+----------------------------------+------------+
|
||||||
| ``(double) "2.2"`` | ``2.2`` |
|
| ``(real) "2.2"`` | ``2.2`` |
|
||||||
+----------------------------------+------------+
|
+----------------------------------+------------+
|
||||||
| ``(tuple) [3.3]`` | ``(3.3)`` |
|
| ``(tuple) [3.3]`` | ``(3.3)`` |
|
||||||
+----------------------------------+------------+
|
+----------------------------------+------------+
|
||||||
| ``(array) 4.4`` | ``[4.4]`` |
|
| ``(array) 4.4`` | ``[4.4]`` |
|
||||||
+----------------------------------+------------+
|
+----------------------------------+------------+
|
||||||
| ``(double) [5.5]`` | ``5.5`` |
|
| ``(real) [5.5]`` | ``5.5`` |
|
||||||
+----------------------------------+------------+
|
+----------------------------------+------------+
|
||||||
| ``(double) [6.6, 7.7]`` | ``error`` |
|
| ``(real) [6.6, 7.7]`` | ``error`` |
|
||||||
+----------------------------------+------------+
|
+----------------------------------+------------+
|
||||||
| ``(double) "8.8 in a string"`` | ``error`` |
|
| ``(real) "8.8 in a string"`` | ``error`` |
|
||||||
+----------------------------------+------------+
|
+----------------------------------+------------+
|
||||||
|
|
||||||
Casts can be used in expressions:
|
Casts can be used in expressions:
|
||||||
|
@ -10525,7 +10521,7 @@ Casts can be used in expressions:
|
||||||
+===========================+============+
|
+===========================+============+
|
||||||
| ``(bool) 0 && true`` | ``false`` |
|
| ``(bool) 0 && true`` | ``false`` |
|
||||||
+---------------------------+------------+
|
+---------------------------+------------+
|
||||||
| ``(double) "1" + 2`` | ``3`` |
|
| ``(real) "1" + 2`` | ``3`` |
|
||||||
+---------------------------+------------+
|
+---------------------------+------------+
|
||||||
| ``(string) (3 + 4)`` | ``"7"`` |
|
| ``(string) (3 + 4)`` | ``"7"`` |
|
||||||
+---------------------------+------------+
|
+---------------------------+------------+
|
||||||
|
@ -10582,9 +10578,9 @@ Macro directives
|
||||||
|
|
||||||
::
|
::
|
||||||
|
|
||||||
@#define x = 5 // Double
|
@#define x = 5 // Real
|
||||||
@#define y = "US" // String
|
@#define y = "US" // String
|
||||||
@#define v = [ 1, 2, 4 ] // Double array
|
@#define v = [ 1, 2, 4 ] // Real array
|
||||||
@#define w = [ "US", "EA" ] // String array
|
@#define w = [ "US", "EA" ] // String array
|
||||||
@#define u = [ 1, ["EA"] ] // Mixed array
|
@#define u = [ 1, ["EA"] ] // Mixed array
|
||||||
@#define z = 3 + v[2] // Equals 5
|
@#define z = 3 + v[2] // Equals 5
|
||||||
|
@ -10630,12 +10626,12 @@ Macro directives
|
||||||
value. Conversely, ``@#ifndef`` will evaluate to true if the MACRO_VARIABLE
|
value. Conversely, ``@#ifndef`` will evaluate to true if the MACRO_VARIABLE
|
||||||
has not yet been defined.
|
has not yet been defined.
|
||||||
|
|
||||||
Note that if a double appears as the result of the MACRO_EXPRESSION, it
|
Note that if a real appears as the result of the MACRO_EXPRESSION, it
|
||||||
will be interpreted as a boolean; a value of ``0`` is interpreted as ``false``,
|
will be interpreted as a boolean; a value of ``0`` is interpreted as ``false``,
|
||||||
otherwise it is interpreted as ``true``. Further note that because of the
|
otherwise it is interpreted as ``true``. Further note that because of the
|
||||||
imprecision of doubles, extra care must be taken when testing them in the
|
imprecision of reals, extra care must be taken when testing them in the
|
||||||
MACRO_EXPRESSION. For example, ``exp(log(5)) == 5`` will evaluate to
|
MACRO_EXPRESSION. For example, ``exp(log(5)) == 5`` will evaluate to
|
||||||
``false``. Hence, when comparing double values, you should generally use a
|
``false``. Hence, when comparing real values, you should generally use a
|
||||||
zero tolerance around the value desired, e.g. ``exp(log(5)) > 5-1e-14 &&
|
zero tolerance around the value desired, e.g. ``exp(log(5)) > 5-1e-14 &&
|
||||||
exp(log(5)) < 5+1e-14``
|
exp(log(5)) < 5+1e-14``
|
||||||
|
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit ddd43618876b50467bb1e8799f271b38a4913838
|
Subproject commit ff6eea7f297cdceab7b8c2fd954d7332bb86e04f
|
Loading…
Reference in New Issue