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

Function BigInt_Pow10

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

result = 10^exponent */

Source from the content-addressed store, hash-verified

756
757/* result = 10^exponent */
758static void
759BigInt_Pow10(BigInt *result, npy_uint32 exponent, BigInt *temp)
760{
761 /* use two temporary values to reduce large integer copy operations */
762 BigInt *curTemp = result;
763 BigInt *pNextTemp = temp;
764 npy_uint32 smallExponent;
765 npy_uint32 tableIdx = 0;
766
767 /* make sure the exponent is within the bounds of the lookup table data */
768 DEBUG_ASSERT(exponent < 8192);
769
770 /*
771 * initialize the result by looking up a 32-bit power of 10 corresponding to
772 * the first 3 bits
773 */
774 smallExponent = exponent & bitmask_u32(3);
775 BigInt_Set_uint32(curTemp, g_PowerOf10_U32[smallExponent]);
776
777 /* remove the low bits that we used for the 32-bit lookup table */
778 exponent >>= 3;
779
780 /* while there are remaining bits in the exponent to be processed */
781 while (exponent != 0) {
782 /* if the current bit is set, multiply by this power of 10 */
783 if (exponent & 1) {
784 BigInt *pSwap;
785
786 /* multiply into the next temporary */
787 BigInt_Multiply(pNextTemp, curTemp, &g_PowerOf10_Big[tableIdx]);
788
789 /* swap to the next temporary */
790 pSwap = curTemp;
791 curTemp = pNextTemp;
792 pNextTemp = pSwap;
793 }
794
795 /* advance to the next bit */
796 ++tableIdx;
797 exponent >>= 1;
798 }
799
800 /* output the result */
801 if (curTemp != result) {
802 BigInt_Copy(result, curTemp);
803 }
804}
805
806/* in = in * 10^exponent */
807static void

Callers 1

Dragon4Function · 0.85

Calls 4

bitmask_u32Function · 0.85
BigInt_Set_uint32Function · 0.85
BigInt_MultiplyFunction · 0.85
BigInt_CopyFunction · 0.85

Tested by

no test coverage detected