| 192 | } // namespace |
| 193 | |
| 194 | absl::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 |