fn intFromFloatExact(T: type, value: anytype) ?T
fn intFromFloatExact(T: type, value: anytype) ?T { const max: @TypeOf(value) = @floatFromInt(std.math.maxInt(T)); const min: @TypeOf(value) = @floatFromInt(std.math.minInt(T)); if (value > max or value < min) { return null; } if (std.math.isNan(value) or std.math.trunc(value) != value) { return null; } return @intFromFloat(value); }