// Assume src._isnormal() && m_first == m_last == NULL void BigReal::copyAllDigits(const BigReal &src) { assert(src._isnormal()); const Digit *sd = src.m_first; Digit *dd, *p; (m_first = p = newDigit())->prev = NULL; p->n = sd->n; for(; sd = sd->next; p = dd) { (dd = newDigit())->prev = p; dd->n = sd->n; p->next = dd; } (m_last = p)->next = NULL; }
// Assume src._isnormal() && length <= src.getLength() && m_first == m_last == NULL void BigReal::copyDigits(const BigReal &src, size_t length) { assert(src._isnormal()); if(length--) { const Digit *sd = src.m_first; (m_first = newDigit())->prev = NULL; Digit *p = m_first; p->n = sd->n; Digit *dd; for(sd = sd->next; length--; sd = sd->next, p = dd) { (dd = newDigit())->prev = p; dd->n = sd->n; p->next = dd; ; } (m_last = p)->next = NULL; } else { m_first = m_last = NULL; } }
// Assume *this != zero. ie m_first != NULL (and m_last != NULL) void BigReal::insertZeroDigits(size_t count) { Digit *p; for(p = m_first; count--;) { Digit *q = newDigit(); q->n = 0; q->next = p; p->prev = q; p = q; } (m_first = p)->prev = NULL; }
void BigReal::insertBorrowDigitsAfter(Digit *p, size_t count) { Digit *q = p->next; if(q) { // p has a tail => p != last while(count--) { // Insert count digits just after p, making the new chain grow at the HEAD (=q) Digit *r = newDigit(); r->n = BIGREALBASE - 1; r->next = q; q->prev = r; q = r; } (p->next = q)->prev = p; // No need to modify m_last. p has a tail, so it is not m_last } else { // q == NULL => p == m_last (and maybe m_first too) for(q = p; count--;) { // Append count digits after each other, making the new chain grow at the END (=q) Digit *r = newDigit(); r->n = BIGREALBASE - 1; r->prev = q; q->next = r; q = r; } (m_last = q)->next = NULL; } }
void BigReal::insertDigit(BRDigitType n) { // assert(n < BIGREALBASE); Digit *p = newDigit(); p->n = n; p->next = m_first; p->prev = NULL; if(m_last == NULL) { m_last = p; } else { m_first->prev = p; } m_first = p; }
void BigReal::insertAfter(Digit *p, BRDigitType n) { // assert(n < BIGREALBASE); Digit *q = newDigit(); q->n = n; q->prev = p; q->next = p->next; if(p->next) { p->next->prev = q; } else { m_last = q; } p->next = q; }
static void processDigit(chanState *pState,uInt8 rawDigit) { //calls newDigit to insert into buffer after converting to ascii uInt8 asciiChar; switch (rawDigit) { case 0xA : asciiChar = '0'; break; case 0xB: asciiChar = '*'; break; case 0xC: asciiChar = '#'; break; default: asciiChar= '0' + rawDigit; break; } newDigit (pState,asciiChar); }