inprove code

This commit is contained in:
Laurent Perron
2025-05-27 13:49:48 +02:00
parent d055baeca4
commit de3d0b452a

View File

@@ -163,7 +163,8 @@ bool AreWithinAbsoluteTolerance(FloatType x, FloatType y,
template <typename FloatType>
bool IsSmallerWithinTolerance(FloatType x, FloatType y, FloatType tolerance) {
if (IsPositiveOrNegativeInfinity(y)) return x <= y;
return x <= y + tolerance * std::max(1.0, std::min(std::abs(x), std::abs(y)));
return x <= y + tolerance * std::max(FloatType(1.0),
std::min(std::abs(x), std::abs(y)));
}
// Returns true if x is within tolerance of any integer. Always returns