diff --git a/README.md b/README.md index 09e07b9..75483ac 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/docs/manual/constants.qmd b/docs/manual/constants.qmd index d5cd851..61d701a 100644 --- a/docs/manual/constants.qmd +++ b/docs/manual/constants.qmd @@ -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 ::: @@ -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 @@ -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 ::: diff --git a/tests/tetests.cpp b/tests/tetests.cpp index dd7e4a1..6acfa0e 100644 --- a/tests/tetests.cpp +++ b/tests/tetests.cpp @@ -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;