Skip to content

Commit

Permalink
Document hexadecimal support
Browse files Browse the repository at this point in the history
Closes #15
#13
  • Loading branch information
Blake-Madden committed Mar 14, 2024
1 parent 2e67b20 commit d8e24d9
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -430,9 +430,9 @@ In addition, whitespace between tokens is ignored.

Valid variable names consist of a letter or underscore followed by any combination
of: letters `a``z` or `A``Z`, digits `0``9`, periods, and
underscores. Constants can be integers, decimal numbers, or in scientific
notation (e.g., `1e3` for `1000`). A leading zero is not required (e.g., `.5`
for `0.5`).
underscores. Constants can be integers or floating-point numbers, and can be in decimal,
hexadecimal (e.g., `0x57CEF7`), or scientific notation (e.g., `1e3` for `1000`).
A leading zero is not required (e.g., `.5` for `0.5`).

## Supported Functions

Expand Down
10 changes: 6 additions & 4 deletions docs/manual/constants.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ The following mathematical and logical constants\index{constants} are available:
::: {.minipage data-latex="{\textwidth}"}
| Constant | Value |
| :------------- |:------------ |
| E | Euler's number (`2.71828182845904523536`) |
| E | Euler's number (`2.71828182845904523536`) |
| NAN | NaN (Not-a-Number) |
| PI | pi (`3.14159265358979323846`) |
| PI | pi (`3.14159265358979323846`) |

Table: Math Constants
:::
Expand All @@ -19,7 +19,7 @@ If [`TE_FLOAT`](#te-float) is defined, then some precision for pi and Euler's nu
::: {.minipage data-latex="{\textwidth}"}
| Constant | Value |
| :------------- |:------------ |
| TRUE | `1` |
| TRUE | `1` |
| FALSE | `0` |

Table: Logical Constants
Expand All @@ -30,7 +30,9 @@ The following number formats are supported:
::: {.minipage data-latex="{\textwidth}"}
| Format | Example |
| :------------- |:------------ |
| Scientific notation\index{scientific notation} | `1e3` for `1000` |
| Decimal | `5754615` or `3.14` |
| Hexadecimal\index{hexadecimal} | `0x57CEF7`, which yields `5754615` |
| Scientific notation\index{scientific notation} | `1e3`, which yields `1000` |

Table: Number Formats
:::
13 changes: 13 additions & 0 deletions tests/tetests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -757,6 +757,19 @@ TEST_CASE("Zeros", "[zeros]")
CHECK(std::isnan(tep.evaluate("(1%0)%1")));
}

TEST_CASE("Hex", "[hex]")
{
te_parser tep;

CHECK(tep.evaluate("0x0") == 0);
CHECK(tep.evaluate("0x8") == 8);
CHECK(tep.evaluate("0x1FFFFFFFFFFFFF") == 9007199254740991);
CHECK(tep.evaluate("0x57CEF7") == 5754615);
CHECK(tep.evaluate("0x57CEF7") == 5754615);
CHECK(tep.evaluate("-0X57CEF7") == -5754615);
CHECK(std::isnan(tep.evaluate("0X")));
}

TEST_CASE("UINT support", "[uint]")
{
te_parser tep;
Expand Down

0 comments on commit d8e24d9

Please sign in to comment.