Is this a bug or am I missing something?

Casting u32 to f64 creates an error loop.

fn print_float(int: u32) void {
    const cast_float = @intCast(int);
    const explicit_float: f64 = @intCast(int);
    const as_float = @as(f64, int);
    const as_cast_float = @as(f64, @intCast(int));
    std.debug.print("{f}\n", .{any_of_the_above});
}

Printing cast_float produces

error: @intCast must have a known result type.

Printing explicit_float produces

error: expected integer or vector, found ‘f64’ // in @intCast

Printing as_float produces

error: expected type ‘f64’, found ‘u32’ // in @as

Printing as_cast_float produces

error: expected integer or vector, found ‘f64’ // in @intCast

you have to use @floatFromInt.

const float: f64 = @floatFromInt(int);
2 Likes

Ahh I mustve missed that builtin. Thanks.

Also {f} is not about floats, but about format functions. Use something like {e} or {d} instead.

Yea realized that just now in testing. Thanks