Skip to content

Commit

Permalink
Combine topics in help, minor edits
Browse files Browse the repository at this point in the history
  • Loading branch information
Blake-Madden committed Oct 22, 2023
1 parent 28025d5 commit c1c6a24
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 33 deletions.
6 changes: 3 additions & 3 deletions docs/manual/09-EndUserUsage.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ IF(AND(smartMeter1.power > 1900, sensor1.temperature < 52), TRUE,
// First logical check failed, so now check another scenario
// and return false if it meets our criteria.
IF(AND(smartMeter1.power < 300, sensor1.temperature > 55), FALSE,
// Neither scenario checked out, so the values are in an
// unaccounted for scenario. Return NaN to indicate a failure.
NAN) )
// Neither scenario checked out, so the values are in an
// unaccounted for scenario. Return NaN to indicate a failure.
NAN) )
```
:::

Expand Down
19 changes: 19 additions & 0 deletions docs/manual/21-Usage.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,22 @@ else
Along with positional and message information, the return value\index{results!evaluating failed} of a parse can also indicate failure.
When an evaluation fails, the parser will return NaN (i.e., `std::numeric_limits<double>::quiet_NaN()`) as the result.
NaN values can be verified using the standard function `std::isnan()`.
## Example {-}
The following is a short example demonstrating how to use *TinyExpr++*.
```cpp
#include "tinyexpr.h"
#include <iostream>
int main(int argc, char *argv[])
{
te_parser tep;
const char* expression = "sqrt(5^2+7^2+11^2+(8-2)^2)";
const double res = tep.evaluate(expression);
std::cout << "The expression:\n\t" <<
expression << "\nevaluates to:\n\t" << res << "\n";
return EXIT_SUCCESS;
}
```
18 changes: 0 additions & 18 deletions docs/manual/22-Examples.Rmd

This file was deleted.

15 changes: 5 additions & 10 deletions docs/manual/23-CustomExtensions.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
## Binding to Custom Variables {-}

::: {.minipage data-latex="{\textwidth}"}
Along with the built-in functions and constants, you can create custom variables\index{variables!binding to custom} for use in expressions. For example:
Along with the built-in functions and constants, you can create custom variables\index{variables!binding to custom} for use in expressions:

```cpp
#include "tinyexpr.h"
Expand All @@ -17,28 +17,23 @@ int main(int argc, char* argv[])
std::cout << "Usage: example \"expression\"\n";
return EXIT_SUCCESS;
}

const char* expression = argv[1];
std::cout << "Evaluating:\n\t" << expression << "\n";

/* The variables x and y are bound at eval-time. */
double x{ 0 }, y{ 0 };
double x{ 0 }, y{ 0 }; // x and y are bound at eval-time.
// Store variable names and pointers.
te_parser tep;
tep.set_variables_and_functions({ {"x", &x}, {"y", &y} });

/* This will compile the expression and check for errors. */
if (tep.compile(expression))
if (tep.compile(expression)) // Compile the expression and check for errors.
{
/* The variables can be changed here, and evaluate can be called multiple
times. This is efficient because the parsing has already been done.*/
x = 3; y = 4;
const double r = tep.evaluate();
std::cout << "Result:\n\t" << r << "\n";
}
else
else // Show the user where the error is at.
{
/* Show the user where the error is at. */
std::cout << "\t " << std::setfill(' ') <<
std::setw(tep.get_last_error_position()) << '^' << "\tError here\n";
}
Expand Down Expand Up @@ -147,6 +142,6 @@ res = tep.evaluate("CellMax()");

:::: {.notesection data-latex=""}
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.
of: letters `az` or `AZ`, digits `09`, periods, and underscores.
::::
:::
4 changes: 2 additions & 2 deletions docs/manual/24-UnknownSymbolResolution.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ tep.evaluate("RESOLUTION * 3");
:::

::: {.warningsection data-latex=""}
Although TinyExpr++ is case insensitive, it is your USR's responsibility to process
Although *TinyExpr++* is case insensitive, it is your USR's responsibility to process
case-insensitively when resolving names. Once a name has been resolved, then the parser
will recognize it case-insensitively in future evaluations.
:::
Expand Down Expand Up @@ -138,7 +138,7 @@ This will force the same unknown symbols to be resolved again with every evaluat
This can be useful for when your USR's symbol resolutions are dynamic and may change with each call.
::: {.minipage data-latex="{\textwidth}"}
For example, say that an end user will enter variables that start with "STRESS", but you are uncertain what the full name will be.
For example, say that an end user will enter variables that start with "STRESS," but you are uncertain what the full name will be.
Additionally, you want to increase the values of these variables with every evaluation. The following demonstrates this:
```cpp
Expand Down

0 comments on commit c1c6a24

Please sign in to comment.