You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Finally, create an instance of the class and connect the custom functions to it,
121
-
while also adding them to the parser:
121
+
Finally, create an instance of the class and connect the custom functions to it, while also adding them to the parser:
122
122
123
123
```{.cpp}
124
124
te_expr_array teArray{ TE_DEFAULT };
@@ -137,11 +137,10 @@ auto result = tep.evaluate("SUM(CELL 0, CELL 1, CELL 2, CELL 3, CELL 4)");
137
137
138
138
// call the other function, getting the object's max value
139
139
// (will be 8)
140
-
res = tep.evaluate("CellMax()");
140
+
result = tep.evaluate("CellMax()");
141
141
```
142
142
143
143
:::: {.notesection data-latex=""}
144
-
Valid variable and function names consist of a letter or underscore followed by any combination
145
-
of: letters `a–z` or `A–Z`, digits `0–9`, periods, and underscores.
144
+
Valid variable and function names consist of a letter or underscore followed by any combination of: letters `a–z` or `A–Z`, digits `0–9`, periods, and underscores.
Note that *TinyExpr++* is slower compared to *TinyExpr* because of additional type safety checks (e.g., the use of `std::variant` instead of unions),
20
-
case insensitivity, and bookkeeping operations.
10
+
Note that *TinyExpr++* is slower compared to *TinyExpr* because of additional type safety checks (e.g., the use of `std::variant` instead of unions), case insensitivity, and bookkeeping operations.
21
11
22
12
Refer to [compile-time options](#compile-time-options) for flags that can provide optimization.
23
13
@@ -28,12 +18,9 @@ To instead seed it with the current time, compile with `TE_RAND_SEED_TIME`.
28
18
29
19
## Volatility {-}
30
20
31
-
If needing to use a `te_parser` object as `volatile`
32
-
(e.g., accessing it in a system interrupt), then you will need
33
-
to do the following.
21
+
If needing to use a `te_parser` object as `volatile` (e.g., accessing it in a system interrupt), then you will need to do the following.
34
22
35
-
First, declare your `te_parser` as a non-`volatile` object outside
36
-
of the interrupt function (e.g., globally):
23
+
First, declare your `te_parser` as a non-`volatile` object outside of the interrupt function (e.g., globally):
37
24
38
25
```{.cpp}
39
26
te_parser tep;
@@ -46,8 +33,9 @@ void OnInterrupt()
46
33
volatile te_parser& vTep = tep;
47
34
}
48
35
```
49
-
Functions in `te_parser` which have `volatile` overloads\index{volatile} can then be
50
-
called directly:
36
+
37
+
::: {.minipage data-latex="{\textwidth}"}
38
+
Functions in `te_parser` which have `volatile` overloads\index{volatile} can then be called directly:
51
39
52
40
```{.cpp}
53
41
void OnInterrupt()
@@ -57,6 +45,8 @@ void OnInterrupt()
57
45
vTep.set_decimal_separator('.');
58
46
}
59
47
```
48
+
:::
49
+
60
50
The following functions in the `te_parser` class have `volatile` overloads:
61
51
62
52
-`get_result()`
@@ -67,8 +57,7 @@ The following functions in the `te_parser` class have `volatile` overloads:
67
57
-`get_list_separator()`
68
58
-`set_list_separator()`
69
59
70
-
For any other functions, use `const_cast<>` to remove the parser
71
-
reference's volatility:
60
+
For any other functions, use `const_cast<>` to remove the parser reference's volatility:
72
61
73
62
```{.cpp}
74
63
void OnInterrupt()
@@ -90,21 +79,18 @@ void OnInterrupt()
90
79
}
91
80
```
92
81
93
-
Note that it is required to make the initial declaration of your
94
-
`te_parser` non-`volatile`; otherwise, the `const_cast<>` to the
95
-
`volatile` reference will cause undefined behavior.
82
+
Note that it is required to make the initial declaration of your `te_parser` non-`volatile`; otherwise, the `const_cast<>` to the `volatile` reference will cause undefined behavior.
96
83
97
84
## Floating-point Numbers {-#fp-numbers}
98
85
99
86
`double` is the default data type used for the parser's variable types, parameters, and return types.
100
-
For embedded environments that require `float`\index{data types!\texttt{float} vs. \texttt{double}},
101
-
compile with `TE_FLOAT` defined to use `float` instead.
87
+
For embedded environments that require `float`\index{data types!\texttt{float} vs. \texttt{double}}, compile with `TE_FLOAT` defined to use `float` instead.
102
88
103
89
When using this option, it is recommended to use the helper typedef `te_type`.
104
90
This will map to either `float` or `double` (depending on whether `TE_FLOAT` is defined).
105
-
By defining your functions and variables with `te_type`,
106
-
you won't need to replace `double` and `float` if needing to change this compiler flag.
91
+
By defining your functions and variables with `te_type`, you won't need to replace `double` and `float` if needing to change this compiler flag.
107
92
93
+
::: {.minipage data-latex="{\textwidth}"}
108
94
For example, a custom function would be written as such:
*TinyExpr++* requires exception handling\index{exceptions}, although it does attempt to
134
-
minimize the use of exceptions (e.g., `noexcept` is used extensively).
135
-
Syntax errors will be reported without the use of exceptions;
136
-
issues such as division by zero or arithmetic overflows, however,
137
-
will internally use exceptions. The parser will trap these
138
-
exceptions and return NaN (not a number) as the result.
120
+
*TinyExpr++* requires exception handling\index{exceptions}, although it does attempt to minimize the use of exceptions (e.g., `noexcept` is used extensively).
121
+
Syntax errors will be reported without the use of exceptions; issues such as division by zero or arithmetic overflows, however, will internally use exceptions.
122
+
The parser will trap these exceptions and return NaN (not a number) as the result.
139
123
140
-
Exceptions can also be thrown when defining custom functions or variables
141
-
which do not follow the proper naming convention.
142
-
(Function and variable names may only contain the characters
143
-
`a`-`z`, `A`-`Z`, `0`-`9`, `.`, and `_`, and must begin with a letter.)
124
+
Exceptions can also be thrown when defining custom functions or variables which do not follow the proper naming convention.
125
+
(Function and variable names may only contain the characters `a`-`z`, `A`-`Z`, `0`-`9`, `.`, and `_`, and must begin with a letter.)
144
126
145
-
Finally, specifying an illegal character for a list or decimal separator
146
-
will also throw.
127
+
Finally, specifying an illegal character for a list or decimal separator will also throw.
147
128
148
-
The following functions in `te_parser` can throw and should be wrapped
149
-
in `try`/`catch` blocks:
129
+
The following functions in `te_parser` can throw and should be wrapped in `try`/`catch` blocks:
150
130
151
131
-`compile()`
152
132
-`evaluate()`
@@ -155,13 +135,9 @@ in `try`/`catch` blocks:
155
135
-`set_decimal_separator()`
156
136
-`set_list_separator()`
157
137
158
-
The caught `std::runtime_error` exception will provide a description
159
-
of the error in its `what()` method.
138
+
The caught `std::runtime_error` exception will provide a description of the error in its `what()` method.
160
139
161
140
## Virtual Functions {-}
162
141
163
-
*TinyExpr++* does not use virtual functions\index{functions!virtual} or derived classes\index{classes!derived},
164
-
unless you create a custom class derived from `te_expr` yourself
165
-
(refer to ["Binding to Custom Classes"](#custom-classes) for an example).
166
-
(`te_expr` defines a virtual destructor that may be implicitly optimized to
167
-
`final` if no derived classes are defined.)
142
+
*TinyExpr++* does not use virtual functions\index{functions!virtual} or derived classes\index{classes!derived}, unless you create a custom class derived from `te_expr` yourself (refer to ["Binding to Custom Classes"](#custom-classes) for an example).
143
+
(`te_expr` defines a virtual destructor that may be implicitly optimized to `final` if no derived classes are defined.)
Copy file name to clipboardExpand all lines: docs/manual/end-user-usage.qmd
+9-8Lines changed: 9 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -1,20 +1,21 @@
1
1
# Usage
2
2
3
-
*TinyExpr++* is a formula-solving library which accepts math and logic expressions such as:
3
+
*TinyExpr++* is an expression-evaluation library which accepts math and logic expressions such as:
4
4
5
5
```{.cpp}
6
6
ABS(((5+2) / (ABS(-2))) * -9 + 2) - 5^2
7
7
```
8
8
9
-
Applications using *TinyExpr++* may provide context-specific variables
10
-
that you can use in your expressions. For example, in a spreadsheet application, values representing cells such as `C1` and `D2` may be available. This would enable the use of expressions such as:
9
+
Applications using *TinyExpr++* may provide context-specific variables that you can use in your expressions.
10
+
For example, in a spreadsheet application, values representing cells such as `C1` and `D2` may be available.
11
+
This would enable the use of expressions such as:
11
12
12
13
```{.cpp}
13
14
SUM(C1, C2, C3, D1, D2, D3)
14
15
```
15
16
16
-
As another example, in a statistical program, the values `N_OBS` and
17
-
`P_LEVEL` may be available. This would make an expression such as this possible:
17
+
As another example, in a statistical program, the values `N_OBS` and`P_LEVEL` may be available.
18
+
This would make an expression such as this possible:
0 commit comments