[XLA] Clean up some floating point printing code

- When doing *exact* floating point comparisons, print out enough digits of the
  floating point number to unambiguously round trip to the float in question.
- The exhaustive op test had an off-by-one for precision when printing a float.

PiperOrigin-RevId: 277988562
Change-Id: I9d30190a754d698e009fd51aa7fe6ca5661e2bc0
This commit is contained in:
David Majnemer 2019-11-01 13:21:25 -07:00 committed by TensorFlower Gardener
parent 34b69b6c28
commit d6fee25d1d
2 changed files with 8 additions and 7 deletions

View File

@ -16,6 +16,7 @@ limitations under the License.
#include "tensorflow/compiler/xla/literal_comparison.h"
#include <unistd.h>
#include <cmath>
#include <vector>
@ -106,9 +107,9 @@ Status MakeBitwiseErrorStatus(NativeT lhs, NativeT rhs,
auto rhs_double = static_cast<double>(rhs);
return InvalidArgument(
"floating values are not bitwise-equal; and equality testing "
"was requested: %s=%g=%a vs %s=%g=%a at array index %s",
StrCat(absl::Hex(ulhs)), lhs_double, lhs_double,
StrCat(absl::Hex(urhs)), rhs_double, rhs_double,
"was requested: %s=%s=%a vs %s=%s=%a at array index %s",
StrCat(absl::Hex(ulhs)), RoundTripFpToString(lhs), lhs_double,
StrCat(absl::Hex(urhs)), RoundTripFpToString(rhs), rhs_double,
LiteralUtil::MultiIndexAsString(multi_index));
}

View File

@ -37,7 +37,7 @@ struct ComponentStringifyFormat<double> {
template <>
struct ComponentStringifyFormat<float> {
static constexpr absl::string_view value = "%0.8g (0x%08x)";
static constexpr absl::string_view value = "%0.9g (0x%08x)";
};
template <>