-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathhello-values.zig
More file actions
42 lines (36 loc) · 1.33 KB
/
hello-values.zig
File metadata and controls
42 lines (36 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
const std = @import("std");
const debugPrint = std.debug.print;
const assert = std.debug.assert;
pub fn sampleValues() !void {
debugPrint("=================== VALUES\n", .{});
// integers
const two_times_two: i32 = 2 * 2;
debugPrint("=> {}\n", .{two_times_two});
// floats
const two_by_four: f32 = 2.0 / 4.0;
debugPrint("=> {}\n", .{two_by_four});
debugPrint("=> {d}\n", .{two_by_four});
debugPrint("=> {d}\n", .{two_by_four + 0.25});
debugPrint("=> {d:.3}\n", .{two_by_four});
const twotwo_by_seven: f64 = 22.0 / 7.0;
debugPrint("=> {d:.10}\n", .{twotwo_by_seven});
// boolean
debugPrint("=> {}\n", .{true and false});
debugPrint("=> {}\n", .{!false});
// optional
var opt_val: ?[]const u8 = null;
assert(opt_val == null);
debugPrint("=> {?s} of type: {}\n", .{ opt_val, @TypeOf(opt_val) });
opt_val = "Z I G";
assert(opt_val != null);
debugPrint("=> {?s} of type: {}\n", .{ opt_val, @TypeOf(opt_val) });
// error union
var err_count: anyerror!i32 = error.ArgNotFound;
debugPrint("=> {!} of type: {}\n", .{ err_count, @TypeOf(err_count) });
err_count = 100;
debugPrint("=> {!} of type: {}\n", .{ err_count, @TypeOf(err_count) });
// var with undefined
var lucky: u8 = undefined;
lucky = 7;
debugPrint("=> {d}\n", .{lucky});
}