Skip to content

Commit 373ffb0

Browse files
committed
Update to Zig 0.12.0-dev.1538+3f10b3ee1
1 parent c373aa8 commit 373ffb0

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

build.zig

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
const std = @import("std");
22

33
pub fn build(b: *std.build.Builder) void {
4-
const mode = b.standardReleaseOptions();
4+
const optimize = b.standardOptimizeOption(.{});
5+
_ = b.addModule("fp", .{ .source_file = .{ .path = "src/main.zig" } });
56

6-
const main_tests = b.addTest("src/main.zig");
7-
main_tests.setBuildMode(mode);
7+
const main_tests = b.addTest(.{
8+
.root_source_file = .{ .path = "src/main.zig" },
9+
.optimize = optimize,
10+
});
11+
const run_tests = b.addRunArtifact(main_tests);
812

913
const test_step = b.step("test", "Run library tests");
10-
test_step.dependOn(&main_tests.step);
14+
test_step.dependOn(&run_tests.step);
1115
}

src/main.zig

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,13 @@ pub fn FixedPoint(comptime bits: comptime_int, comptime scaling: comptime_int) t
5353

5454
pub fn fromFloat(v: f32) F {
5555
// std.debug.print("fromFloat({}, {d})\n", .{ Int, v });
56-
return .{ .raw = @floatToInt(Int, scaling * v) };
56+
return .{ .raw = @as(Int, @intFromFloat(scaling * v)) };
5757
}
5858

5959
pub fn toFloat(v: F, comptime T: type) T {
6060
// std.debug.print("toFloat({}, {})\n", .{ Int, v.raw });
6161
_ = @typeInfo(T).Float;
62-
return @intToFloat(T, v.raw) / scaling;
62+
return @as(T, @floatFromInt(v.raw)) / scaling;
6363
}
6464

6565
pub fn fromInt(i: IntPart) F {
@@ -68,7 +68,7 @@ pub fn FixedPoint(comptime bits: comptime_int, comptime scaling: comptime_int) t
6868

6969
pub fn toInt(f: F) IntPart {
7070
// std.debug.print("toInt({}, {})\n", .{ Int, f.raw });
71-
return @intCast(IntPart, @divTrunc(f.raw, scaling));
71+
return @as(IntPart, @intCast(@divTrunc(f.raw, scaling)));
7272
}
7373

7474
// arithmetic operators:
@@ -82,11 +82,11 @@ pub fn FixedPoint(comptime bits: comptime_int, comptime scaling: comptime_int) t
8282
}
8383

8484
pub fn mul(a: F, b: F) F {
85-
return .{ .raw = @intCast(Int, scaleDown(@as(Int2, a.raw) * @as(Int2, b.raw))) };
85+
return .{ .raw = @as(Int, @intCast(scaleDown(@as(Int2, a.raw) * @as(Int2, b.raw)))) };
8686
}
8787

8888
pub fn div(a: F, b: F) F {
89-
return .{ .raw = @intCast(Int, @divTrunc(scaleUp(a.raw), b.raw)) };
89+
return .{ .raw = @as(Int, @intCast(@divTrunc(scaleUp(a.raw), b.raw))) };
9090
}
9191

9292
pub fn mod(a: F, b: F) F {
@@ -131,7 +131,7 @@ pub fn FixedPoint(comptime bits: comptime_int, comptime scaling: comptime_int) t
131131
} else if (comptime std.mem.eql(u8, fmt, "e")) {
132132
try std.fmt.formatFloatScientific(f.toFloat(f32), options, writer);
133133
} else {
134-
@compileError(comptime std.fmt.comptimePrint("Invalid fmt for FixedPoint({},{}): {{{s}}}", .{ bits, scaling, fmt }));
134+
@compileError(std.fmt.comptimePrint("Invalid fmt for FixedPoint({},{}): {{{s}}}", .{ bits, scaling, fmt }));
135135
}
136136
}
137137

@@ -151,9 +151,9 @@ pub fn FixedPoint(comptime bits: comptime_int, comptime scaling: comptime_int) t
151151

152152
fn scaleDown(in: Int2) Int {
153153
return if (is_pot)
154-
@intCast(Int, in >> precision_bits)
154+
@as(Int, @intCast(in >> precision_bits))
155155
else
156-
@intCast(Int, @divTrunc(in, scaling));
156+
@as(Int, @intCast(@divTrunc(in, scaling)));
157157
}
158158
};
159159
}

0 commit comments

Comments
 (0)