104 if (a != 0.0 && b > 0.0)
120 int32_t printExponent = 0;
124 bool sci = (dexponent > 9.0 || dexponent < -8.0);
129 else if (dexponent < 0.0)
140 static const int size = 64;
141 char *out =
new char[size];
142 char *pOutBuffer = out;
143 uint32_t bufferSize = size;
159 uint32_t mantissaHighBitIdx;
160 bool hasUnequalMargins;
162 if (floatExponent != 0)
165 mantissa = (1ull << 52) | floatMantissa;
166 exponent = floatExponent - 1023 - 52;
167 mantissaHighBitIdx = 52;
168 hasUnequalMargins = (floatExponent != 1) && (floatMantissa == 0);
173 mantissa = floatMantissa;
174 exponent = 1 - 1023 - 52;
175 mantissaHighBitIdx =
log2i(mantissa
);
176 hasUnequalMargins =
false;
181 int32_t printExponent;
182 uint32_t numPrintDigits;
183 uint32_t maxPrintLen = bufferSize - 1;
195 uint32_t numFractionDigits = 0;
198 if (printExponent >= 0)
201 uint32_t numWholeDigits = printExponent + 1;
202 if (numPrintDigits < numWholeDigits)
205 if (numWholeDigits > maxPrintLen)
206 numWholeDigits = maxPrintLen;
209 for (; numPrintDigits < numWholeDigits; ++numPrintDigits)
210 pOutBuffer[numPrintDigits] =
'0';
213 else if (numPrintDigits > (uint32_t)numWholeDigits)
215 numFractionDigits = numPrintDigits - numWholeDigits;
216 uint32_t maxFractionDigits = maxPrintLen - numWholeDigits - 1;
217 if (numFractionDigits > maxFractionDigits)
218 numFractionDigits = maxFractionDigits;
220 MemCopy(pOutBuffer + numWholeDigits + 1
, pOutBuffer + numWholeDigits
, numFractionDigits
);
222 numPrintDigits = numWholeDigits + 1 + numFractionDigits;
230 uint32_t numFractionZeros = (uint32_t)-printExponent - 1;
231 uint32_t maxFractionZeros = maxPrintLen - 2;
232 if (numFractionZeros > maxFractionZeros)
233 numFractionZeros = maxFractionZeros;
235 uint32_t digitsStartIdx = 2 + numFractionZeros;
238 numFractionDigits = numPrintDigits;
239 uint32_t maxFractionDigits = maxPrintLen - digitsStartIdx;
240 if (numFractionDigits > maxFractionDigits)
241 numFractionDigits = maxFractionDigits;
243 MemCopy(pOutBuffer + digitsStartIdx
, pOutBuffer
, numFractionDigits
);
246 for (uint32_t i = 2; i < digitsStartIdx; ++i)
250 numFractionDigits += numFractionZeros;
251 numPrintDigits = numFractionDigits;
270 if (precision > (int32_t)numFractionDigits && numPrintDigits < maxPrintLen)
273 if (numFractionDigits == 0)
279 uint32_t totalDigits = numPrintDigits + (precision - numFractionDigits);
280 if (totalDigits > maxPrintLen)
281 totalDigits = maxPrintLen;
283 for (; numPrintDigits < totalDigits; ++numPrintDigits)
284 pOutBuffer[numPrintDigits] =
'0';
287 pOutBuffer[numPrintDigits] =
'\0';
291 uint32_t numPrintDigits;
302 char *pCurOut = pOutBuffer;
306 uint32_t numFractionDigits = numPrintDigits - 1;
307 if (numFractionDigits > 0 && bufferSize > 1)
309 uint32_t maxFractionDigits = bufferSize - 2;
310 if (numFractionDigits > maxFractionDigits)
311 numFractionDigits = maxFractionDigits;
315 pCurOut += (1 + numFractionDigits);
331 if (printExponent != 0)
334 if (printExponent >= 0)
341 printExponent = -printExponent;
void Append(const char c)
PositionalNumeralSystem(unsigned int base, unsigned int digits, const char fractionPoint)
double trunc(double x)
Truncate function.
double log10(double x)
Base 10 logarithm function.
void IntegerToBuffer(double value, unsigned int digits, int *outdigits) const
bool RemoveTrailing(const char c)
double creal(complex z)
Real part of complex number.
int32_t GetExponent() const
void Append(const char *source)
const char * GetSpecialCase(Number *number)
const char * GetText(double number) const
DecimalSystem(unsigned int digits, const char fractionPoint)
unsigned int log2i(unsigned int x)
uint64_t GetMantissa() const
Base class for all numeral systems with a positional notation.
virtual double GetRealValue()=0
double cimag(complex z)
Imaginary part of complex number.
double fabs(double x)
Returns the absolute value of x.
Represent a complex number with 2 components of 15 significant digits.
uint32_t Dragon4(uint64_t mantissa, int32_t exponent, uint32_t mantissaHighBitIdx, bool hasUnequalMargins, tCutoffMode cutoffMode, uint32_t cutoffNumber, char *pOubooluffer, uint32_t bufferSize, int32_t *pOutExponent)
void EnsureGrowth(unsigned int size)
complex GetComplexValue() const
bool Contains(const char c) const
DecimalSystem(unsigned int digits)
virtual const char * GetText(Number *number)
void MemCopy(void *destination, const void *source, unsigned int length)
Copy a block of memory, handling overlap.