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

Function BigInt_Multiply_int

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

result = lhs * rhs */

Source from the content-addressed store, hash-verified

447
448/* result = lhs * rhs */
449static void
450BigInt_Multiply_int(BigInt *result, const BigInt *lhs, npy_uint32 rhs)
451{
452 /* perform long multiplication */
453 npy_uint32 carry = 0;
454 npy_uint32 *resultCur = result->blocks;
455 const npy_uint32 *pLhsCur = lhs->blocks;
456 const npy_uint32 *pLhsEnd = lhs->blocks + lhs->length;
457 for ( ; pLhsCur != pLhsEnd; ++pLhsCur, ++resultCur) {
458 npy_uint64 product = (npy_uint64)(*pLhsCur) * rhs + carry;
459 *resultCur = (npy_uint32)(product & bitmask_u64(32));
460 carry = product >> 32;
461 }
462
463 /* if there is a remaining carry, grow the array */
464 if (carry != 0) {
465 /* grow the array */
466 DEBUG_ASSERT(lhs->length + 1 <= c_BigInt_MaxBlocks);
467 *resultCur = (npy_uint32)carry;
468 result->length = lhs->length + 1;
469 }
470 else {
471 result->length = lhs->length;
472 }
473}
474
475/* result = in * 2 */
476static void

Callers 1

BigInt_MultiplyPow10Function · 0.85

Calls 1

bitmask_u64Function · 0.85

Tested by

no test coverage detected