MCPcopy Create free account
hub / github.com/cel-expr/cel-cpp / FormatDoubleConstant

Function FormatDoubleConstant

common/constant.cc:57–80  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

55}
56
57std::string FormatDoubleConstant(double value) {
58 if (std::isfinite(value)) {
59 if (std::floor(value) != value) {
60 // The double is not representable as a whole number, so use
61 // absl::StrCat which will add decimal places.
62 return absl::StrCat(value);
63 }
64 // absl::StrCat historically would represent 0.0 as 0, and we want the
65 // decimal places so ZetaSQL correctly assumes the type as double
66 // instead of int64.
67 std::string stringified = absl::StrCat(value);
68 if (!absl::StrContains(stringified, '.')) {
69 absl::StrAppend(&stringified, ".0");
70 }
71 return stringified;
72 }
73 if (std::isnan(value)) {
74 return "nan";
75 }
76 if (std::signbit(value)) {
77 return "-infinity";
78 }
79 return "+infinity";
80}
81
82std::string FormatBytesConstant(absl::string_view value) {
83 return internal::FormatBytesLiteral(value);

Callers 1

AbslStringifyFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected