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

Function BigInt_MultiplyPow10

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

in = in * 10^exponent */

Source from the content-addressed store, hash-verified

805
806/* in = in * 10^exponent */
807static void
808BigInt_MultiplyPow10(BigInt *in, npy_uint32 exponent, BigInt *temp)
809{
810 /* use two temporary values to reduce large integer copy operations */
811 BigInt *curTemp, *pNextTemp;
812 npy_uint32 smallExponent;
813 npy_uint32 tableIdx = 0;
814
815 /* make sure the exponent is within the bounds of the lookup table data */
816 DEBUG_ASSERT(exponent < 8192);
817
818 /*
819 * initialize the result by looking up a 32-bit power of 10 corresponding to
820 * the first 3 bits
821 */
822 smallExponent = exponent & bitmask_u32(3);
823 if (smallExponent != 0) {
824 BigInt_Multiply_int(temp, in, g_PowerOf10_U32[smallExponent]);
825 curTemp = temp;
826 pNextTemp = in;
827 }
828 else {
829 curTemp = in;
830 pNextTemp = temp;
831 }
832
833 /* remove the low bits that we used for the 32-bit lookup table */
834 exponent >>= 3;
835
836 /* while there are remaining bits in the exponent to be processed */
837 while (exponent != 0) {
838 /* if the current bit is set, multiply by this power of 10 */
839 if (exponent & 1) {
840 BigInt *pSwap;
841
842 /* multiply into the next temporary */
843 BigInt_Multiply(pNextTemp, curTemp, &g_PowerOf10_Big[tableIdx]);
844
845 /* swap to the next temporary */
846 pSwap = curTemp;
847 curTemp = pNextTemp;
848 pNextTemp = pSwap;
849 }
850
851 /* advance to the next bit */
852 ++tableIdx;
853 exponent >>= 1;
854 }
855
856 /* output the result */
857 if (curTemp != in){
858 BigInt_Copy(in, curTemp);
859 }
860}
861
862/* result = 2^exponent */
863static inline void

Callers 1

Dragon4Function · 0.85

Calls 4

bitmask_u32Function · 0.85
BigInt_Multiply_intFunction · 0.85
BigInt_MultiplyFunction · 0.85
BigInt_CopyFunction · 0.85

Tested by

no test coverage detected