mirror of
https://codeberg.org/andyscott/ziglings.git
synced 2024-12-22 22:13:11 -05:00
Merge pull request #157 from chrboesch/e64
fixed: https://github.com/ratfactor/ziglings/issues/156
This commit is contained in:
commit
318873a0fc
1 changed files with 2 additions and 4 deletions
|
@ -38,14 +38,12 @@ pub fn main() void {
|
||||||
// Let's try it with a tiny 4-bit integer size to make it clear:
|
// Let's try it with a tiny 4-bit integer size to make it clear:
|
||||||
const a: u4 = 0b1101;
|
const a: u4 = 0b1101;
|
||||||
const b: u4 = 0b0101;
|
const b: u4 = 0b0101;
|
||||||
var my_result: u4 = undefined;
|
const my_result = @addWithOverflow(a, b);
|
||||||
var overflowed: bool = undefined;
|
|
||||||
overflowed = @addWithOverflow(u4, a, b, &my_result);
|
|
||||||
|
|
||||||
// Check out our fancy formatting! b:0>4 means, "print
|
// Check out our fancy formatting! b:0>4 means, "print
|
||||||
// as a binary number, zero-pad right-aligned four digits."
|
// as a binary number, zero-pad right-aligned four digits."
|
||||||
// The print() below will produce: "1101 + 0101 = 0010 (true)".
|
// The print() below will produce: "1101 + 0101 = 0010 (true)".
|
||||||
print("{b:0>4} + {b:0>4} = {b:0>4} ({})", .{ a, b, my_result, overflowed });
|
print("{b:0>4} + {b:0>4} = {b:0>4} ({s})", .{ a, b, my_result[0], if (my_result[1] == 1) "true" else "false" });
|
||||||
|
|
||||||
// Let's make sense of this answer. The value of 'b' in decimal is 5.
|
// Let's make sense of this answer. The value of 'b' in decimal is 5.
|
||||||
// Let's add 5 to 'a' but go one by one and see where it overflows:
|
// Let's add 5 to 'a' but go one by one and see where it overflows:
|
||||||
|
|
Loading…
Reference in a new issue