aboutsummaryrefslogtreecommitdiff
path: root/builtins/range.c
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2024-08-13 01:30:25 -0400
committerBruce Hill <bruce@bruce-hill.com>2024-08-13 01:30:25 -0400
commitd08f795794b33a5d52e39c6b9f0c4e6e88fede3d (patch)
tree7267e0828b73685f9af0c3e9cf58212c45af289c /builtins/range.c
parentc1c889b024529ac754f83caec4cc15971123d07b (diff)
Partially working first draft of bigints
Diffstat (limited to 'builtins/range.c')
-rw-r--r--builtins/range.c22
1 files changed, 13 insertions, 9 deletions
diff --git a/builtins/range.c b/builtins/range.c
index ced2a26f..840397b9 100644
--- a/builtins/range.c
+++ b/builtins/range.c
@@ -2,6 +2,7 @@
#include <ctype.h>
#include <err.h>
+#include <gmp.h>
#include <gc.h>
#include <gc/cord.h>
#include <math.h>
@@ -11,23 +12,24 @@
#include <sys/param.h>
#include "types.h"
+#include "integers.h"
#include "util.h"
static int32_t Range$compare(const Range_t *x, const Range_t *y, const TypeInfo *type)
{
(void)type;
- int32_t diff = (x->first > y->first) - (x->first < y->first);
+ int32_t diff = Int$compare(&x->first, &y->first, &$Int);
if (diff != 0) return diff;
- diff = (x->last > y->last) - (x->last < y->last);
+ diff = Int$compare(&x->last, &y->last, &$Int);
if (diff != 0) return diff;
- return (x->step > y->step) - (x->step < y->step);
+ return Int$compare(&x->step, &y->step, &$Int);
}
static bool Range$equal(const Range_t *x, const Range_t *y, const TypeInfo *type)
{
(void)type;
- return (x->first == y->first) && (x->last == y->last) && (x->step == y->step);
+ return Int$equal(&x->first, &y->first, &$Int) && Int$equal(&x->last, &y->last, &$Int) && Int$equal(&x->step, &y->step, &$Int);
}
static CORD Range$as_text(const Range_t *r, bool use_color, const TypeInfo *type)
@@ -35,18 +37,20 @@ static CORD Range$as_text(const Range_t *r, bool use_color, const TypeInfo *type
(void)type;
if (!r) return "Range";
- return CORD_asprintf(use_color ? "\x1b[0;1mRange\x1b[m(first=\x1b[35m%ld\x1b[m, last=\x1b[35m%ld\x1b[m, step=\x1b[35m%ld\x1b[m)"
- : "Range(first=%ld, last=%ld, step=%ld)", r->first, r->last, r->step);
+ return CORD_asprintf(use_color ? "\x1b[0;1mRange\x1b[m(first=%r, last=%r, step=%r)"
+ : "Range(first=%r, last=%r, step=%r)",
+ Int$as_text(&r->first, use_color, &$Int), Int$as_text(&r->last, use_color, &$Int),
+ Int$as_text(&r->step, use_color, &$Int));
}
public Range_t Range$reversed(Range_t r)
{
- return (Range_t){r.last, r.first, -r.step};
+ return (Range_t){r.last, r.first, Int$negative(r.step)};
}
-public Range_t Range$by(Range_t r, int64_t step)
+public Range_t Range$by(Range_t r, Int_t step)
{
- return (Range_t){r.first, r.last, step*r.step};
+ return (Range_t){r.first, r.last, Int$times(step, r.step)};
}
public const TypeInfo Range = {sizeof(Range_t), __alignof(Range_t), {.tag=CustomInfo, .CustomInfo={