| 37 | using ::cel::well_known_types::ValueReflection; |
| 38 | |
| 39 | std::string DoubleDebugString(double value) { |
| 40 | if (std::isfinite(value)) { |
| 41 | if (std::floor(value) != value) { |
| 42 | // The double is not representable as a whole number, so use |
| 43 | // absl::StrCat which will add decimal places. |
| 44 | return absl::StrCat(value); |
| 45 | } |
| 46 | // absl::StrCat historically would represent 0.0 as 0, and we want the |
| 47 | // decimal places so ZetaSQL correctly assumes the type as double |
| 48 | // instead of int64. |
| 49 | std::string stringified = absl::StrCat(value); |
| 50 | if (!absl::StrContains(stringified, '.')) { |
| 51 | absl::StrAppend(&stringified, ".0"); |
| 52 | } else { |
| 53 | // absl::StrCat has a decimal now? Use it directly. |
| 54 | } |
| 55 | return stringified; |
| 56 | } |
| 57 | if (std::isnan(value)) { |
| 58 | return "nan"; |
| 59 | } |
| 60 | if (std::signbit(value)) { |
| 61 | return "-infinity"; |
| 62 | } |
| 63 | return "+infinity"; |
| 64 | } |
| 65 | |
| 66 | } // namespace |
| 67 | |