aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author_ov4 <ov4@ov4.org>2026-10-23 01:21:23 +0000
committer_ov4 <ov4@ov4.org>2026-10-23 01:21:23 +0000
commita0dba2acdeb6e2e9af8e53a4d886fba79c7a3afe (patch)
treedd2ee26ba4fe80999d509daa1b96888b76c90dbb
parent90fc80c193453e8d5038530f310fc007f9ff9789 (diff)
feat(stdlib): add a CHAR overload of STR_TO_NUM
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
-rw-r--r--doc/language/function/cpsc-function-str_to_num.7.md1
-rw-r--r--pseudocode-lib/README.md2
-rw-r--r--pseudocode-lib/string.cps6
3 files changed, 7 insertions, 2 deletions
diff --git a/doc/language/function/cpsc-function-str_to_num.7.md b/doc/language/function/cpsc-function-str_to_num.7.md
index 48d24db..a9d008b 100644
--- a/doc/language/function/cpsc-function-str_to_num.7.md
+++ b/doc/language/function/cpsc-function-str_to_num.7.md
@@ -8,6 +8,7 @@ cpsc-function-str_to_num - convert text to a real number
```text
STR_TO_NUM(text : STRING) RETURNS REAL
+STR_TO_NUM(text : CHAR) RETURNS REAL
```
# DESCRIPTION
diff --git a/pseudocode-lib/README.md b/pseudocode-lib/README.md
index f3c683f..dbdebf3 100644
--- a/pseudocode-lib/README.md
+++ b/pseudocode-lib/README.md
@@ -35,7 +35,7 @@ The library provides `&`, six case-sensitive content comparisons, and these ordi
- `ASC(CHAR)` and `ASC(STRING)` return the unsigned character or first-byte code; an empty string returns zero.
- `CHR(Code)` returns a CHAR containing the low eight bits. `LENGTH(CHR(0))` is 1.
- `NUM_TO_STR(INTEGER)` and `NUM_TO_STR(REAL)` convert INTEGER to decimal text and REAL to the shortest round-trip text (Python `repr` style, identical to OUTPUT: `2.0`, `0.1`, `1e-07`, `inf`).
-- `STR_TO_NUM(S)` returns REAL through the same `parseNumber` helper as IS_NUM (`strtod`, full consumption). Invalid text and trailing junk throw `STR_TO_NUM: '<text>' is not a number`; overflow throws `... is out of the REAL range`; underflow is accepted.
+- `STR_TO_NUM(S)` accepts STRING or CHAR and returns REAL through the same `parseNumber` helper as IS_NUM (`strtod`, full consumption). Invalid text and trailing junk throw `STR_TO_NUM: '<text>' is not a number`; overflow throws `... is out of the REAL range`; underflow is accepted.
- `IS_NUM(S)` agrees with STR_TO_NUM: full consumption by `strtod` and no overflow, without throwing. Leading whitespace is accepted; trailing whitespace, trailing junk, empty input, embedded NUL bytes, and overflowing values (`1e999`) are rejected.
Library C++ exceptions print the user call line and can be caught with TRY/CATCH. Library functions follow the guide where specified; LEFT, STRING case conversion, byte-code and numeric-conversion functions remain compatibility extensions.
diff --git a/pseudocode-lib/string.cps b/pseudocode-lib/string.cps
index 1ad63d3..cb06758 100644
--- a/pseudocode-lib/string.cps
+++ b/pseudocode-lib/string.cps
@@ -78,9 +78,13 @@ OVERLOAD FUNCTION NUM_TO_STR(Number : REAL) RETURNS STRING
CALL _string_impl_from_real(Result._HANDLE, (C_DOUBLE)Number)
RETURN Result
ENDFUNCTION
-FUNCTION STR_TO_NUM(S : STRING) RETURNS REAL
+OVERLOAD FUNCTION STR_TO_NUM(S : STRING) RETURNS REAL
RETURN (REAL)_string_impl_to_real(S._HANDLE)
ENDFUNCTION
+OVERLOAD FUNCTION STR_TO_NUM(C : CHAR) RETURNS REAL
+ DECLARE S : STRING(1, (C_CHAR)C)
+ RETURN STR_TO_NUM(S)
+ENDFUNCTION
FUNCTION LENGTH(S : STRING) RETURNS INTEGER
RETURN (INTEGER)_string_impl_length(S._HANDLE)
ENDFUNCTION