Exemplo n.º 1
0
bool CNormalProduct::remove(const CNormalItemPower& itemPower)
{
  std::set <CNormalItemPower*, compareItemPowers>::iterator it;
  std::set <CNormalItemPower*, compareItemPowers>::iterator itEnd = mItemPowers.end();

  for (it = mItemPowers.begin(); it != itEnd; ++it)
    {
      if ((*it)->getItem() == itemPower.getItem())
        {
          C_FLOAT64 dif = (*it)->getExp() - itemPower.getExp();

          if (dif >= 1.0E-100)
            {
              (*it)->setExp(dif);
              return true;
            }

          if (fabs(dif) < 1.0E-100)
            {
              delete(*it);
              mItemPowers.erase(it);
              return true;
            }

          return false;
        }
    }

  return false;
}
Exemplo n.º 2
0
C_FLOAT64 CNormalSum::checkFactor(const CNormalItemPower& itemPower) const //sum does not contain fractions!!
{
    // TODO incorporate the denominator of the product if it is not 1
    C_FLOAT64 exp = itemPower.getExp();
    std::set<CNormalProduct*, compareProducts >::const_iterator it;
    std::set<CNormalProduct*, compareProducts >::const_iterator itEnd = mProducts.end();

    for (it = mProducts.begin(); it != itEnd; ++it)
    {
        bool containsFactor = false;
        std::set<CNormalItemPower*, compareItemPowers >::const_iterator it2;
        std::set<CNormalItemPower*, compareItemPowers >::const_iterator it2End = (*it)->getItemPowers().end();

        for (it2 = (*it)->getItemPowers().begin(); it2 != it2End; ++it2)
        {
            if ((*it2)->getItem().areEqual(itemPower.getItem()))
            {
                exp = (*it2)->getExp() < exp ? (*it2)->getExp() : exp;
                containsFactor = true;
                break;
            }
        }

        if (containsFactor == false)
            return 0;
    }

    return exp;
}
Exemplo n.º 3
0
/**
 * Multiply an itempower to this product.
 * @return true.
 */
bool CNormalProduct::multiply(const CNormalItemPower& itemPower)
{
  if (fabs(mFactor) < 1.0E-100)
    return true;
  std::set <CNormalItemPower*, compareItemPowers >::const_iterator it;
  std::set <CNormalItemPower*, compareItemPowers >::const_iterator itEnd = mItemPowers.end();
  for (it = mItemPowers.begin(); it != itEnd; ++it)
    {
      if ((*it)->getItem().areEqual(itemPower.getItem()))
        {
          (*it)->setExp((*it)->getExp() + itemPower.getExp());
          return true;
        }
    }
  CNormalItemPower* tmp = new CNormalItemPower(itemPower);
  mItemPowers.insert(tmp);
  return true;
}