From 82f5f05bb9440b758ae5e4a7c168e36ecff06db5 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Mon, 7 Apr 2025 03:21:58 -0400 Subject: Move clamped() and is_between() to proper functions (not just macros) --- src/stdlib/integers.h | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) (limited to 'src/stdlib/integers.h') diff --git a/src/stdlib/integers.h b/src/stdlib/integers.h index 12fec62b..c7643a8d 100644 --- a/src/stdlib/integers.h +++ b/src/stdlib/integers.h @@ -33,12 +33,8 @@ Closure_t type_name ## $to(c_type first, c_type last, Optional ## type_name ## _t step); \ Closure_t type_name ## $onward(c_type first, c_type step); \ PUREFUNC Optional ## type_name ## _t type_name ## $parse(Text_t text); \ - MACROLIKE CONSTFUNC bool type_name ## $is_between(const c_type x, const c_type low, const c_type high) { \ - return low <= x && x <= high; \ - } \ - MACROLIKE PUREFUNC c_type type_name ## $clamped(c_type x, c_type min, c_type max) { \ - return x < min ? min : (x > max ? max : x); \ - } \ + CONSTFUNC bool type_name ## $is_between(const c_type x, const c_type low, const c_type high); \ + CONSTFUNC c_type type_name ## $clamped(c_type x, c_type min, c_type max); \ MACROLIKE CONSTFUNC c_type type_name ## $from_byte(Byte_t b) { return (c_type)b; } \ MACROLIKE CONSTFUNC c_type type_name ## $from_bool(Bool_t b) { return (c_type)b; } \ CONSTFUNC c_type type_name ## $gcd(c_type x, c_type y); \ @@ -96,9 +92,8 @@ Text_t Int$value_as_text(Int_t i); PUREFUNC uint64_t Int$hash(const void *x, const TypeInfo_t *type); PUREFUNC int32_t Int$compare(const void *x, const void *y, const TypeInfo_t *type); PUREFUNC int32_t Int$compare_value(const Int_t x, const Int_t y); -MACROLIKE CONSTFUNC bool Int$is_between(const Int_t x, const Int_t low, const Int_t high) { - return Int$compare_value(low, x) <= 0 && Int$compare_value(x, high) <= 0; -} +CONSTFUNC bool Int$is_between(const Int_t x, const Int_t low, const Int_t high); +CONSTFUNC Int_t Int$clamped(Int_t x, Int_t low, Int_t high); PUREFUNC bool Int$equal(const void *x, const void *y, const TypeInfo_t *type); PUREFUNC bool Int$equal_value(const Int_t x, const Int_t y); Text_t Int$format(Int_t i, Int_t digits); @@ -157,10 +152,6 @@ Int_t Int$factorial(Int_t n); extern const TypeInfo_t Int$info; -MACROLIKE PUREFUNC Int_t Int$clamped(Int_t x, Int_t low, Int_t high) { - return (Int$compare(&x, &low, &Int$info) <= 0) ? low : (Int$compare(&x, &high, &Int$info) >= 0 ? high : x); -} - // Fast-path inline versions for the common case where integer arithmetic is // between two small ints. -- cgit v1.2.3