int dp = 0;
int end = 0;
+ bool negate = str[0] == '-';
+ if (negate)
+ {
+ dp++;
+ end++;
+ }
while (str[dp] != '\0' && str[dp] != '.')
{
++dp;
while (str[end] != '\0')
++end;
ParanoidNumber m(1);
- for (int i = dp-1; i >= 0; --i)
+ for (int i = dp-1; i >= negate; --i)
{
ParanoidNumber b(str[i]-'0');
b*=m;
b*=n;
this->operator+=(b);
}
+
+ if (negate)
+ Negate();
+
+ #ifdef PARANOID_COMPARE_EPSILON
+ double d = strtod(str.c_str(), NULL);
+ CompareForSanity(d, d);
+ #endif
}
ParanoidNumber & ParanoidNumber::operator=(const ParanoidNumber & a)
#ifdef PARANOID_SIZE_LIMIT
if (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 = 0;
+ Debug("Cut off %p", this);
return b;
}
//Debug("At size limit %d", m_size);
#ifdef PARANOID_SIZE_LIMIT
if (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 = 0;
+
+ Debug("Cut off %p", this);
return b;
}
return true;
}
+void ParanoidNumber::Negate()
+{
+ swap(m_next[ADD], m_next[SUBTRACT]);
+ m_value = -m_value;
+}
+
#ifdef PARANOID_USE_ARENA
void * ParanoidNumber::operator new(size_t s)