| 1619 | } |
| 1620 | |
| 1621 | std::string JsonNumberDebugString(double value) { |
| 1622 | if (std::isfinite(value)) { |
| 1623 | if (std::floor(value) != value) { |
| 1624 | // The double is not representable as a whole number, so use |
| 1625 | // absl::StrCat which will add decimal places. |
| 1626 | return absl::StrCat(value); |
| 1627 | } |
| 1628 | // absl::StrCat historically would represent 0.0 as 0, and we want the |
| 1629 | // decimal places so ZetaSQL correctly assumes the type as double |
| 1630 | // instead of int64. |
| 1631 | std::string stringified = absl::StrCat(value); |
| 1632 | if (!absl::StrContains(stringified, '.')) { |
| 1633 | absl::StrAppend(&stringified, ".0"); |
| 1634 | } else { |
| 1635 | // absl::StrCat has a decimal now? Use it directly. |
| 1636 | } |
| 1637 | return stringified; |
| 1638 | } |
| 1639 | if (std::isnan(value)) { |
| 1640 | return "nan"; |
| 1641 | } |
| 1642 | if (std::signbit(value)) { |
| 1643 | return "-infinity"; |
| 1644 | } |
| 1645 | return "+infinity"; |
| 1646 | } |
| 1647 | |
| 1648 | class JsonDebugStringState final { |
| 1649 | public: |