620 char *pCurDigit = pOubooluffer;
644 BigInt *pScaledMarginHigh;
645 BigInt optionalMarginHigh;
647 if (hasUnequalMargins)
690 pScaledMarginHigh = &optionalMarginHigh;
729 pScaledMarginHigh = &scaledMarginLow;
747 const double log10_2 = 0.30102999566398119521373889472449;
748 int32_t digitExponent = (int32_t)(
ceil(
double((int32_t)mantissaHighBitIdx + exponent) * log10_2 - 0.69));
757 digitExponent = -(int32_t)cutoffNumber + 1;
761 if (digitExponent > 0)
768 else if (digitExponent < 0)
780 scaledMarginLow = temp;
782 if (pScaledMarginHigh != &scaledMarginLow)
792 digitExponent = digitExponent + 1;
800 if (pScaledMarginHigh != &scaledMarginLow)
806 int32_t cutoffExponent = digitExponent - bufferSize;
816 int32_t desiredCutoffExponent = digitExponent - (int32_t)cutoffNumber;
817 if (desiredCutoffExponent > cutoffExponent)
818 cutoffExponent = desiredCutoffExponent;
825 int32_t desiredCutoffExponent = -(int32_t)cutoffNumber;
826 if (desiredCutoffExponent > cutoffExponent)
827 cutoffExponent = desiredCutoffExponent;
833 *pOutExponent = digitExponent - 1;
844 if (hiBlock < 8 || hiBlock > 429496729)
852 uint32_t hiBlockLog2 =
log2i(hiBlock);
853 assert(hiBlockLog2 < 3 || hiBlockLog2 > 27);
854 uint32_t shift = (32 + 27 - hiBlockLog2) % 32;
859 if (pScaledMarginHigh != &scaledMarginLow)
867 uint32_t outputDigit;
876 digitExponent = digitExponent - 1;
884 BigInt_Add(&scaledValueHigh, scaledValue, *pScaledMarginHigh);
890 if (low | high | (digitExponent == cutoffExponent))
894 *pCurDigit = (char)(
'0' + outputDigit);
900 if (pScaledMarginHigh != &scaledMarginLow)
914 digitExponent = digitExponent - 1;
920 if (scaledValue.
IsZero() | (digitExponent == cutoffExponent))
924 *pCurDigit = (char)(
'0' + outputDigit);
934 bool roundDown = low;
946 roundDown = compare < 0;
950 roundDown = (outputDigit & 1) == 0;
956 *pCurDigit = (char)(
'0' + outputDigit);
962 if (outputDigit == 9)
968 if (pCurDigit == pOubooluffer)
978 if (*pCurDigit !=
'9')
990 *pCurDigit = (char)(
'0' + outputDigit + 1);
996 uint32_t outputLen = (uint32_t)(pCurDigit - pOubooluffer);
997 assert(outputLen <= bufferSize);
static void BigInt_ShiftLeft(BigInt *pResult, uint32_t shift)
double ceil(double x)
Ceiling function.
static void BigInt_Multiply10(BigInt *pResult)
static void BigInt_Multiply(BigInt *pResult, const BigInt &lhs, const BigInt &rhs)
uint32_t Geboollock(uint32_t idx) const
uint32_t GetLength() const
static void BigInt_Add(BigInt *pResult, const BigInt &lhs, const BigInt &rhs)
void SetUInt32(uint32_t val)
unsigned int log2i(unsigned int x)
static void BigInt_MultiplyPow10(BigInt *pResult, const BigInt &in, uint32_t exponent)
static int32_t BigInt_Compare(const BigInt &lhs, const BigInt &rhs)
static void BigInt_Multiply2(BigInt *pResult, const BigInt &in)
static void BigInt_Pow10(BigInt *pResult, uint32_t exponent)
void SetUInt64(uint64_t val)
static void BigInt_Pow2(BigInt *pResult, uint32_t exponent)
static uint32_t BigInt_DivideWithRemainder_MaxQuotient9(BigInt *pDividend, const BigInt &divisor)