From 630f910563b6f27dd34a4a0496a43d32539eadcb Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Sat, 15 Nov 2025 14:33:15 -0500 Subject: Incremental fixes --- src/stdlib/bigint.c | 8 ++++---- src/stdlib/reals.c | 10 +++++----- src/stdlib/text.h | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) (limited to 'src/stdlib') diff --git a/src/stdlib/bigint.c b/src/stdlib/bigint.c index 5e8986d1..41e8e6db 100644 --- a/src/stdlib/bigint.c +++ b/src/stdlib/bigint.c @@ -418,22 +418,22 @@ OptionalInt_t Int$parse(Text_t text, Text_t *remainder) { const char *end = str + 2 + strspn(str + 2, "0123456789abcdefABCDEF"); if (remainder) *remainder = Text$from_str(end); else if (*end != '\0') return NONE_INT; - result = mpz_init_set_str(i, str + 2, 16); + result = mpz_init_set_str(i, String(string_slice(str + 2, (size_t)(end - (str + 2)))), 16); } else if (strncmp(str, "0o", 2) == 0) { const char *end = str + 2 + strspn(str + 2, "01234567"); if (remainder) *remainder = Text$from_str(end); else if (*end != '\0') return NONE_INT; - result = mpz_init_set_str(i, str + 2, 8); + result = mpz_init_set_str(i, String(string_slice(str + 2, (size_t)(end - (str + 2)))), 8); } else if (strncmp(str, "0b", 2) == 0) { const char *end = str + 2 + strspn(str + 2, "01"); if (remainder) *remainder = Text$from_str(end); else if (*end != '\0') return NONE_INT; - result = mpz_init_set_str(i, str + 2, 2); + result = mpz_init_set_str(i, String(string_slice(str + 2, (size_t)(end - (str + 2)))), 2); } else { const char *end = str + strspn(str, "0123456789"); if (remainder) *remainder = Text$from_str(end); else if (*end != '\0') return NONE_INT; - result = mpz_init_set_str(i, str, 10); + result = mpz_init_set_str(i, String(string_slice(str, (size_t)(end - str))), 10); } if (result != 0) { if (remainder) *remainder = text; diff --git a/src/stdlib/reals.c b/src/stdlib/reals.c index 1c4be751..cfa027d1 100644 --- a/src/stdlib/reals.c +++ b/src/stdlib/reals.c @@ -67,13 +67,13 @@ static Int_t Real$compute_double(Real_t r, int64_t precision) { public OptionalReal_t Real$parse(Text_t text, Text_t *remainder) { - Text_t decimal_onwards; + Text_t decimal_onwards = EMPTY_TEXT; OptionalInt_t int_component = Int$parse(text, &decimal_onwards); if (int_component.small == 0) int_component = I(0); - Text_t fraction_text; + Text_t fraction_text = EMPTY_TEXT; if (Text$starts_with(decimal_onwards, Text("."), &fraction_text)) { fraction_text = Text$replace(fraction_text, Text("_"), EMPTY_TEXT); - OptionalInt_t fraction = Int$parse(decimal_onwards, remainder); + OptionalInt_t fraction = Int$parse(fraction_text, remainder); if (fraction.small == 0) return NONE_REAL; int64_t shift = fraction_text.length; Int_t scale = Int$power(I(10), I(shift)); @@ -106,9 +106,9 @@ double Real$as_float64(Real_t x) { if (((orig_exp + exp_adj) & ~0x7fful) != 0) { // overflow if (scaled_int.d < 0.0) { - return -INFINITY; + return (double)-INFINITY; } else { - return INFINITY; + return (double)INFINITY; } } scaled_int.bits += exp_adj << 52; diff --git a/src/stdlib/text.h b/src/stdlib/text.h index 2046d667..37ed056a 100644 --- a/src/stdlib/text.h +++ b/src/stdlib/text.h @@ -44,7 +44,7 @@ static inline Text_t Text_from_text(Text_t t) { return t; } int16_t: Int16$value_as_text, \ int32_t: Int32$value_as_text, \ int64_t: Int64$value_as_text, \ - double: Float64$value_as_text, \ + double: Float64$value_as_text, \ float: Float32$value_as_text)(x) Text_t Text$_concat(int n, Text_t items[n]); -- cgit v1.2.3