fn intFromFloatExact(T: type, value: anytype) ?T T: typevalue1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186fn 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);
}