[XLA] Avoid fp division by 0 in literal_comparison.cc.
Found by running hlo_evaluator_test with ubsan. PiperOrigin-RevId: 226937627
This commit is contained in:
parent
c220247fe3
commit
79126ece73
@ -387,7 +387,14 @@ class NearComparator {
|
|||||||
rel_error = std::numeric_limits<float>::infinity();
|
rel_error = std::numeric_limits<float>::infinity();
|
||||||
} else {
|
} else {
|
||||||
abs_error = FpAbsoluteValue(actual - expected);
|
abs_error = FpAbsoluteValue(actual - expected);
|
||||||
rel_error = abs_error / FpAbsoluteValue(expected);
|
|
||||||
|
// Avoid division by 0 even though it's well-defined because ubsan can be
|
||||||
|
// configured to treat this as a fatal error.
|
||||||
|
if (expected != T{0}) {
|
||||||
|
rel_error = abs_error / FpAbsoluteValue(expected);
|
||||||
|
} else {
|
||||||
|
rel_error = std::numeric_limits<float>::infinity();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
const bool is_abs_mismatch = abs_error > error_.abs;
|
const bool is_abs_mismatch = abs_error > error_.abs;
|
||||||
const bool is_rel_mismatch = rel_error > error_.rel;
|
const bool is_rel_mismatch = rel_error > error_.rel;
|
||||||
|
Loading…
Reference in New Issue
Block a user