Fix the equality check of two floating point values

PiperOrigin-RevId: 266022088
This commit is contained in:
Feng Liu 2019-08-28 16:39:18 -07:00 committed by A. Unique TensorFlower
parent 29099e03ce
commit 7dd5efdf2c
1 changed files with 5 additions and 3 deletions

View File

@ -71,10 +71,12 @@ mlir::quant::fakeQuantAttrsToType(Location loc, unsigned numBits, double rmin,
nullptr);
}
// Special case where min/max is a point. Must be 0.
if (rmin == rmax) {
// Special case where min/max is close enough. The tensor contents are all
// 0.0s, so the scale is set to 1.0 and the tensor can be quantized to zero
// points and dequantized to 0.0.
if (std::fabs(rmax - rmin) < std::numeric_limits<double>::epsilon()) {
return UniformQuantizedType::getChecked(flags, storageType, expressedType,
0.0, 0, qmin, qmax, loc);
1.0, 0, qmin, qmax, loc);
}
// Determine the scale.