In literal_comparison, don't try to compute a relative error when the
expected value is 0, because doing so would mean that the only
acceptable value *is* zero, which probably isn't what you mean.
PiperOrigin-RevId:
198137414
rel_error = std::numeric_limits<float>::infinity();
} else {
abs_error = FpAbsoluteValue(actual - expected);
- rel_error = abs_error / FpAbsoluteValue(expected);
+ // If the expected result is exactly zero, don't compute relative error;
+ // that's meaningless.
+ //
+ // TODO(b/80321728): Come up with a better way to handle this case.
+ if (expected == NativeT{}) {
+ rel_error = 0;
+ } else {
+ rel_error = abs_error / FpAbsoluteValue(expected);
+ }
}
const bool is_abs_mismatch = abs_error > error_.abs;
const bool is_rel_mismatch = rel_error > error_.rel;