X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=src%2Fparanoidnumber.cpp;h=6b602c0ececc1b17d5d20607394131cdaf12141d;hb=748d002a813bbe6309dd22259bdce3278c02b0c8;hp=40071e15f89f7585562cdf741e43e51c3b7c5b08;hpb=71df61ab8ea302247ad35ccdc973bc8e0cafd5b1;p=ipdf%2Fcode.git diff --git a/src/paranoidnumber.cpp b/src/paranoidnumber.cpp index 40071e1..6b602c0 100644 --- a/src/paranoidnumber.cpp +++ b/src/paranoidnumber.cpp @@ -29,7 +29,7 @@ ParanoidNumber::~ParanoidNumber() ParanoidNumber::ParanoidNumber(const string & str) : m_value(0), m_next() { #ifdef PARANOID_SIZE_LIMIT - m_size = 0; + m_size = 1; #endif #ifdef PARANOID_CACHE_RESULTS m_cached_result = NAN; @@ -430,16 +430,15 @@ ParanoidNumber * ParanoidNumber::OperationTerm(ParanoidNumber * b, Optype op, Pa m_cached_result = NAN; #endif #ifdef PARANOID_SIZE_LIMIT - if (m_size >= PARANOID_SIZE_LIMIT) + if (m_size + b->m_size >= PARANOID_SIZE_LIMIT) { + this->operator=(this->Digit()); if (op == ADD) - { - m_value += b->Digit() / GetFactors(); - } + m_value += b->Digit(); else - { - m_value -= b->Digit() / GetFactors(); - } + m_value -= b->Digit(); + m_size = 1; + //Debug("Cut off %p", this); return b; } //Debug("At size limit %d", m_size); @@ -542,7 +541,7 @@ ParanoidNumber * ParanoidNumber::OperationTerm(ParanoidNumber * b, Optype op, Pa //merge->m_next[*merge_op].push_back(b); m_next[op].push_back(b); #ifdef PARANOID_SIZE_LIMIT - m_size += 1+b->m_size; + m_size += b->m_size; #endif } else @@ -565,17 +564,16 @@ ParanoidNumber * ParanoidNumber::OperationFactor(ParanoidNumber * b, Optype op, m_cached_result = NAN; #endif #ifdef PARANOID_SIZE_LIMIT - if (m_size >= PARANOID_SIZE_LIMIT) + if (m_size + b->m_size >= PARANOID_SIZE_LIMIT) { + this->operator=(this->Digit()); if (op == MULTIPLY) m_value *= b->Digit(); else m_value /= b->Digit(); - - for (auto n : m_next[ADD]) - delete n->OperationFactor(new ParanoidNumber(*b), op); - for (auto n : m_next[SUBTRACT]) - delete n->OperationFactor(new ParanoidNumber(*b), op); + m_size = 1; + + //Debug("Cut off %p", this); return b; } @@ -692,7 +690,7 @@ ParanoidNumber * ParanoidNumber::OperationFactor(ParanoidNumber * b, Optype op, delete(sub->OperationFactor(new ParanoidNumber(*cpy_b), op)); #ifdef PARANOID_SIZE_LIMIT - m_size += 1+b->m_size; + m_size += b->m_size; #endif } //assert(SanityCheck()); @@ -785,7 +783,7 @@ bool ParanoidNumber::Simplify(Optype op) if (result != NULL) { #ifdef PARANOID_SIZE_LIMIT - m_size -= (1+result->m_size); + m_size -= result->m_size; #endif *m = NULL; delete(result); @@ -802,7 +800,7 @@ bool ParanoidNumber::Simplify(Optype op) #ifdef PARANOID_SIZE_LIMIT if (Operation(n, op) == n) { - m_size -= (1+n->m_size); + m_size -= n->m_size; delete n; } #else