aboutsummaryrefslogtreecommitdiff
path: root/BigInt.c
diff options
context:
space:
mode:
authorSyndamia <kamen@syndamia.com>2026-05-28 09:51:28 +0300
committerSyndamia <kamen@syndamia.com>2026-07-12 09:14:06 +0300
commitdb41083fe6a15711f86cae849abe7413bedc6a13 (patch)
tree5a7272f8cb71b6a665e7813344e6896c23cc5565 /BigInt.c
parente68fef2645c69f4e89dd6175f94d71875c42ef7c (diff)
downloadfoollib-db41083fe6a15711f86cae849abe7413bedc6a13.tar
foollib-db41083fe6a15711f86cae849abe7413bedc6a13.tar.gz
foollib-db41083fe6a15711f86cae849abe7413bedc6a13.zip
feat: Implement bitwise operations
Diffstat (limited to 'BigInt.c')
-rw-r--r--BigInt.c59
1 files changed, 59 insertions, 0 deletions
diff --git a/BigInt.c b/BigInt.c
index 4323443..a1a617c 100644
--- a/BigInt.c
+++ b/BigInt.c
@@ -248,6 +248,65 @@ B_sub(BigInt *inta, BigInt intb) {
}
Result
+B_compl(BigInt *intx) {
+ if (NULL == intx)
+ return R_NullArgument;
+
+ struct BigIntMeta *xm = B_metadata(intx);
+ UWord *x = (void*)intx;
+
+ for (usize i = 0; i < xm->words; ++i)
+ x[i] = ~x[i];
+
+ return R_Ok;
+}
+
+Result
+B_bitand(BigInt *intx, BigInt *inty) {
+ if (NULL == intx || NULL == inty)
+ return R_NullArgument;
+
+ struct BigIntMeta *xm = B_metadata(intx), *ym = B_metadata(inty);
+ UWord *x = (void*)intx, *y = (void*)inty;
+
+ usize size = xm->words < ym->words ? xm->words : ym->words;
+ for (usize i = 0; i < size; ++i)
+ x[i] &= y[i];
+
+ return R_Ok;
+}
+
+Result
+B_bitor(BigInt *intx, BigInt *inty) {
+ if (NULL == intx || NULL == inty)
+ return R_NullArgument;
+
+ struct BigIntMeta *xm = B_metadata(intx), *ym = B_metadata(inty);
+ UWord *x = (void*)intx, *y = (void*)inty;
+
+ usize size = xm->words < ym->words ? xm->words : ym->words;
+ for (usize i = 0; i < size; ++i)
+ x[i] |= y[i];
+
+ return R_Ok;
+}
+
+Result
+B_bitxor(BigInt *intx, BigInt *inty) {
+ if (NULL == intx || NULL == inty)
+ return R_NullArgument;
+
+ struct BigIntMeta *xm = B_metadata(intx), *ym = B_metadata(inty);
+ UWord *x = (void*)intx, *y = (void*)inty;
+
+ usize size = xm->words < ym->words ? xm->words : ym->words;
+ for (usize i = 0; i < size; ++i)
+ x[i] ^= y[i];
+
+ return R_Ok;
+}
+
+Result
B_rshift(BigInt *intx, usize shift) {
if (NULL == intx || NULL == *intx)
return R_NullArgument;