Merge branch 'main' into exercise_060_f80

This commit is contained in:
Chris Boesch 2023-01-14 13:36:33 +01:00 committed by GitHub
commit 10e6abc1a1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 12 additions and 11 deletions

View file

@ -17,7 +17,7 @@ pub fn main() void {
var num: u8 = 1;
var more_nums = [_]u8{ 1, 1, 1, 1 };
// Let's pass a reference to num to our function and print it:
// Let's pass the num reference to our function and print it:
makeFive(&num);
std.debug.print("num: {}, ", .{num});

View file

@ -38,14 +38,12 @@ pub fn main() void {
// Let's try it with a tiny 4-bit integer size to make it clear:
const a: u4 = 0b1101;
const b: u4 = 0b0101;
var my_result: u4 = undefined;
var overflowed: bool = undefined;
overflowed = @addWithOverflow(u4, a, b, &my_result);
const my_result = @addWithOverflow(a, b);
// Check out our fancy formatting! b:0>4 means, "print
// as a binary number, zero-pad right-aligned four digits."
// 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 add 5 to 'a' but go one by one and see where it overflows:

View file

@ -4,8 +4,8 @@
//
// .{
// false,
// @as(u32, 15);
// @as(i64, 67.12);
// @as(u32, 15),
// @as(f64, 67.12)
// }
//
// We call these "tuples", which is a term used by many