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

Function FloatFromValue

eval/public/structs/cel_proto_wrap_util.cc:789–809  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

787}
788
789google::protobuf::Message* FloatFromValue(const google::protobuf::Message* prototype,
790 const CelValue& value, google::protobuf::Arena* arena) {
791 double val;
792 if (!value.GetValue(&val)) {
793 return nullptr;
794 }
795 float fval = val;
796 // Abort the conversion if the value is outside the float range.
797 if (val > std::numeric_limits<float>::max()) {
798 fval = std::numeric_limits<float>::infinity();
799 } else if (val < std::numeric_limits<float>::lowest()) {
800 fval = -std::numeric_limits<float>::infinity();
801 }
802 auto* message = prototype->New(arena);
803 CEL_ASSIGN_OR_RETURN(
804 auto reflection,
805 cel::well_known_types::GetFloatValueReflection(message->GetDescriptor()),
806 _.With(IgnoreErrorAndReturnNullptr()));
807 reflection.SetValue(message, static_cast<float>(fval));
808 return message;
809}
810
811google::protobuf::Message* Int32FromValue(const google::protobuf::Message* prototype,
812 const CelValue& value, google::protobuf::Arena* arena) {

Callers 1

MaybeWrapMessageMethod · 0.85

Calls 3

GetValueMethod · 0.45
NewMethod · 0.45
SetValueMethod · 0.45

Tested by

no test coverage detected