Calculate a mod n for integer and floating-point inputs.
| 513 | |
| 514 | // Calculate a mod n for integer and floating-point inputs. |
| 515 | SIValue 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 | |
| 533 | int SIArray_Compare(SIValue arrayA, SIValue arrayB, int *disjointOrNull) { |
| 534 | uint arrayALen = SIArray_Length(arrayA); |
no test coverage detected