From 87176ead2de2b0eb396d75555b3ed2bd5783ce8d Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Sun, 3 Nov 2024 15:04:28 -0500 Subject: Add wrapping plus/minus for fixed-size integers --- stdlib/integers.h | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'stdlib') diff --git a/stdlib/integers.h b/stdlib/integers.h index 4214c2fa..2293e065 100644 --- a/stdlib/integers.h +++ b/stdlib/integers.h @@ -60,6 +60,12 @@ } \ MACROLIKE c_type type_name ## $modulo1(c_type D, c_type d) { \ return type_name ## $modulo(D-1, d) + 1; \ + } \ + MACROLIKE PUREFUNC c_type type_name ## $wrapping_plus(c_type x, c_type y) { \ + return (c_type)((u##c_type)x + (u##c_type)y); \ + } \ + MACROLIKE PUREFUNC c_type type_name ## $wrapping_minus(c_type x, c_type y) { \ + return (c_type)((u##c_type)x + (u##c_type)y); \ } DEFINE_INT_TYPE(int64_t, Int64, __attribute__(())) -- cgit v1.2.3