namespace open_spiel {

// Formats doubles with human-readable strings with a specified number of
// decimal places, i.e. results in lossy serialization.
struct SimpleDoubleFormatter {
  SimpleDoubleFormatter(int precision = 6) : precision(precision) {}

  void operator()(std::string* out, const double& d) const {
    std::stringstream stream;
    stream << std::fixed << std::setprecision(precision) << d;
    absl::StrAppend(out, stream.str());
  }

  const int precision;
};

// Formats doubles with non-portable bitwise representation hex strings, i.e.
// results in lossless serialization.
struct HexDoubleFormatter {
  void operator()(std::string* out, const double& d) const {
    absl::StrAppend(out, absl::StrFormat("%a", d));
  }
};

}  // namespace open_spiel

#endif  // OPEN_SPIEL_UTILS_SERIALIZATION_H_
