Prevent extremely unlikely division by zero

This commit is contained in:
Jarred Sumner
2024-06-08 22:31:14 -07:00
parent c5010e9a12
commit 731a85f80d

View File

@@ -545,10 +545,10 @@ pub fn getSystemLoadavg() [3]f64 {
const loadavg = loadavg_[0];
const scale = @as(f64, @floatFromInt(loadavg.fscale));
return [3]f64{
@as(f64, @floatFromInt(loadavg.ldavg[0])) / scale,
@as(f64, @floatFromInt(loadavg.ldavg[1])) / scale,
@as(f64, @floatFromInt(loadavg.ldavg[2])) / scale,
return .{
if (scale == 0.0) 0 else @as(f64, @floatFromInt(loadavg.ldavg[0])) / scale,
if (scale == 0.0) 0 else @as(f64, @floatFromInt(loadavg.ldavg[1])) / scale,
if (scale == 0.0) 0 else @as(f64, @floatFromInt(loadavg.ldavg[2])) / scale,
};
}