From a7b024edd7ba14d4656c25928f8324fad071b7d1 Mon Sep 17 00:00:00 2001 From: radj307 Date: Thu, 3 Mar 2022 19:10:17 -0500 Subject: [PATCH] shorten the logic for negated operations, fix logic bugs in strmath.hpp --- 307lib | 2 +- convlib/include/tokenizers/bitwise.hpp | 30 +++----------------------- 2 files changed, 4 insertions(+), 28 deletions(-) diff --git a/307lib b/307lib index 01fa61f..93f2936 160000 --- a/307lib +++ b/307lib @@ -1 +1 @@ -Subproject commit 01fa61f113a8a095ffe13e262d52bc35d1226921 +Subproject commit 93f2936c09c6a991538a9da6bac6a9a67b822dcb diff --git a/convlib/include/tokenizers/bitwise.hpp b/convlib/include/tokenizers/bitwise.hpp index 75befb1..419e54f 100644 --- a/convlib/include/tokenizers/bitwise.hpp +++ b/convlib/include/tokenizers/bitwise.hpp @@ -193,39 +193,15 @@ namespace bitwise { long long operator&(const Operand& o) const { - if (negated && !o.negated) - return ~value & o.value; - else if (!negated && !o.negated) - return value & o.value; - else if (!negated && o.negated) - return value & ~o.value; - else if (negated && o.negated) - return ~value & ~o.value; - else throw make_exception("Unhandled operation"); + return (negated ? ~value : value) & (o.negated ? ~o.value : o.value); } long long operator|(const Operand& o) const { - if (negated && !o.negated) - return ~value | o.value; - else if (!negated && !o.negated) - return value | o.value; - else if (!negated && o.negated) - return value | ~o.value; - else if (negated && o.negated) - return ~value | ~o.value; - else throw make_exception("Unhandled operation"); + return (negated ? ~value : value) | (o.negated ? ~o.value : o.value); } long long operator^(const Operand& o) const { - if (negated && !o.negated) - return ~value ^ o.value; - else if (!negated && !o.negated) - return value ^ o.value; - else if (!negated && o.negated) - return value ^ ~o.value; - else if (negated && o.negated) - return ~value ^ ~o.value; - else throw make_exception("Unhandled operation"); + return (negated ? ~value : value) ^ (o.negated ? ~o.value : o.value); } friend std::ostream& operator<<(std::ostream& os, const Operand& op)