diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2025-04-07 01:17:02 -0400 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2025-04-07 01:17:02 -0400 |
| commit | f857f38f718fff586e373815a1bcad2701b4d983 (patch) | |
| tree | 29b3e367437099f39f6fc9a4e7d1dd2f177afb59 /src/stdlib/integers.h | |
| parent | fb4e4cef1382a5e37d99ccb8e97fe1d2a8cd7e93 (diff) | |
Add `is_between()` for various types
Diffstat (limited to 'src/stdlib/integers.h')
| -rw-r--r-- | src/stdlib/integers.h | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/src/stdlib/integers.h b/src/stdlib/integers.h index 8988e7c8..12fec62b 100644 --- a/src/stdlib/integers.h +++ b/src/stdlib/integers.h @@ -33,6 +33,9 @@ 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); \ } \ @@ -93,6 +96,9 @@ 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; +} 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); |
