| 114 | } |
| 115 | |
| 116 | absl::StatusOr<absl::string_view> FormatDouble( |
| 117 | double value, std::optional<int> precision, bool use_scientific_notation, |
| 118 | std::string& scratch ABSL_ATTRIBUTE_LIFETIME_BOUND) { |
| 119 | static constexpr int kDefaultPrecision = 6; |
| 120 | if (std::isnan(value)) { |
| 121 | return "NaN"; |
| 122 | } else if (value == std::numeric_limits<double>::infinity()) { |
| 123 | return "Infinity"; |
| 124 | } else if (value == -std::numeric_limits<double>::infinity()) { |
| 125 | return "-Infinity"; |
| 126 | } |
| 127 | auto format = absl::StrCat("%.", precision.value_or(kDefaultPrecision), |
| 128 | use_scientific_notation ? "e" : "f"); |
| 129 | if (use_scientific_notation) { |
| 130 | scratch = absl::StrFormat(*absl::ParsedFormat<'e'>::New(format), value); |
| 131 | } else { |
| 132 | scratch = absl::StrFormat(*absl::ParsedFormat<'f'>::New(format), value); |
| 133 | } |
| 134 | return scratch; |
| 135 | } |
| 136 | |
| 137 | absl::StatusOr<absl::string_view> FormatList( |
| 138 | const Value& value, |
no test coverage detected