-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
@bitCast() and meta.Vector components don't work together as expected #9768
Copy link
Copy link
Open
Labels
bugObserved behavior contradicts documented or intended behaviorObserved behavior contradicts documented or intended behavior
Milestone
Description
Consider the following program:
const std = @import("std");
pub const Vec4f = std.meta.Vector(4, f32);
pub fn garbage(a: Vec4f) void {
const b = Vec4f{
@bitCast(f32, @bitCast(i32, a[0])),
@bitCast(f32, @bitCast(i32, a[1])),
@bitCast(f32, @bitCast(i32, a[2])),
@bitCast(f32, @bitCast(i32, a[3])),
};
std.debug.print("{} {}\n", .{ a, b });
}
pub fn noGarbage(a: Vec4f) void {
const b0 = @bitCast(f32, @bitCast(i32, a[0]));
const b1 = @bitCast(f32, @bitCast(i32, a[1]));
const b2 = @bitCast(f32, @bitCast(i32, a[2]));
const b3 = @bitCast(f32, @bitCast(i32, a[3]));
const b = Vec4f{ b0, b1, b2, b3 };
std.debug.print("{} {}\n", .{ a, b });
}
pub fn main() void {
const p = Vec4f{ 100.0, 100.0, 100.0, 100.0 };
garbage(p);
noGarbage(p);
}
The b vector does not print as expected when calling garbage(), it works as expected with noGarbage(). Example output:
{ 1.0e+02, 1.0e+02, 1.0e+02, 1.0e+02 } { 1.0e+02, 4.59121428e-41, 3.24416114e-03, 2.03188277e-43 }
{ 1.0e+02, 1.0e+02, 1.0e+02, 1.0e+02 } { 1.0e+02, 1.0e+02, 1.0e+02, 1.0e+02 }
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugObserved behavior contradicts documented or intended behaviorObserved behavior contradicts documented or intended behavior