MCPcopy Create free account
hub / github.com/antirez/llama.cpp-deepseek-v4-flash / value_compare

Function value_compare

common/jinja/value.cpp:1289–1350  ·  view source on GitHub ↗

compare operator for value_t

Source from the content-addressed store, hash-verified

1287
1288// compare operator for value_t
1289bool value_compare(const value & a, const value & b, value_compare_op op) {
1290 auto cmp = [&]() {
1291 // compare numeric types
1292 if ((is_val<value_int>(a) || is_val<value_float>(a)) &&
1293 (is_val<value_int>(b) || is_val<value_float>(b))){
1294 try {
1295 if (op == value_compare_op::eq) {
1296 return a->as_float() == b->as_float();
1297 } else if (op == value_compare_op::ge) {
1298 return a->as_float() >= b->as_float();
1299 } else if (op == value_compare_op::gt) {
1300 return a->as_float() > b->as_float();
1301 } else if (op == value_compare_op::lt) {
1302 return a->as_float() < b->as_float();
1303 } else if (op == value_compare_op::ne) {
1304 return a->as_float() != b->as_float();
1305 } else {
1306 throw std::runtime_error("Unsupported comparison operator for numeric types");
1307 }
1308 } catch (...) {}
1309 }
1310 // compare string and number
1311 // TODO: not sure if this is the right behavior
1312 if ((is_val<value_string>(b) && (is_val<value_int>(a) || is_val<value_float>(a))) ||
1313 (is_val<value_string>(a) && (is_val<value_int>(b) || is_val<value_float>(b))) ||
1314 (is_val<value_string>(a) && is_val<value_string>(b))) {
1315 try {
1316 if (op == value_compare_op::eq) {
1317 return a->as_string().str() == b->as_string().str();
1318 } else if (op == value_compare_op::ge) {
1319 return a->as_string().str() >= b->as_string().str();
1320 } else if (op == value_compare_op::gt) {
1321 return a->as_string().str() > b->as_string().str();
1322 } else if (op == value_compare_op::lt) {
1323 return a->as_string().str() < b->as_string().str();
1324 } else if (op == value_compare_op::ne) {
1325 return a->as_string().str() != b->as_string().str();
1326 } else {
1327 throw std::runtime_error("Unsupported comparison operator for string/number types");
1328 }
1329 } catch (...) {}
1330 }
1331 // compare boolean simple
1332 if (is_val<value_bool>(a) && is_val<value_bool>(b)) {
1333 if (op == value_compare_op::eq) {
1334 return a->as_bool() == b->as_bool();
1335 } else if (op == value_compare_op::ne) {
1336 return a->as_bool() != b->as_bool();
1337 } else {
1338 throw std::runtime_error("Unsupported comparison operator for bool type");
1339 }
1340 }
1341 // compare by type
1342 if (a->type() != b->type()) {
1343 return false;
1344 }
1345 return false;
1346 };

Callers 2

test_compare_fnFunction · 0.85
value.cppFile · 0.85

Calls 5

as_floatMethod · 0.45
strMethod · 0.45
as_stringMethod · 0.45
as_boolMethod · 0.45
typeMethod · 0.45

Tested by 1

test_compare_fnFunction · 0.68