| 404 | } |
| 405 | |
| 406 | absl::StatusOr<double> GetDouble(const Value& value, std::string& scratch) { |
| 407 | if (value.kind() == ValueKind::kString) { |
| 408 | auto str = value.GetString().NativeString(scratch); |
| 409 | if (str == "NaN") { |
| 410 | return std::nan(""); |
| 411 | } else if (str == "Infinity") { |
| 412 | return std::numeric_limits<double>::infinity(); |
| 413 | } else if (str == "-Infinity") { |
| 414 | return -std::numeric_limits<double>::infinity(); |
| 415 | } else { |
| 416 | return absl::InvalidArgumentError( |
| 417 | absl::StrCat("only \"NaN\", \"Infinity\", and \"-Infinity\" are " |
| 418 | "supported for conversion to double: ", |
| 419 | str)); |
| 420 | } |
| 421 | } |
| 422 | if (value.kind() != ValueKind::kDouble) { |
| 423 | return absl::InvalidArgumentError( |
| 424 | absl::StrCat("expected a double but got a ", value.GetTypeName())); |
| 425 | } |
| 426 | return value.GetDouble().NativeValue(); |
| 427 | } |
| 428 | |
| 429 | absl::StatusOr<absl::string_view> FormatFixed( |
| 430 | const Value& value, std::optional<int> precision, |
no test coverage detected