result = 10^exponent */
| 756 | |
| 757 | /* result = 10^exponent */ |
| 758 | static void |
| 759 | BigInt_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 */ |
| 807 | static void |
no test coverage detected