// ------------------------------------- // Appends the digit to the digit list if it's not out of scope. // Ignores the digit, otherwise. // // This function is horribly inefficient to implement with decNumber because // the digits are stored least significant first, which requires moving all // existing digits down one to make space for the new one to be appended. // void DigitList::append(char digit) { U_ASSERT(digit>='0' && digit<='9'); // Ignore digits which exceed the precision we can represent // And don't fix for larger precision. Fix callers instead. if (decNumberIsZero(fDecNumber)) { // Zero needs to be special cased because of the difference in the way // that the old DigitList and decNumber represent it. // digit cout was zero for digitList, is one for decNumber fDecNumber->lsu[0] = digit & 0x0f; fDecNumber->digits = 1; fDecNumber->exponent--; // To match the old digit list implementation. } else { int32_t nDigits = fDecNumber->digits; if (nDigits < fContext.digits) { int i; for (i=nDigits; i>0; i--) { fDecNumber->lsu[i] = fDecNumber->lsu[i-1]; } fDecNumber->lsu[0] = digit & 0x0f; fDecNumber->digits++; // DigitList emulation - appending doesn't change the magnitude of existing // digits. With decNumber's decimal being after the // least signficant digit, we need to adjust the exponent. fDecNumber->exponent--; } } internalClear(); }
/** * Set the DigitList from a decimal number string. * * The incoming string _must_ be nul terminated, even though it is arriving * as a StringPiece because that is what the decNumber library wants. * We can get away with this for an internal function; it would not * be acceptable for a public API. */ void DigitList::set(const StringPiece &source, UErrorCode &status) { if (U_FAILURE(status)) { return; } // Figure out a max number of digits to use during the conversion, and // resize the number up if necessary. int32_t numDigits = source.length(); if (numDigits > fContext.digits) { // fContext.digits == fStorage.getCapacity() decNumber *t = fStorage.resize(numDigits, fStorage.getCapacity()); if (t == NULL) { status = U_MEMORY_ALLOCATION_ERROR; return; } fDecNumber = t; fContext.digits = numDigits; } fContext.status = 0; uprv_decNumberFromString(fDecNumber, source.data(), &fContext); if ((fContext.status & DEC_Conversion_syntax) != 0) { status = U_DECIMAL_NUMBER_SYNTAX_ERROR; } internalClear(); }
/* * Divide * The number will _not_ be expanded for inexact results. * TODO: probably should expand some, for rounding increments that * could add a few digits, e.g. .25, but not expand arbitrarily. */ void DigitList::div(const DigitList &other, UErrorCode &status) { if (U_FAILURE(status)) { return; } uprv_decNumberDivide(fDecNumber, fDecNumber, other.fDecNumber, &fContext); internalClear(); }
void DigitList::setDigit(int32_t i, char v) { int32_t count = fDecNumber->digits; U_ASSERT(i<count); U_ASSERT(v>='0' && v<='9'); v &= 0x0f; fDecNumber->lsu[count-i-1] = v; internalClear(); }
void DigitList::setPositive(UBool s) { if (s) { fDecNumber->bits &= ~DECNEG; } else { fDecNumber->bits |= DECNEG; } internalClear(); }
/** * Round the representation to the given number of digits. * @param maximumDigits The maximum number of digits to be shown. * Upon return, count will be less than or equal to maximumDigits. */ void DigitList::round(int32_t maximumDigits) { int32_t savedDigits = fContext.digits; fContext.digits = maximumDigits; uprv_decNumberPlus(fDecNumber, fDecNumber, &fContext); fContext.digits = savedDigits; uprv_decNumberTrim(fDecNumber); internalClear(); }
/** * Set the DigitList from a decimal number string. * * The incoming string _must_ be nul terminated, even though it is arriving * as a StringPiece because that is what the decNumber library wants. * We can get away with this for an internal function; it would not * be acceptable for a public API. */ void DigitList::set(StringPiece source, UErrorCode &status, uint32_t /*fastpathBits*/) { if (U_FAILURE(status)) { return; } #if 0 if(fastpathBits==(kFastpathOk|kNoDecimal)) { int32_t size = source.size(); const char *data = source.data(); int64_t r = 0; int64_t m = 1; // fast parse while(size>0) { char ch = data[--size]; if(ch=='+') { break; } else if(ch=='-') { r = -r; break; } else { int64_t d = ch-'0'; //printf("CH[%d]=%c, %d, *=%d\n", size,ch, (int)d, (int)m); r+=(d)*m; m *= 10; } } //printf("R=%d\n", r); set(r); } else #endif { // Figure out a max number of digits to use during the conversion, and // resize the number up if necessary. int32_t numDigits = source.length(); if (numDigits > fContext.digits) { // fContext.digits == fStorage.getCapacity() decNumber *t = fStorage.resize(numDigits, fStorage.getCapacity()); if (t == NULL) { status = U_MEMORY_ALLOCATION_ERROR; return; } fDecNumber = t; fContext.digits = numDigits; } fContext.status = 0; uprv_decNumberFromString(fDecNumber, source.data(), &fContext); if ((fContext.status & DEC_Conversion_syntax) != 0) { status = U_DECIMAL_NUMBER_SYNTAX_ERROR; } } internalClear(); }
void DigitList::setCount(int32_t c) { U_ASSERT(c <= fContext.digits); if (c == 0) { // For a value of zero, DigitList sets all fields to zero, while // decNumber keeps one digit (with that digit being a zero) c = 1; fDecNumber->lsu[0] = 0; } fDecNumber->digits = c; internalClear(); }
/* * Multiply * The number will be expanded if need be to retain full precision. * In practice, for formatting, multiply is by 10, 100 or 1000, so more digits * will not be required for this use. */ void DigitList::mult(const DigitList &other, UErrorCode &status) { fContext.status = 0; int32_t requiredDigits = this->digits() + other.digits(); if (requiredDigits > fContext.digits) { reduce(); // Remove any trailing zeros int32_t requiredDigits = this->digits() + other.digits(); ensureCapacity(requiredDigits, status); } uprv_decNumberMultiply(fDecNumber, fDecNumber, other.fDecNumber, &fContext); internalClear(); }
void DigitList::setDecimalAt(int32_t d) { U_ASSERT((fDecNumber->bits & DECSPECIAL) == 0); // Not Infinity or NaN U_ASSERT(d-1>-999999999); U_ASSERT(d-1< 999999999); int32_t adjustedDigits = fDecNumber->digits; if (decNumberIsZero(fDecNumber)) { // Account for difference in how zero is represented between DigitList & decNumber. adjustedDigits = 0; } fDecNumber->exponent = d - adjustedDigits; internalClear(); }
void DigitList::roundFixedPoint(int32_t maximumFractionDigits) { reduce(); // Remove trailing zeros. if (fDecNumber->exponent >= -maximumFractionDigits) { return; } decNumber scale; // Dummy decimal number, but with the desired number of uprv_decNumberZero(&scale); // fraction digits. scale.exponent = -maximumFractionDigits; scale.lsu[0] = 1; uprv_decNumberQuantize(fDecNumber, fDecNumber, &scale, &fContext); reduce(); internalClear(); }
/** * Round the representation to the given number of digits. * @param maximumDigits The maximum number of digits to be shown. * Upon return, count will be less than or equal to maximumDigits. */ void DigitList::round(int32_t maximumDigits) { reduce(); if (maximumDigits >= fDecNumber->digits) { return; } int32_t savedDigits = fContext.digits; fContext.digits = maximumDigits; uprv_decNumberPlus(fDecNumber, fDecNumber, &fContext); fContext.digits = savedDigits; uprv_decNumberTrim(fDecNumber); reduce(); internalClear(); }
QXmlStreamReader& SimpleLoggerRoutingInfo::read(QXmlStreamReader& reader) { internalClear(); //qDebug("Ready SimpleLoggerRoutingInfo::read"); QString name; while (!reader.atEnd()) { if (reader.isStartElement()) { name = reader.name().toString(); //qDebug(qPrintable(QString("Found start element thingy name %1").arg(name))); if (QString::compare(name, "SimpleLoggerRoutingInfo", Qt::CaseInsensitive) == 0) { readInternals(reader, "1"); return reader; } else { reader.raiseError(QObject::tr("Not a SimpleLoggerRoutingInfo")); } } else if (reader.isEndElement()) { return reader; } reader.readNext(); } return reader; }
void DigitList::shiftDecimalRight(int32_t n) { fDecNumber->exponent += n; internalClear(); }
GridMaker::~GridMaker() { internalClear(); }
void CollisionBlock::clear(){ internalClear(); }
GenericObject::~GenericObject() { internalClear(); }
void StrList::clear() { internalClear(); }
//Destruktor, kör internalClear funktionen för att rensa mapparna ResourceHandler::~ResourceHandler() { internalClear(); }
StrList::~StrList() { internalClear(); }