BigReal &BigReal::multPow10(BRExpoType exp) {
  DEFINEMETHODNAME;
  if(!_isnormal()) {
    return *this;
  }
  int m = exp % LOG10_BIGREALBASE;
  BRExpoType   n = exp / LOG10_BIGREALBASE;
  if(m == 0) {
    m_expo += n;
    m_low  += n;
    if(m_expo > BIGREAL_MAXEXPO || m_expo < BIGREAL_MINEXPO) {
      throwBigRealInvalidArgumentException(method, _T("Invalid m_expo:%s"), format1000(m_expo).cstr());
    }
  } else {
    if(m < 0) {
      m = -m;
    }
    const BRDigitType s = pow10(m);
    const BRDigitType t = BIGREALBASE / s;
    if(exp > 0) { // shift left
      Digit *p = m_first;
      Digit *q = p->next; // *this != 0 => p != NULL
      if(p->n >= t) {
        insertDigit(p->n / t);
        m_expo++;
      }
      while(q) {
        p->n = q->n/t + (p->n%t) * s;
        p = q;
        q = q->next;
      }
      p->n = (p->n%t) * s;
    } else { // exp < 0. shift right
      Digit *p = m_last;
      Digit *q = p->prev; // *this != 0 => p != NULL
      appendDigit((p->n % s) * t);
      m_low--;
      while(q) {
        p->n = p->n/s + (q->n%s) * t;
        p = q;
        q = q->prev;
      }
      p->n /= s;
    }
    m_expo += n;
    m_low  += n;
    trimZeroes();
  }
  return *this;
}
Beispiel #2
0
unsigned int ValueCodec::decode( unsigned char* byte, const QString& digits, unsigned int pos ) const
{
    const unsigned int oldPos = pos;
    const unsigned int left = digits.size() - pos;

    unsigned int d = encodingWidth();
    if( left < d )
        d = left;

    unsigned char result = 0;
    while( d > 0 )
    {
        if( !appendDigit(&result,digits.at(pos).toLatin1()) ) // TODO: use QChar.digitValue()
            break;

        ++pos;
        --d;
    }

    *byte = result;
    return pos - oldPos;
}
void BigReal::load(ByteInputStream &s) {
  int b = s.getByte();
  if(b == EOF) {
    throwBigRealException(_T("Unexpected enf of stream"));
  }
  if(b & ZERO_FLAG) {
    setToZero();
  } else {
    clearDigits();
    m_negative = (b & NEGATIVE_FLAG) ? true : false;
    s.getBytesForced((BYTE*)&m_expo, sizeof(m_expo));
    size_t length;
    s.getBytesForced((BYTE*)&length, sizeof(length));
    for(size_t i = 0; i < length; i++) {
      BRDigitType d;
      s.getBytesForced((BYTE*)(&d), sizeof(d));
      assert(d < BIGREALBASE);
      appendDigit(d);
    }
    m_low = m_expo - length + 1;
  }
}
Beispiel #4
0
void UnicalcMath::press9(){
	appendDigit(9);
	emit changed();
}