Skip to content

Commit d8e24d9

Browse files
committed
Document hexadecimal support
Closes Blake-Madden#15 Blake-Madden#13
1 parent 2e67b20 commit d8e24d9

File tree

3 files changed

+22
-7
lines changed

3 files changed

+22
-7
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -430,9 +430,9 @@ In addition, whitespace between tokens is ignored.
430430

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

437437
## Supported Functions
438438

docs/manual/constants.qmd

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ The following mathematical and logical constants\index{constants} are available:
55
::: {.minipage data-latex="{\textwidth}"}
66
| Constant | Value |
77
| :------------- |:------------ |
8-
| E | Euler's number (`2.71828182845904523536`) |
8+
| E | Euler's number (`2.71828182845904523536`) |
99
| NAN | NaN (Not-a-Number) |
10-
| PI | pi (`3.14159265358979323846`) |
10+
| PI | pi (`3.14159265358979323846`) |
1111

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

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

3537
Table: Number Formats
3638
:::

tests/tetests.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -757,6 +757,19 @@ TEST_CASE("Zeros", "[zeros]")
757757
CHECK(std::isnan(tep.evaluate("(1%0)%1")));
758758
}
759759

760+
TEST_CASE("Hex", "[hex]")
761+
{
762+
te_parser tep;
763+
764+
CHECK(tep.evaluate("0x0") == 0);
765+
CHECK(tep.evaluate("0x8") == 8);
766+
CHECK(tep.evaluate("0x1FFFFFFFFFFFFF") == 9007199254740991);
767+
CHECK(tep.evaluate("0x57CEF7") == 5754615);
768+
CHECK(tep.evaluate("0x57CEF7") == 5754615);
769+
CHECK(tep.evaluate("-0X57CEF7") == -5754615);
770+
CHECK(std::isnan(tep.evaluate("0X")));
771+
}
772+
760773
TEST_CASE("UINT support", "[uint]")
761774
{
762775
te_parser tep;

0 commit comments

Comments
 (0)