diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2024-09-02 19:29:43 -0400 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2024-09-02 19:29:43 -0400 |
| commit | 80a09e6dba7042271cba5372e31c2e5e86e58215 (patch) | |
| tree | cf28322474b8becfabb8af1c43a5af58fec15355 /builtins | |
| parent | a4454df4b93e2e2d071fe9e364318e3615fd7a98 (diff) | |
Fix up some integer and print statement stuff
Diffstat (limited to 'builtins')
| -rw-r--r-- | builtins/integers.c | 10 | ||||
| -rw-r--r-- | builtins/integers.h | 1 |
2 files changed, 7 insertions, 4 deletions
diff --git a/builtins/integers.c b/builtins/integers.c index 45db160d..44ecaf91 100644 --- a/builtins/integers.c +++ b/builtins/integers.c @@ -345,8 +345,7 @@ public Range_t Int$to(Int_t from, Int_t to) { return (Range_t){from, to, Int$compare(&to, &from, &$Int) >= 0 ? (Int_t){.small=(1<<2)|1} : (Int_t){.small=(-1>>2)|1}}; } -public Int_t Int$from_text(Text_t text, bool *success) { - const char *str = Text$as_c_string(text); +public Int_t Int$from_str(const char *str, bool *success) { mpz_t i; int result; if (strncmp(str, "0x", 2) == 0) { @@ -362,6 +361,10 @@ public Int_t Int$from_text(Text_t text, bool *success) { return Int$from_mpz(i); } +public Int_t Int$from_text(Text_t text, bool *success) { + return Int$from_str(Text$as_c_string(text), success); +} + public bool Int$is_prime(Int_t x, Int_t reps) { mpz_t p; @@ -406,8 +409,7 @@ public const TypeInfo $Int = { public Text_t KindOfInt ## $as_text(const c_type *i, bool colorize, const TypeInfo *type) { \ (void)type; \ if (!i) return Text$from_str(#KindOfInt); \ - Int_t as_int = KindOfInt##_to_Int(*i); \ - return Int$as_text(&as_int, colorize, type); \ + return Text$format(colorize ? "\x1b[35m%" fmt "\x1b[m" : "%" fmt, *i); \ } \ public int32_t KindOfInt ## $compare(const c_type *x, const c_type *y, const TypeInfo *type) { \ (void)type; \ diff --git a/builtins/integers.h b/builtins/integers.h index 359b1d57..6e2a1fe6 100644 --- a/builtins/integers.h +++ b/builtins/integers.h @@ -82,6 +82,7 @@ Text_t Int$octal(Int_t i, Int_t digits, bool prefix); void Int$init_random(long seed); Int_t Int$random(Int_t min, Int_t max); Range_t Int$to(Int_t from, Int_t to); +Int_t Int$from_str(const char *str, bool *success); Int_t Int$from_text(Text_t text, bool *success); Int_t Int$abs(Int_t x); Int_t Int$power(Int_t base, Int_t exponent); |
