zig/test/cases/compile_errors/intFromFloat_comptime_safety.zig
mlugg f26dda2117 all: migrate code to new cast builtin syntax
Most of this migration was performed automatically with `zig fmt`. There
were a few exceptions which I had to manually fix:

* `@alignCast` and `@addrSpaceCast` cannot be automatically rewritten
* `@truncate`'s fixup is incorrect for vectors
* Test cases are not formatted, and their error locations change
2023-06-24 16:56:39 -07:00

18 lines
498 B
Zig

comptime {
_ = @as(i8, @intFromFloat(@as(f32, -129.1)));
}
comptime {
_ = @as(u8, @intFromFloat(@as(f32, -1.1)));
}
comptime {
_ = @as(u8, @intFromFloat(@as(f32, 256.1)));
}
// error
// backend=stage2
// target=native
//
// :2:31: error: float value '-129.10000610351562' cannot be stored in integer type 'i8'
// :5:31: error: float value '-1.100000023841858' cannot be stored in integer type 'u8'
// :8:31: error: float value '256.1000061035156' cannot be stored in integer type 'u8'