MCPcopy Create free account
hub / github.com/RedisGraph/RedisGraph / SIValue_Modulo

Function SIValue_Modulo

src/value.c:515–531  ·  view source on GitHub ↗

Calculate a mod n for integer and floating-point inputs.

Source from the content-addressed store, hash-verified

513
514// Calculate a mod n for integer and floating-point inputs.
515SIValue SIValue_Modulo(const SIValue a, const SIValue n) {
516 bool inputs_are_integers = SI_TYPE(a) & SI_TYPE(n) & T_INT64;
517 if(inputs_are_integers) {
518 // The modulo machine instruction may be used if a and n are both integers.
519
520 int64_t res = 0;
521 // workaround for https://gcc.gnu.org/bugzilla/show_bug.cgi?id=30484
522 if (n.longval != -1){ // % -1 is always return 0
523 res = (int64_t)a.longval % (int64_t)n.longval;
524 }
525
526 return SI_LongVal(res);
527 } else {
528 // Otherwise, use the library function fmod to calculate the modulo and return a double.
529 return SI_DoubleVal(fmod(SI_GET_NUMERIC(a), SI_GET_NUMERIC(n)));
530 }
531}
532
533int SIArray_Compare(SIValue arrayA, SIValue arrayB, int *disjointOrNull) {
534 uint arrayALen = SIArray_Length(arrayA);

Callers 1

AR_MODULOFunction · 0.85

Calls 2

SI_LongValFunction · 0.85
SI_DoubleValFunction · 0.85

Tested by

no test coverage detected