I have to cast to device compatible types and part of that process is reinterpreting f16
to u16
. I noticed that inf
doesn’t get carried over when using the builtin methods, but pointer casting does:
info: Original: inf
info: Builtin Cast: 3.1744e+04
info: Pointer Cast: inf
pub fn main() !void {
const x = std.math.inf(f16);
const u: *const u16 = @ptrCast(&x);
// @floatFromInt - doesn't preserve inf
const y: f16 = @floatFromInt(u.*);
// pointer casting - preserves inf
const z: f16 = @as(*const f16, @ptrCast(u)).*;
std.log.info("Original: {}", .{ x });
std.log.info("Builtin Cast: {}", .{ y });
std.log.info("Pointer Cast: {}", .{ z });
}
Any reason this doesn’t preserve infinity? I’m making custom casting operators to respect original floating point values to handle this, but I’m curious why this is this case.