MCPcopy Create free account
hub / github.com/numpy/numpy / BigInt_Compare

Function BigInt_Compare

numpy/core/src/multiarray/dragon4.c:290–316  ·  view source on GitHub ↗

* Returns 0 if (lhs = rhs), negative if (lhs < rhs), positive if (lhs > rhs) */

Source from the content-addressed store, hash-verified

288 * Returns 0 if (lhs = rhs), negative if (lhs < rhs), positive if (lhs > rhs)
289 */
290static npy_int32
291BigInt_Compare(const BigInt *lhs, const BigInt *rhs)
292{
293 int i;
294
295 /* A bigger length implies a bigger number. */
296 npy_int32 lengthDiff = lhs->length - rhs->length;
297 if (lengthDiff != 0) {
298 return lengthDiff;
299 }
300
301 /* Compare blocks one by one from high to low. */
302 for (i = lhs->length - 1; i >= 0; --i) {
303 if (lhs->blocks[i] == rhs->blocks[i]) {
304 continue;
305 }
306 else if (lhs->blocks[i] > rhs->blocks[i]) {
307 return 1;
308 }
309 else {
310 return -1;
311 }
312 }
313
314 /* no blocks differed */
315 return 0;
316}
317
318/* result = lhs + rhs */
319static void

Callers 2

Dragon4Function · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected