Skip to content

Commit 0ee024c

Browse files
committed
Edits to the manual
1 parent 5061516 commit 0ee024c

13 files changed

+160
-191
lines changed

docs/manual/building.qmd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Building
22

3-
*TinyExpr++* is self-contained in two files: "tinyexpr.cpp" and "tinyexpr.h". To use
4-
*TinyExpr++*, add those files to your project.
3+
*TinyExpr++* is self-contained in two files: "tinyexpr.cpp" and "tinyexpr.h".
4+
To use it, add those files to your project.
55

66
The API documentation can be built using the following:
77

docs/manual/comments.qmd

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ C/C++ style comments are supported, which provide:
66
- multi-line comments (text within a pair of `/*` and `*/`).
77
- single line comments (everything after a `//` until the end of the current line).
88

9-
For example, assuming that the variables `P_LEVEL` and `N_OBS` have been
10-
defined within the parser, an expression such as this could be used:
9+
For example, assuming that the variables `P_LEVEL` and `N_OBS` have been defined within the parser, an expression such as this could be used:
1110

1211
```{.cpp}
1312
/* Returns the p-level of a study if:

docs/manual/compile-time-options.qmd

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ This flag will also disable all bitwise functions and operators.
1515

1616
Compile with `TE_LONG_DOUBLE` defined to use `long double` as the default data type.
1717

18-
Depending on the compiler, this may provide support for handling `uint64_t` values. Call `te_parser::supports_64bit()`
19-
(or `SUPPORTS64BIT()` in an expression at runtime) to confirm this.
18+
Depending on the compiler, this may provide sufficient mantissa precision to represent ``uint64_t`` values exactly.
19+
Call `te_parser::supports_64bit()` (or `SUPPORTS64BIT()` in an expression at runtime) to confirm this.
2020

2121
## `TE_RAND_SEED` {-}
2222

23-
Define this as an unsigned integer to seed the random number generator with.
23+
Define this as an unsigned integer to seed the random number generator.
2424
This will affect the function `RAND()`, causing it to produce a deterministic series of numbers.
2525

2626
## `TE_RAND_SEED_TIME` {-}
@@ -32,8 +32,8 @@ The default is to seed the random number generator with `std::random_device`.
3232

3333
## `TE_BITWISE_OPERATORS` {-#te-bitwise-ops}
3434

35-
By default, the operators `&`, `|`, and `^` represent logical AND, logical OR, and exponentiation. If `TE_BITWISE_OPERATORS` is defined,
36-
then they will represent bitwise AND, OR, and XOR.
35+
By default, the operators `&`, `|`, and `^` represent logical AND, logical OR, and exponentiation.
36+
If `TE_BITWISE_OPERATORS` is defined, then they will represent bitwise AND, OR, and XOR.
3737

3838
## `TE_BRACKETS_AS_PARENS` {-}
3939

@@ -45,37 +45,34 @@ In this context, `rsp` could represent a memory address in the debugger.
4545
## `TE_NO_BOOKKEEPING` {-}
4646

4747
By default, the parser will keep track of all functions and variables used in the last expression it evaluated.
48-
From this, the presence of a function or variable in the expression can be verified via `is_function_used()`
49-
and `is_variable_used()`.
48+
From this, the presence of a function or variable in the expression can be verified via `is_function_used()` and `is_variable_used()`.
5049

5150
Turning this option off can provide a small optimization, as it will result in less heap allocations and search operations.
5251
Defining `TE_NO_BOOKKEEPING` will disable this feature.
5352

5453
## `TE_POW_FROM_RIGHT` {-}
5554

56-
By default, *TinyExpr++* does exponentiation from left to right. For example:
55+
By default, *TinyExpr++* does exponentiation from left to right.
56+
For example:
5757

5858
`a^b^c == (a^b)^c` and `-a^b == (-a)^b`
5959

60-
This is by design; it's the way that spreadsheets do it
61-
(e.g., *LibreOffice Calc*, *Excel*, *Google Sheets*).
60+
This is by design; it's the way that spreadsheets do it (e.g., *LibreOffice Calc*, *Excel*, *Google Sheets*).
6261

63-
If you would rather have exponentiation work from right to left, you need to
64-
define `TE_POW_FROM_RIGHT`\index{compiling!options} when compiling.
62+
If you would rather have exponentiation work from right to left, you need to define `TE_POW_FROM_RIGHT`\index{compiling!options} when compiling.
6563
With `TE_POW_FROM_RIGHT` defined, the behavior is:
6664

6765
`a^b^c == a^(b^c)` and `-a^b == -(a^b)`
6866

6967
That will match how many scripting languages do it (e.g., Python, Ruby).
7068

7169
::: {.tipsection data-latex=""}
72-
Symbols can be defined by passing them to your compiler's
73-
command line (or in a *CMake* configuration) as such: `-DTE_POW_FROM_RIGHT`
70+
Symbols can be defined by passing them to your compiler's command line (or in a *CMake* configuration) as such: `-DTE_POW_FROM_RIGHT`
7471
:::
7572

76-
## C++20 Features {-}
73+
## Rotation Features {-}
7774

78-
If compiling as C++20 (and `TE_FLOAT` is not defined), then the following functions and operators will be available:
75+
If `TE_FLOAT` is not defined, then the following functions and operators will be available:
7976

8077
- `BITLROTATE8`
8178
- `BITLROTATE16`

docs/manual/custom-extensions.qmd

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ int main(int argc, char* argv[])
4545
::: {.minipage data-latex="{\textwidth}"}
4646
## Binding to Custom Functions {-}
4747

48-
*TinyExpr++* can call custom functions\index{functions!binding to custom} also. Here is a short example:
48+
*TinyExpr++* can also call custom functions\index{functions!binding to custom}.
49+
Here is a short example:
4950

5051
```{.cpp}
5152
te_type my_sum(te_type a, te_type b)
@@ -82,8 +83,8 @@ const auto r = tep.evaluate("mysum(5, 6)");
8283
::: {.minipage data-latex="{\textwidth}"}
8384
## Binding to Custom Classes {-#custom-classes}
8485

85-
A class derived from `te_expr` can be bound to custom functions\index{classes!binding to custom}. This enables you to
86-
have full access to an object (via these functions) when parsing an expression.
86+
A class derived from `te_expr` can be bound to custom functions\index{classes!binding to custom}.
87+
This enables you to have full access to an object (via these functions) when parsing an expression.
8788

8889
The following demonstrates creating a `te_expr`-derived class which contains an array of values:
8990

@@ -97,8 +98,8 @@ public:
9798
};
9899
```
99100

100-
Next, create two functions that can accept this object and perform
101-
actions on it. (Note that proper error handling is not included for brevity.):
101+
Next, create two functions that can accept this object and perform actions on it.
102+
(Note that proper error handling is not included for brevity.):
102103

103104
```{.cpp}
104105
// Returns the value of a cell from the object's data.
@@ -117,8 +118,7 @@ te_type cell_max(const te_expr* context)
117118
}
118119
```
119120

120-
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:
122122

123123
```{.cpp}
124124
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)");
137137
138138
// call the other function, getting the object's max value
139139
// (will be 8)
140-
res = tep.evaluate("CellMax()");
140+
result = tep.evaluate("CellMax()");
141141
```
142142

143143
:::: {.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.
146145
::::
147146
:::
Lines changed: 26 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,13 @@
11
# Embedded Programming
22

3-
The following section discusses topics related to using *TinyExpr++* in an
4-
embedded environment\index{embedded systems}.
3+
The following section discusses topics related to using *TinyExpr++* in an embedded environment\index{embedded systems}.
54

65
## Performance {-}
76

87
*TinyExpr++* is fairly fast compared to compiled C when the expression is short or does hard calculations (e.g., exponentiation).
9-
*TinyExpr++* is slower compared to C when the expression is long and involves only basic arithmetic.
8+
It is slower compared to C when the expression is long and involves only basic arithmetic.
109

11-
Here are some example benchmarks:
12-
13-
| Expression | *TinyExpr++* | Native C | Comparison |
14-
| :------------- |-------------:| -----:|----:|
15-
| sqrt(a^1.5+a^2.5) | 1,707 ns | 58.25 ns | 29% slower |
16-
| a+5 | 535 ns | 0.67 ns | 798% slower |
17-
| (1/(a+1)+2/(a+2)+3/(a+3)) | 3,388 ns | 3.941 ns | 859% slower |
18-
19-
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.
2111

2212
Refer to [compile-time options](#compile-time-options) for flags that can provide optimization.
2313

@@ -28,12 +18,9 @@ To instead seed it with the current time, compile with `TE_RAND_SEED_TIME`.
2818

2919
## Volatility {-}
3020

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.
3422

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):
3724

3825
```{.cpp}
3926
te_parser tep;
@@ -46,8 +33,9 @@ void OnInterrupt()
4633
volatile te_parser& vTep = tep;
4734
}
4835
```
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:
5139

5240
```{.cpp}
5341
void OnInterrupt()
@@ -57,6 +45,8 @@ void OnInterrupt()
5745
vTep.set_decimal_separator('.');
5846
}
5947
```
48+
:::
49+
6050
The following functions in the `te_parser` class have `volatile` overloads:
6151

6252
- `get_result()`
@@ -67,8 +57,7 @@ The following functions in the `te_parser` class have `volatile` overloads:
6757
- `get_list_separator()`
6858
- `set_list_separator()`
6959

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:
7261

7362
```{.cpp}
7463
void OnInterrupt()
@@ -90,21 +79,18 @@ void OnInterrupt()
9079
}
9180
```
9281

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.
9683

9784
## Floating-point Numbers {-#fp-numbers}
9885

9986
`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.
10288

10389
When using this option, it is recommended to use the helper typedef `te_type`.
10490
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.
10792

93+
::: {.minipage data-latex="{\textwidth}"}
10894
For example, a custom function would be written as such:
10995

11096
```{.cpp}
@@ -127,26 +113,20 @@ tep.set_variables_and_functions({
127113
{ return a + b; } }
128114
});
129115
```
116+
:::
130117

131118
## Exception Handling {-}
132119

133-
*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.
139123

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.)
144126

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.
147128

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:
150130

151131
- `compile()`
152132
- `evaluate()`
@@ -155,13 +135,9 @@ in `try`/`catch` blocks:
155135
- `set_decimal_separator()`
156136
- `set_list_separator()`
157137

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.
160139

161140
## Virtual Functions {-}
162141

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.)

docs/manual/end-user-usage.qmd

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
11
# Usage
22

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:
44

55
```{.cpp}
66
ABS(((5+2) / (ABS(-2))) * -9 + 2) - 5^2
77
```
88

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:
1112

1213
```{.cpp}
1314
SUM(C1, C2, C3, D1, D2, D3)
1415
```
1516

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:
1819

1920
```{.cpp}
2021
IF(AND(P_LEVEL < .05, N_OBS >= 30),
@@ -43,10 +44,10 @@ IFS(AND(smartMeter1.power > 1900, sensor1.temperature < 52), TRUE,
4344
2. Neither scenario passed; return NaN because the values are in an unaccounted for scenario.
4445

4546
::: {.notesection data-latex=""}
46-
Expressions can optionally begin with an `=`, the same as spreadsheet programs. For example: \
47+
Expressions can optionally begin with an `=`, the same as spreadsheet programs.
48+
For example: \
4749

4850
`=SUM(C1, C2, C3, D1, D2, D3)`
4951
:::
5052

51-
Please consult your application's documentation for which custom
52-
variables and functions it may provide for its formulas.
53+
Please consult your application's documentation for which custom variables and functions it may provide for its formulas.

0 commit comments

Comments
 (0)