aboutsummaryrefslogtreecommitdiff
path: root/unused.jai
diff options
context:
space:
mode:
authordam <dam@gudinoff>2023-01-25 00:26:24 +0000
committerdam <dam@gudinoff>2023-01-25 00:26:24 +0000
commite7cdf6fe804e1c01179afc3e40b761144cd0b057 (patch)
tree122cd35ee730bbcdb89ff252e1ce65f4dc92e06c /unused.jai
parentbb62e6e9f46f2009a9b09d8b3f106a7470ffb0f2 (diff)
downloadtask-time-tracker-e7cdf6fe804e1c01179afc3e40b761144cd0b057.tar.zst
task-time-tracker-e7cdf6fe804e1c01179afc3e40b761144cd0b057.zip
Ported add_int64 and sub_int64 to jai.
Diffstat (limited to 'unused.jai')
-rw-r--r--unused.jai50
1 files changed, 50 insertions, 0 deletions
diff --git a/unused.jai b/unused.jai
new file mode 100644
index 0000000..3529a46
--- /dev/null
+++ b/unused.jai
@@ -0,0 +1,50 @@
+checked_add :: (a: $T, b: T) -> result: T, overflow: bool
+#modify {
+ if T.type == .INTEGER return;
+ T = null;
+}
+{
+ overflow: bool;
+ result: T = a + b;
+
+ info := type_info(T);
+ if info.signed {
+ // (+A) + (+B) = −C
+ // (−A) + (−B) = +C
+ if ((a > 0) && (b > 0) && (result < 0)) || ((a < 0) && (b < 0) && (result > 0)) {
+ overflow = true;
+ }
+ } else {
+ if result < a {
+ overflow = true;
+ }
+ }
+
+ return result, overflow;
+}
+
+checked_sub :: (a: $T, b: T) -> result: T, overflow: bool
+#modify {
+ if T.type == .INTEGER return;
+ T = null;
+}
+{
+ overflow: bool;
+ result: T = a - b;
+
+ info := type_info(T);
+ if info.signed {
+ // (+A) − (−B) = −C
+ // (−A) − (+B) = +C
+ if ((a > 0) && (b < 0) && (result < 0)) || ((a < 0) && (b > 0) && (result > 0)) {
+ overflow = true;
+ }
+ } else {
+ if result > a {
+ overflow = true;
+ }
+ }
+
+ return result, overflow;
+}
+