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

Function GetDouble

extensions/formatting.cc:406–427  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

404}
405
406absl::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
429absl::StatusOr<absl::string_view> FormatFixed(
430 const Value& value, std::optional<int> precision,

Callers 3

GetMethod · 0.85
GetMethod · 0.85

Calls 5

kindMethod · 0.45
GetStringMethod · 0.45
GetTypeNameMethod · 0.45
NativeValueMethod · 0.45
GetDoubleMethod · 0.45

Tested by

no test coverage detected