Try not to optimize the loop

Signed-off-by: jmug <u.g.a.mariano@gmail.com>
This commit is contained in:
Mariano Uvalle 2025-04-28 00:50:32 -07:00
parent 64f41ad5b9
commit aa1e940362
2 changed files with 9 additions and 4 deletions

13
testdata/addupto.zig vendored
View file

@ -1,9 +1,14 @@
const expect = @import("std").testing.expect;
pub export fn addUpTo(to: u32) u32 {
var res: u32 = 0;
for (0..to) |_| {
res += to;
pub export fn addUpTo(to: i32) i32 {
var res: i32 = 0;
for (0..@intCast(to)) |i| {
const ii: i32 = @intCast(i);
if (ii < 20) {
res += ii * to;
} else {
res += ii + to * 2;
}
}
return res;
}

Binary file not shown.