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

Function RegisterArithmeticFunctions

runtime/standard/arithmetic_functions.cc:194–231  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

192} // namespace
193
194absl::Status RegisterArithmeticFunctions(FunctionRegistry& registry,
195 const RuntimeOptions& options) {
196 CEL_RETURN_IF_ERROR(RegisterArithmeticFunctionsForType<int64_t>(registry));
197 CEL_RETURN_IF_ERROR(RegisterArithmeticFunctionsForType<uint64_t>(registry));
198 CEL_RETURN_IF_ERROR(RegisterArithmeticFunctionsForType<double>(registry));
199
200 // Modulo
201 CEL_RETURN_IF_ERROR(registry.Register(
202 BinaryFunctionAdapter<Value, int64_t, int64_t>::CreateDescriptor(
203 cel::builtin::kModulo, false),
204 BinaryFunctionAdapter<Value, int64_t, int64_t>::WrapFunction(
205 &Modulo<int64_t>)));
206
207 CEL_RETURN_IF_ERROR(registry.Register(
208 BinaryFunctionAdapter<Value, uint64_t, uint64_t>::CreateDescriptor(
209 cel::builtin::kModulo, false),
210 BinaryFunctionAdapter<Value, uint64_t, uint64_t>::WrapFunction(
211 &Modulo<uint64_t>)));
212
213 // Negation group
214 CEL_RETURN_IF_ERROR(
215 registry.Register(UnaryFunctionAdapter<Value, int64_t>::CreateDescriptor(
216 cel::builtin::kNeg, false),
217 UnaryFunctionAdapter<Value, int64_t>::WrapFunction(
218 [](int64_t value) -> Value {
219 auto inv = cel::internal::CheckedNegation(value);
220 if (!inv.ok()) {
221 return ErrorValue(inv.status());
222 }
223 return IntValue(*inv);
224 })));
225
226 return registry.Register(
227 UnaryFunctionAdapter<double, double>::CreateDescriptor(cel::builtin::kNeg,
228 false),
229 UnaryFunctionAdapter<double, double>::WrapFunction(
230 [](double value) -> double { return -value; }));
231}
232
233} // namespace cel

Callers 3

RegisterBuiltinFunctionsFunction · 0.85
TESTFunction · 0.85

Calls 6

CreateDescriptorFunction · 0.85
CheckedNegationFunction · 0.85
ErrorValueFunction · 0.85
IntValueClass · 0.50
RegisterMethod · 0.45
okMethod · 0.45

Tested by 1

TESTFunction · 0.68