aboutsummaryrefslogtreecommitdiff
path: root/stdlib/integers.h
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2024-11-03 15:04:28 -0500
committerBruce Hill <bruce@bruce-hill.com>2024-11-03 15:04:28 -0500
commit87176ead2de2b0eb396d75555b3ed2bd5783ce8d (patch)
tree238aa79fb1e5e6fb9bba69a774f96e97550842af /stdlib/integers.h
parent87d3bf928a9e7ff5d5cd0abba4af7e9bc154a2b0 (diff)
Add wrapping plus/minus for fixed-size integers
Diffstat (limited to 'stdlib/integers.h')
-rw-r--r--stdlib/integers.h6
1 files changed, 6 insertions, 0 deletions
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__(()))