Commit 32c91ad892
Changed files (2)
src
test
cases
src/bigint.cpp
@@ -50,7 +50,7 @@ size_t bigint_bits_needed(const BigInt *op) {
size_t full_bits = op->digit_count * 64;
size_t leading_zero_count = bigint_clz(op, full_bits);
size_t bits_needed = full_bits - leading_zero_count;
- return bits_needed + op->is_negative;
+ return bits_needed;
}
static void to_twos_complement(BigInt *dest, const BigInt *op, size_t bit_count) {
test/cases/eval.zig
@@ -737,3 +737,16 @@ test "slice bounds in comptime concatenation" {
assert(str2.len == 1);
assert(std.mem.eql(u8, str2, "1"));
}
+
+test "comptime bitwise operators" {
+ comptime {
+ assert(3 & 1 == 1);
+ assert(3 & -1 == 3);
+ assert(-3 & -1 == -3);
+ assert(3 | -1 == -1);
+ assert(-3 | -1 == -1);
+ assert(3 ^ -1 == -4);
+ assert(~i8(-1) == 0);
+ assert(~i128(-1) == 0);
+ }
+}