Number add(Number n1, Number n2)
{
	return Number(n1.get_x() + n2.get_x());
}
Number Number::operator-(const Number num1) const 
{
	return calculator.sub(value, num1);
}
Number Number::operator*(const Number num1) const 
{
	return calculator.mult(value, num1);
}
Esempio n. 4
0
    /* static function, throws OperationError, has no traces but optional pstate for returned value */
    Value_Ptr op_numbers(enum Sass_OP op, const Number& lhs, const Number& rhs, struct Sass_Inspect_Options opt, const ParserState& pstate, bool delayed)
    {
      double lval = lhs.value();
      double rval = rhs.value();

      if (op == Sass_OP::MOD && rval == 0) {
        return SASS_MEMORY_NEW(String_Quoted, pstate, "NaN");
      }

      if (op == Sass_OP::DIV && rval == 0) {
        std::string result(lval ? "Infinity" : "NaN");
        return SASS_MEMORY_NEW(String_Quoted, pstate, result);
      }

      size_t l_n_units = lhs.numerators.size();
      size_t l_d_units = lhs.numerators.size();
      size_t r_n_units = rhs.denominators.size();
      size_t r_d_units = rhs.denominators.size();
      // optimize out the most common and simplest case
      if (l_n_units == r_n_units && l_d_units == r_d_units) {
        if (l_n_units + l_d_units <= 1 && r_n_units + r_d_units <= 1) {
          if (lhs.numerators == rhs.numerators) {
            if (lhs.denominators == rhs.denominators) {
              Number_Ptr v = SASS_MEMORY_COPY(&lhs);
              v->value(ops[op](lval, rval));
              return v;
            }
          }
        }
      }

      Number_Obj v = SASS_MEMORY_COPY(&lhs);

      if (lhs.is_unitless() && (op == Sass_OP::ADD || op == Sass_OP::SUB || op == Sass_OP::MOD)) {
        v->numerators = rhs.numerators;
        v->denominators = rhs.denominators;
      }

      if (op == Sass_OP::MUL) {
        v->value(ops[op](lval, rval));
        v->numerators.insert(v->numerators.end(),
          rhs.numerators.begin(), rhs.numerators.end()
        );
        v->denominators.insert(v->denominators.end(),
          rhs.denominators.begin(), rhs.denominators.end()
        );
        v->reduce();
      }
      else if (op == Sass_OP::DIV) {
        v->value(ops[op](lval, rval));
        v->numerators.insert(v->numerators.end(),
          rhs.denominators.begin(), rhs.denominators.end()
        );
        v->denominators.insert(v->denominators.end(),
          rhs.numerators.begin(), rhs.numerators.end()
        );
        v->reduce();
      }
      else {
        Number ln(lhs), rn(rhs);
        ln.reduce(); rn.reduce();
        double f(rn.convert_factor(ln));
        v->value(ops[op](lval, rn.value() * f));
      }

      v->pstate(pstate);
      return v.detach();
    }
Esempio n. 5
0
bool Number::is_less(Element *other) const {
	Number *otherValue = Element::as_number(other);
	if (!otherValue) { return false; }
	return _value < otherValue->value();
}
Esempio n. 6
0
Number operator + (const Number& x, const Number& y) {
	return  Number(x.GetNum() + y.GetNum(), x.GetMod());
}
Esempio n. 7
0
Number operator * (const int x, const Number& y) {
	return  Number(x * y.GetNum(), y.GetMod());
}
Esempio n. 8
0
Number operator/( Number l, Number r)
{
	Number inverse(r.denominator(), r.numerator());	
	return l*inverse;
}
static void print_number(const Number & n)
{
	print_ref(n);
	std::cerr << "+ type() : " << n.type() << std::endl;
}
Esempio n. 10
0
bool operator==( Number l, Number r ) { 
    return (l.numerator() == r.numerator() && l.denominator() == r.denominator());
}
Esempio n. 11
0
Number operator+( Number l, Number r)
{
	int lnum = l.num;
	int lden = l.denom;
	int rnum = r.num;
	int rden = r.denom;
	
	// if one is whole number
	if (lden == 1)
	{
		return Number(lnum*rden + rnum, rden);
	}
	if (rden == 1)
	{
		return Number(rnum*lden + lnum, lden);
	}
	// sum of whole numbers
	int sumWhole = lnum/lden + rnum/rden;
	// what is left after subtracting whole number
	lnum = lnum%lden;
	rnum = rnum%rden;	

	// lMaxMul is the largest integer that you can multiply 
	// by lnum to not go over INT_MAX
	int lMaxMul = INT_MAX/abs(lnum);
	int rMaxMul = INT_MAX/abs(rnum);
	int gcdDenom = gcdFunction(lden,rden);

	// if numerators will not go over INT_MAX when
	// multiplied for common denom
	if (lMaxMul >= rden/gcdDenom && rMaxMul >= lden/gcdDenom)
	{
		// if the sum of numerators multiplied by their respective
		// factors will not go over INT_MAX
		if ( INT_MAX- lnum*(rden/gcdDenom) >= rnum*(lden/gcdDenom))
		{
			// numerator (without reducing)
			int OriginalNum = lnum*(rden/gcdDenom) + rnum*(lden/gcdDenom);
			// reduce with both lden and rden
			Number reduce1(OriginalNum, lden);
			Number reduce2(reduce1.numerator(), rden/gcdDenom);	
			return Number(reduce2.numerator() + sumWhole*(reduce1.denominator())*(reduce2.denominator()), (reduce1.denominator())*(reduce2.denominator()));
		} // if 
	} // if
	
	// else, sum of two numbers is over 1 (or under -1)
	l.num = lnum;
	r.num = rnum;
	Number fill = l.fill();
	// fill the first number so it reaches 1 or -1	
	// i.e. if l = 3/5 and r = 4/7, fill = 2/5
	// 3/5 + 4/7 = 3/5 + 2/5 - 2/5 + 4/7
	//           = 1 - 2/5 + 4/7
	if (lnum > 0)
		sumWhole++;
	else
		sumWhole--;	
	Number wholeNumber(sumWhole, 1);	
	Number sumFractions = r - fill;
	return wholeNumber + sumFractions;
}
Esempio n. 12
0
// copy constructor
Number::Number(const Number &c) :
	num(c.numerator()), denom(c.denominator())
{}
Esempio n. 13
0
//-------------------------------------------------------------------------------------------------
// FuntionName: readCharacter
// Purpose: read each character input from stdin, then add it to number object
//          case charater is ' ' => build number.
//          case charater is '\n' => Calculate a sum of squares for Line, then loop for other Line
//          case charater is 'q' => end of test.
//          Other case will be reject.
//--------------------------------------------------------------------------------------------------
bool readCharacter( Number& num, char*& buff, char& sign, bool& isInputIncorrect )
{
   char c = getchar();
   if( c == ENTER )
   {
      putc('\n',stdout);
   }
   else if( c != END_PROGRAM )
   {
      putc(c,stdout);
   }

   if( (c >= '0' && c <= '9') || c == ENTER || c == END_PROGRAM || c == '-' || c == ' ')
   {
      if(c == END_PROGRAM)
      {
         sign = END_PROGRAM;
         return true;
      }
      else
      {
         if( c != ' ' && c != ENTER )
         {
            num.setListCharacter(c);
         }
         else
         {
            bool ret = num.setNumber();
            if(ret)
            {
               countLine += num.getNumber() * num.getNumber();
               num.reset();
            }
            else
            {
               num.reset();
               countLine = 0;
               isInputIncorrect = true;
               return true;
            }

            if( c == ENTER )
            {
               char buf[10];
               sprintf(buf,"%d\n",countLine);
               appenData(buff,buf);
               countLine = 0;
            }
         }

         readCharacter(num, buff, sign, isInputIncorrect);
      }
   }
   else
   {
      num.reset();
      countLine = 0;
      isInputIncorrect = true;
      return true;
   }
}
Esempio n. 14
0
    int Number::compare(const Number& num) const
    {
#ifndef PMP_DISABLE_VECTOR
        if (is_v() || num.is_v())
        {
            bool comparisons[3];
            compare(num, comparisons);
            if (comparisons[0])      return -1;
            else if (comparisons[1]) return 0;
            else if (comparisons[2]) return 1;
            else return -2;
        }
#endif

        floating_type f;
        switch (type())
        {
        case Number::INTEGER:
            switch (num.type())
            {
            case Number::INTEGER:
                return get_i().compare(num.get_i());

            case Number::FLOATING:
                f = to_f();
                return f.compare(num.get_f());

            case Number::RATIONAL:
                f = to_f();
                return f.compare(num.to_f());

            default:
                assert(0);
                return 0;
            }

        case Number::FLOATING:
            switch (num.type())
            {
            case Number::INTEGER:
                f = num.to_f();
                return get_f().compare(f);

            case Number::FLOATING:
                return get_f().compare(num.get_f());

            case Number::RATIONAL:
                return get_f().compare(num.to_f());

            default:
                assert(0);
                return 0;
            }

        case Number::RATIONAL:
            switch (num.type())
            {
            case Number::INTEGER:
                f = num.to_f();
                return to_f().compare(f);

            case Number::FLOATING:
                return to_f().compare(num.get_f());

            case Number::RATIONAL:
                return to_f().compare(num.to_f());

            default:
                assert(0);
                return 0;
            }

        default:
            assert(0);
            return 0;
        }
    }
Esempio n. 15
0
    bool operator == (const Number& x) {
		    return (mod == x.GetMod() && num == x.GetNum());
	}
Esempio n. 16
0
void ExodusII_IO::write_element_data (const EquationSystems & es)
{
  // Be sure the file has been opened for writing!
  if (MeshOutput<MeshBase>::mesh().processor_id() == 0 && !exio_helper->opened_for_writing)
    libmesh_error_msg("ERROR, ExodusII file must be initialized before outputting element variables.");

  // This function currently only works on SerialMeshes. We rely on
  // having a reference to a non-const MeshBase object from our
  // MeshInput parent class to construct a MeshSerializer object,
  // similar to what is done in ExodusII_IO::write().  Note that
  // calling ExodusII_IO::write_timestep() followed by
  // ExodusII_IO::write_element_data() when the underlying Mesh is a
  // ParallelMesh will result in an unnecessary additional
  // serialization/re-parallelization step.
  MeshSerializer serialize(MeshInput<MeshBase>::mesh(), !MeshOutput<MeshBase>::_is_parallel_format);

  // To be (possibly) filled with a filtered list of variable names to output.
  std::vector<std::string> names;

  // If _output_variables is populated, only output the monomials which are
  // also in the _output_variables vector.
  if (_output_variables.size() > 0)
    {
      std::vector<std::string> monomials;
      const FEType type(CONSTANT, MONOMIAL);

      // Create a list of monomial variable names
      es.build_variable_names(monomials, &type);

      // Filter that list against the _output_variables list.  Note: if names is still empty after
      // all this filtering, all the monomial variables will be gathered
      std::vector<std::string>::iterator it = monomials.begin();
      for (; it!=monomials.end(); ++it)
        if (std::find(_output_variables.begin(), _output_variables.end(), *it) != _output_variables.end())
          names.push_back(*it);
    }

  // If we pass in a list of names to "get_solution" it'll filter the variables coming back
  std::vector<Number> soln;
  es.get_solution(soln, names);

  if(soln.empty()) // If there is nothing to write just return
    return;

  // The data must ultimately be written block by block.  This means that this data
  // must be sorted appropriately.
  if(MeshOutput<MeshBase>::mesh().processor_id())
    return;

  const MeshBase & mesh = MeshOutput<MeshBase>::mesh();

#ifdef LIBMESH_USE_COMPLEX_NUMBERS

  std::vector<std::string> complex_names = exio_helper->get_complex_names(names);

  exio_helper->initialize_element_variables(complex_names);

  unsigned int num_values = soln.size();
  unsigned int num_vars = names.size();
  unsigned int num_elems = num_values / num_vars;

  // This will contain the real and imaginary parts and the magnitude
  // of the values in soln
  std::vector<Real> complex_soln(3*num_values);

  for (unsigned i=0; i<num_vars; ++i)
    {

      for (unsigned int j=0; j<num_elems; ++j)
        {
          Number value = soln[i*num_vars + j];
          complex_soln[3*i*num_elems + j] = value.real();
        }
      for (unsigned int j=0; j<num_elems; ++j)
        {
          Number value = soln[i*num_vars + j];
          complex_soln[3*i*num_elems + num_elems +j] = value.imag();
        }
      for (unsigned int j=0; j<num_elems; ++j)
        {
          Number value = soln[i*num_vars + j];
          complex_soln[3*i*num_elems + 2*num_elems + j] = std::abs(value);
        }
    }

  exio_helper->write_element_values(mesh, complex_soln, _timestep);

#else
  exio_helper->initialize_element_variables(names);
  exio_helper->write_element_values(mesh, soln, _timestep);
#endif
}
Esempio n. 17
0
	bool operator != (const Number& x) {
            return (mod != x.GetMod() || num != x.GetNum());
	}
Esempio n. 18
0
Number exponent(Number a,Number b){
	int dec = 1000000000;
	long long gcd;
	Number result;
	long double temp=0;
	a.nomerator = (a.decimalSystem < 0)? 1 : a.nomerator;
	a.denomerator = (a.decimalSystem < 0)? 1 : a.denomerator;
	b.nomerator = (b.decimalSystem < 0)? 1 : b.nomerator;
	b.denomerator = (b.decimalSystem < 0)? 1 : b.denomerator;
	if (a.nomerator == 1 && a.nomerator == 1)
	{
		return a;
	}
	if (a.ifINF && b.nomerator == 0)
	{
		result.setValue(1,1);
		result.ifInited = true;
		return result;
	}
	if (a.ifINF || b.ifINF)
	{
		result.setValue(INT64_MAX,1);
		result.ifINF = true;
		return result;
	}

	temp = static_cast<double>(a.nomerator)/a.denomerator;
	if (temp<0){
		Number res(0,1);
		res.decimalSystem = -1;
		return res;
	}
	if ((static_cast<double>(b.nomerator)/b.denomerator)<0)// Check when exponent is less then zero
		temp = pow(temp,static_cast<double>(b.denomerator)/b.nomerator*(-1));
	else 
		temp = pow(temp,static_cast<double>(b.nomerator)/b.denomerator);
	if (temp >= INT64_MAX){
		result.nomerator=INT64_MAX;
		result.updateDecimalSystem(a,b);
		result.ifINF = true;
		return result;
	}
	if (abs(ceil(temp)-temp)<0.00000001){
		result.nomerator = static_cast< long long>(ceil(temp));
		result.updateDecimalSystem(a,b);
		return result;
	}
	if (abs(floor(temp)-temp)<0.00000001){
		result.nomerator = static_cast< long long>(floor(temp));
		result.updateDecimalSystem(a,b);
		return result;
	}
	long long nextDenomerator = 1;
	while(temp<dec){
		temp*=10;
		nextDenomerator*=10;
	}
	if(static_cast< long long>(temp*10)%10<5)
		result.nomerator=static_cast< long long>(floor(temp));
	else
		result.nomerator=static_cast< long long>(ceil(temp));
	result.denomerator = nextDenomerator;
	gcd = GCD(result.nomerator,result.denomerator);
	if (gcd!=0){
		result.nomerator/=gcd;
		result.denomerator/=gcd;
	}
	result.updateDecimalSystem(a,b);
	return result;
}
Esempio n. 19
0
Number operator * (const Number& x, const int y) {
	return  Number(x.GetNum() * y, x.GetMod());
}
Esempio n. 20
0
Number Number::operator+ (const Number& other)
{
	return Number(getInt() + other.getInt());
}
Esempio n. 21
0
inline void debug_ast(AST_Node* node, string ind = "", Env* env = 0)
{
  if (node == 0) return;
  if (ind == "") cerr << "####################################################################\n";
  if (dynamic_cast<Bubble*>(node)) {
    Bubble* bubble = dynamic_cast<Bubble*>(node);
    cerr << ind << "Bubble " << bubble << " " << bubble->tabs() << endl;
  } else if (dynamic_cast<At_Root_Block*>(node)) {
    At_Root_Block* root_block = dynamic_cast<At_Root_Block*>(node);
    cerr << ind << "At_Root_Block " << root_block << " " << root_block->tabs() << endl;
    if (root_block->block()) for(auto i : root_block->block()->elements()) { debug_ast(i, ind + " ", env); }
  } else if (dynamic_cast<Selector_List*>(node)) {
    Selector_List* selector = dynamic_cast<Selector_List*>(node);

    cerr << ind << "Selector_List " << selector
      << " [block:" << selector->last_block() << "]"
      << (selector->last_block() && selector->last_block()->is_root() ? " [root]" : "")
      << " [@media:" << selector->media_block() << "]"
      << (selector->is_optional() ? " [is_optional]": " -")
      << (selector->has_line_break() ? " [line-break]": " -")
      << (selector->has_line_feed() ? " [line-feed]": " -")
    << endl;

    for(auto i : selector->elements()) { debug_ast(i, ind + " ", env); }

//  } else if (dynamic_cast<Expression*>(node)) {
//    Expression* expression = dynamic_cast<Expression*>(node);
//    cerr << ind << "Expression " << expression << " " << expression->concrete_type() << endl;

  } else if (dynamic_cast<Parent_Selector*>(node)) {
    Parent_Selector* selector = dynamic_cast<Parent_Selector*>(node);
    cerr << ind << "Parent_Selector " << selector;
    cerr << " <" << prettyprint(selector->pstate().token.ws_before()) << ">" << endl;
    debug_ast(selector->selector(), ind + "->", env);

  } else if (dynamic_cast<Complex_Selector*>(node)) {
    Complex_Selector* selector = dynamic_cast<Complex_Selector*>(node);
    cerr << ind << "Complex_Selector " << selector
      << " [block:" << selector->last_block() << "]"
      << " [weight:" << longToHex(selector->specificity()) << "]"
      << (selector->last_block() && selector->last_block()->is_root() ? " [root]" : "")
      << " [@media:" << selector->media_block() << "]"
      << (selector->is_optional() ? " [is_optional]": " -")
      << (selector->has_line_break() ? " [line-break]": " -")
      << (selector->has_line_feed() ? " [line-feed]": " -") << " -> ";
      switch (selector->combinator()) {
        case Complex_Selector::PARENT_OF:   cerr << "{>}"; break;
        case Complex_Selector::PRECEDES:    cerr << "{~}"; break;
        case Complex_Selector::ADJACENT_TO: cerr << "{+}"; break;
        case Complex_Selector::ANCESTOR_OF: cerr << "{ }"; break;
      }
    cerr << " <" << prettyprint(selector->pstate().token.ws_before()) << ">" << endl;
    debug_ast(selector->head(), ind + " ", env);
    debug_ast(selector->tail(), ind + "-", env);
  } else if (dynamic_cast<Compound_Selector*>(node)) {
    Compound_Selector* selector = dynamic_cast<Compound_Selector*>(node);
    cerr << ind << "Compound_Selector " << selector;
    cerr << " [block:" << selector->last_block() << "]";
    cerr << " [weight:" << longToHex(selector->specificity()) << "]";
    // cerr << (selector->last_block() && selector->last_block()->is_root() ? " [root]" : "");
    cerr << " [@media:" << selector->media_block() << "]";
    cerr << (selector->is_optional() ? " [is_optional]": " -");
    cerr << (selector->has_line_break() ? " [line-break]": " -");
    cerr << (selector->has_line_feed() ? " [line-feed]": " -");
    cerr << " <" << prettyprint(selector->pstate().token.ws_before()) << ">" << endl;
    for(auto i : selector->elements()) { debug_ast(i, ind + " ", env); }
  } else if (dynamic_cast<Propset*>(node)) {
    Propset* selector = dynamic_cast<Propset*>(node);
    cerr << ind << "Propset " << selector << " " << selector->tabs() << endl;
    if (selector->block()) for(auto i : selector->block()->elements()) { debug_ast(i, ind + " ", env); }
  } else if (dynamic_cast<Wrapped_Selector*>(node)) {
    Wrapped_Selector* selector = dynamic_cast<Wrapped_Selector*>(node);
    cerr << ind << "Wrapped_Selector " << selector << " <<" << selector->name() << ">>" << (selector->has_line_break() ? " [line-break]": " -") << (selector->has_line_feed() ? " [line-feed]": " -") << endl;
    debug_ast(selector->selector(), ind + " () ", env);
  } else if (dynamic_cast<Pseudo_Selector*>(node)) {
    Pseudo_Selector* selector = dynamic_cast<Pseudo_Selector*>(node);
    cerr << ind << "Pseudo_Selector " << selector << " <<" << selector->name() << ">>" << (selector->has_line_break() ? " [line-break]": " -") << (selector->has_line_feed() ? " [line-feed]": " -") << endl;
    debug_ast(selector->expression(), ind + " <= ", env);
  } else if (dynamic_cast<Attribute_Selector*>(node)) {
    Attribute_Selector* selector = dynamic_cast<Attribute_Selector*>(node);
    cerr << ind << "Attribute_Selector " << selector << " <<" << selector->name() << ">>" << (selector->has_line_break() ? " [line-break]": " -") << (selector->has_line_feed() ? " [line-feed]": " -") << endl;
    debug_ast(selector->value(), ind + "[" + selector->matcher() + "] ", env);
  } else if (dynamic_cast<Selector_Qualifier*>(node)) {
    Selector_Qualifier* selector = dynamic_cast<Selector_Qualifier*>(node);
    cerr << ind << "Selector_Qualifier " << selector << " <<" << selector->name() << ">>" << (selector->has_line_break() ? " [line-break]": " -") << (selector->has_line_feed() ? " [line-feed]": " -") << endl;
  } else if (dynamic_cast<Type_Selector*>(node)) {
    Type_Selector* selector = dynamic_cast<Type_Selector*>(node);
    cerr << ind << "Type_Selector " << selector << " <<" << selector->name() << ">>" << (selector->has_line_break() ? " [line-break]": " -") <<
      " <" << prettyprint(selector->pstate().token.ws_before()) << ">" << endl;
  } else if (dynamic_cast<Selector_Placeholder*>(node)) {

    Selector_Placeholder* selector = dynamic_cast<Selector_Placeholder*>(node);
    cerr << ind << "Selector_Placeholder [" << selector->name() << "] " << selector
      << " [block:" << selector->last_block() << "]"
      << " [@media:" << selector->media_block() << "]"
      << (selector->is_optional() ? " [is_optional]": " -")
      << (selector->has_line_break() ? " [line-break]": " -")
      << (selector->has_line_feed() ? " [line-feed]": " -")
    << endl;

  } else if (dynamic_cast<Selector_Reference*>(node)) {
    Selector_Reference* selector = dynamic_cast<Selector_Reference*>(node);
    cerr << ind << "Selector_Reference " << selector << " @ref " << selector->selector() << endl;
  } else if (dynamic_cast<Simple_Selector*>(node)) {
    Simple_Selector* selector = dynamic_cast<Simple_Selector*>(node);
    cerr << ind << "Simple_Selector " << selector << (selector->has_line_break() ? " [line-break]": " -") << (selector->has_line_feed() ? " [line-feed]": " -") << endl;

  } else if (dynamic_cast<Selector_Schema*>(node)) {
    Selector_Schema* selector = dynamic_cast<Selector_Schema*>(node);
    cerr << ind << "Selector_Schema " << selector
      << " [block:" << selector->last_block() << "]"
      << (selector->last_block() && selector->last_block()->is_root() ? " [root]" : "")
      << " [@media:" << selector->media_block() << "]"
      << (selector->has_line_break() ? " [line-break]": " -")
      << (selector->has_line_feed() ? " [line-feed]": " -")
    << endl;

    debug_ast(selector->contents(), ind + " ");
    // for(auto i : selector->elements()) { debug_ast(i, ind + " ", env); }

  } else if (dynamic_cast<Selector*>(node)) {
    Selector* selector = dynamic_cast<Selector*>(node);
    cerr << ind << "Selector " << selector
      << (selector->has_line_break() ? " [line-break]": " -")
      << (selector->has_line_feed() ? " [line-feed]": " -")
    << endl;

  } else if (dynamic_cast<Media_Query_Expression*>(node)) {
    Media_Query_Expression* block = dynamic_cast<Media_Query_Expression*>(node);
    cerr << ind << "Media_Query_Expression " << block
      << (block->is_interpolated() ? " [is_interpolated]": " -")
    << endl;
    debug_ast(block->feature(), ind + " f) ");
    debug_ast(block->value(), ind + " v) ");

  } else if (dynamic_cast<Media_Query*>(node)) {
    Media_Query* block = dynamic_cast<Media_Query*>(node);
    cerr << ind << "Media_Query " << block
      << (block->is_negated() ? " [is_negated]": " -")
      << (block->is_restricted() ? " [is_restricted]": " -")
    << endl;
    debug_ast(block->media_type(), ind + " ");
    for(auto i : block->elements()) { debug_ast(i, ind + " ", env); }

  } else if (dynamic_cast<Media_Block*>(node)) {
    Media_Block* block = dynamic_cast<Media_Block*>(node);
    cerr << ind << "Media_Block " << block << " " << block->tabs() << endl;
    debug_ast(block->media_queries(), ind + " =@ ");
    debug_ast(block->selector(), ind + " -@ ");
    if (block->block()) for(auto i : block->block()->elements()) { debug_ast(i, ind + " ", env); }
  } else if (dynamic_cast<Feature_Block*>(node)) {
    Feature_Block* block = dynamic_cast<Feature_Block*>(node);
    cerr << ind << "Feature_Block " << block << " " << block->tabs() << endl;
    if (block->block()) for(auto i : block->block()->elements()) { debug_ast(i, ind + " ", env); }
  } else if (dynamic_cast<Block*>(node)) {
    Block* root_block = dynamic_cast<Block*>(node);
    cerr << ind << "Block " << root_block << " " << root_block->tabs() << endl;
    if (root_block->block()) for(auto i : root_block->block()->elements()) { debug_ast(i, ind + " ", env); }
  } else if (dynamic_cast<Warning*>(node)) {
    Warning* block = dynamic_cast<Warning*>(node);
    cerr << ind << "Warning " << block << " " << block->tabs() << endl;
  } else if (dynamic_cast<Error*>(node)) {
    Error* block = dynamic_cast<Error*>(node);
    cerr << ind << "Error " << block << " " << block->tabs() << endl;
  } else if (dynamic_cast<Debug*>(node)) {
    Debug* block = dynamic_cast<Debug*>(node);
    cerr << ind << "Debug " << block << " " << block->tabs() << endl;
  } else if (dynamic_cast<Comment*>(node)) {
    Comment* block = dynamic_cast<Comment*>(node);
    cerr << ind << "Comment " << block << " " << block->tabs() <<
      " <" << prettyprint(block->pstate().token.ws_before()) << ">" << endl;
    debug_ast(block->text(), ind + "// ", env);
  } else if (dynamic_cast<If*>(node)) {
    If* block = dynamic_cast<If*>(node);
    cerr << ind << "If " << block << " " << block->tabs() << endl;
  } else if (dynamic_cast<Return*>(node)) {
    Return* block = dynamic_cast<Return*>(node);
    cerr << ind << "Return " << block << " " << block->tabs() << endl;
  } else if (dynamic_cast<Extension*>(node)) {
    Extension* block = dynamic_cast<Extension*>(node);
    cerr << ind << "Extension " << block << " " << block->tabs() << endl;
    debug_ast(block->selector(), ind + "-> ", env);
  } else if (dynamic_cast<Content*>(node)) {
    Content* block = dynamic_cast<Content*>(node);
    cerr << ind << "Content " << block << " " << block->tabs() << endl;
  } else if (dynamic_cast<Import_Stub*>(node)) {
    Import_Stub* block = dynamic_cast<Import_Stub*>(node);
    cerr << ind << "Import_Stub " << block << " " << block->tabs() << endl;
  } else if (dynamic_cast<Import*>(node)) {
    Import* block = dynamic_cast<Import*>(node);
    cerr << ind << "Import " << block << " " << block->tabs() << endl;
    // vector<string>         files_;
    for (auto imp : block->urls()) debug_ast(imp, "@ ", env);
  } else if (dynamic_cast<Assignment*>(node)) {
    Assignment* block = dynamic_cast<Assignment*>(node);
    cerr << ind << "Assignment " << block << " <<" << block->variable() << ">> " << block->tabs() << endl;
    debug_ast(block->value(), ind + "=", env);
  } else if (dynamic_cast<Declaration*>(node)) {
    Declaration* block = dynamic_cast<Declaration*>(node);
    cerr << ind << "Declaration " << block << " " << block->tabs() << endl;
    debug_ast(block->property(), ind + " prop: ", env);
    debug_ast(block->value(), ind + " value: ", env);
  } else if (dynamic_cast<Keyframe_Rule*>(node)) {
    Keyframe_Rule* has_block = dynamic_cast<Keyframe_Rule*>(node);
    cerr << ind << "Keyframe_Rule " << has_block << " " << has_block->tabs() << endl;
    if (has_block->selector()) debug_ast(has_block->selector(), ind + "@");
    if (has_block->block()) for(auto i : has_block->block()->elements()) { debug_ast(i, ind + " ", env); }
  } else if (dynamic_cast<At_Rule*>(node)) {
    At_Rule* block = dynamic_cast<At_Rule*>(node);
    cerr << ind << "At_Rule " << block << " [" << block->keyword() << "] " << block->tabs() << endl;
    debug_ast(block->value(), ind + "+", env);
    debug_ast(block->selector(), ind + "~", env);
    if (block->block()) for(auto i : block->block()->elements()) { debug_ast(i, ind + " ", env); }
  } else if (dynamic_cast<Each*>(node)) {
    Each* block = dynamic_cast<Each*>(node);
    cerr << ind << "Each " << block << " " << block->tabs() << endl;
    if (block->block()) for(auto i : block->block()->elements()) { debug_ast(i, ind + " ", env); }
  } else if (dynamic_cast<For*>(node)) {
    For* block = dynamic_cast<For*>(node);
    cerr << ind << "For " << block << " " << block->tabs() << endl;
    if (block->block()) for(auto i : block->block()->elements()) { debug_ast(i, ind + " ", env); }
  } else if (dynamic_cast<While*>(node)) {
    While* block = dynamic_cast<While*>(node);
    cerr << ind << "While " << block << " " << block->tabs() << endl;
    if (block->block()) for(auto i : block->block()->elements()) { debug_ast(i, ind + " ", env); }
  } else if (dynamic_cast<Definition*>(node)) {
    Definition* block = dynamic_cast<Definition*>(node);
    cerr << ind << "Definition " << block << " " << block->tabs() << endl;
    if (block->block()) for(auto i : block->block()->elements()) { debug_ast(i, ind + " ", env); }
  } else if (dynamic_cast<Mixin_Call*>(node)) {
    Mixin_Call* block = dynamic_cast<Mixin_Call*>(node);
    cerr << ind << "Mixin_Call " << block << " " << block->tabs() << endl;
    if (block->block()) for(auto i : block->block()->elements()) { debug_ast(i, ind + " ", env); }
  } else if (dynamic_cast<Ruleset*>(node)) {
    Ruleset* ruleset = dynamic_cast<Ruleset*>(node);
    cerr << ind << "Ruleset " << ruleset << " " << ruleset->tabs() << endl;
    debug_ast(ruleset->selector(), ind + " ");
    if (ruleset->block()) for(auto i : ruleset->block()->elements()) { debug_ast(i, ind + " ", env); }
  } else if (dynamic_cast<Block*>(node)) {
    Block* block = dynamic_cast<Block*>(node);
    cerr << ind << "Block " << block << " " << block->tabs() << endl;
    for(auto i : block->elements()) { debug_ast(i, ind + " ", env); }
  } else if (dynamic_cast<Textual*>(node)) {
    Textual* expression = dynamic_cast<Textual*>(node);
    cerr << ind << "Textual ";
    if (expression->type() == Textual::NUMBER) cerr << " [NUMBER]";
    else if (expression->type() == Textual::PERCENTAGE) cerr << " [PERCENTAGE]";
    else if (expression->type() == Textual::DIMENSION) cerr << " [DIMENSION]";
    else if (expression->type() == Textual::HEX) cerr << " [HEX]";
    cerr << expression << " [" << expression->value() << "]" << endl;
  } else if (dynamic_cast<Variable*>(node)) {
    Variable* expression = dynamic_cast<Variable*>(node);
    cerr << ind << "Variable " << expression << " [" << expression->name() << "]" << endl;
    string name(expression->name());
    if (env && env->has(name)) debug_ast(static_cast<Expression*>((*env)[name]), ind + " -> ", env);
  } else if (dynamic_cast<Function_Call_Schema*>(node)) {
    Function_Call_Schema* expression = dynamic_cast<Function_Call_Schema*>(node);
    cerr << ind << "Function_Call_Schema " << expression << "]" << endl;
    debug_ast(expression->name(), ind + "name: ", env);
    debug_ast(expression->arguments(), ind + " args: ", env);
  } else if (dynamic_cast<Function_Call*>(node)) {
    Function_Call* expression = dynamic_cast<Function_Call*>(node);
    cerr << ind << "Function_Call " << expression << " [" << expression->name() << "]" << endl;
    debug_ast(expression->arguments(), ind + " args: ", env);
  } else if (dynamic_cast<Arguments*>(node)) {
    Arguments* expression = dynamic_cast<Arguments*>(node);
    cerr << ind << "Arguments " << expression << "]" << endl;
    for(auto i : expression->elements()) { debug_ast(i, ind + " ", env); }
  } else if (dynamic_cast<Argument*>(node)) {
    Argument* expression = dynamic_cast<Argument*>(node);
    cerr << ind << "Argument " << expression << " [" << expression->value() << "]" << endl;
    debug_ast(expression->value(), ind + " value: ", env);
  } else if (dynamic_cast<Unary_Expression*>(node)) {
    Unary_Expression* expression = dynamic_cast<Unary_Expression*>(node);
    cerr << ind << "Unary_Expression " << expression << " [" << expression->type() << "]" << endl;
    debug_ast(expression->operand(), ind + " operand: ", env);
  } else if (dynamic_cast<Binary_Expression*>(node)) {
    Binary_Expression* expression = dynamic_cast<Binary_Expression*>(node);
    cerr << ind << "Binary_Expression " << expression << " [" << expression->type() << "]" << endl;
    debug_ast(expression->left(), ind + " left:  ", env);
    debug_ast(expression->right(), ind + " right: ", env);
  } else if (dynamic_cast<Map*>(node)) {
    Map* expression = dynamic_cast<Map*>(node);
    cerr << ind << "Map " << expression << " [Hashed]" << endl;
  } else if (dynamic_cast<List*>(node)) {
    List* expression = dynamic_cast<List*>(node);
    cerr << ind << "List " << expression << " (" << expression->length() << ") " <<
      (expression->separator() == Sass::List::Separator::COMMA ? "Comma " : "Space ") <<
      " [delayed: " << expression->is_delayed() << "] " <<
      " [interpolant: " << expression->is_interpolant() << "] " <<
      endl;
    for(auto i : expression->elements()) { debug_ast(i, ind + " ", env); }
  } else if (dynamic_cast<Content*>(node)) {
    Content* expression = dynamic_cast<Content*>(node);
    cerr << ind << "Content " << expression << " [Statement]" << endl;
  } else if (dynamic_cast<Boolean*>(node)) {
    Boolean* expression = dynamic_cast<Boolean*>(node);
    cerr << ind << "Boolean " << expression << " [" << expression->value() << "]" << endl;
  } else if (dynamic_cast<Color*>(node)) {
    Color* expression = dynamic_cast<Color*>(node);
    cerr << ind << "Color " << expression << " [" << expression->r() << ":"  << expression->g() << ":" << expression->b() << "@" << expression->a() << "]" << endl;
  } else if (dynamic_cast<Number*>(node)) {
    Number* expression = dynamic_cast<Number*>(node);
    cerr << ind << "Number " << expression << " [" << expression->value() << expression->unit() << "]" << endl;
  } else if (dynamic_cast<String_Quoted*>(node)) {
    String_Quoted* expression = dynamic_cast<String_Quoted*>(node);
    cerr << ind << "String_Quoted : " << expression << " [" << prettyprint(expression->value()) << "]" <<
      (expression->is_delayed() ? " {delayed}" : "") <<
      (expression->sass_fix_1291() ? " {sass_fix_1291}" : "") <<
      (expression->quote_mark() != 0 ? " {qm:" + string(1, expression->quote_mark()) + "}" : "") <<
      " <" << prettyprint(expression->pstate().token.ws_before()) << ">" << endl;
  } else if (dynamic_cast<String_Constant*>(node)) {
    String_Constant* expression = dynamic_cast<String_Constant*>(node);
    cerr << ind << "String_Constant : " << expression << " [" << prettyprint(expression->value()) << "]" <<
      (expression->is_delayed() ? " {delayed}" : "") <<
      (expression->sass_fix_1291() ? " {sass_fix_1291}" : "") <<
      " <" << prettyprint(expression->pstate().token.ws_before()) << ">" << endl;
  } else if (dynamic_cast<String_Schema*>(node)) {
    String_Schema* expression = dynamic_cast<String_Schema*>(node);
    cerr << ind << "String_Schema " << expression << " " << expression->concrete_type() <<
      (expression->has_interpolants() ? " {has_interpolants}" : "") <<
      endl;
    for(auto i : expression->elements()) { debug_ast(i, ind + " ", env); }
  } else if (dynamic_cast<String*>(node)) {
    String* expression = dynamic_cast<String*>(node);
    cerr << ind << "String " << expression << expression->concrete_type() <<
      " " << (expression->sass_fix_1291() ? "{sass_fix_1291}" : "") <<
      endl;
  } else if (dynamic_cast<Expression*>(node)) {
    Expression* expression = dynamic_cast<Expression*>(node);
    cerr << ind << "Expression " << expression;
    switch (expression->concrete_type()) {
      case Expression::Concrete_Type::NONE: cerr << " [NONE]"; break;
      case Expression::Concrete_Type::BOOLEAN: cerr << " [BOOLEAN]"; break;
      case Expression::Concrete_Type::NUMBER: cerr << " [NUMBER]"; break;
      case Expression::Concrete_Type::COLOR: cerr << " [COLOR]"; break;
      case Expression::Concrete_Type::STRING: cerr << " [STRING]"; break;
      case Expression::Concrete_Type::LIST: cerr << " [LIST]"; break;
      case Expression::Concrete_Type::MAP: cerr << " [MAP]"; break;
      case Expression::Concrete_Type::SELECTOR: cerr << " [SELECTOR]"; break;
      case Expression::Concrete_Type::NULL_VAL: cerr << " [NULL_VAL]"; break;
      case Expression::Concrete_Type::NUM_TYPES: cerr << " [NUM_TYPES]"; break;
    }
    cerr << endl;
  } else if (dynamic_cast<Has_Block*>(node)) {
    Has_Block* has_block = dynamic_cast<Has_Block*>(node);
    cerr << ind << "Has_Block " << has_block << " " << has_block->tabs() << endl;
    if (has_block->block()) for(auto i : has_block->block()->elements()) { debug_ast(i, ind + " ", env); }
  } else if (dynamic_cast<Statement*>(node)) {
    Statement* statement = dynamic_cast<Statement*>(node);
    cerr << ind << "Statement " << statement << " " << statement->tabs() << endl;
  }

  if (ind == "") cerr << "####################################################################\n";
}
Esempio n. 22
0
bool Number::operator== (const Number& other) const
{
	return getInt() == other.getInt();
}
Esempio n. 23
0
bool Number::is_equal(Element *other) const {
	if (Element::is_equal(other)) { return true; }
	Number *otherNum = Element::as_number(other);
	return otherNum && otherNum->value() == _value;
}
Esempio n. 24
0
QDebug operator<<(QDebug dbg, Number n)
{
    dbg.nospace() << n.toString();

    return dbg.space();
}
Esempio n. 25
0
int main()
{
    int e = 0;

    DEBUG(frexp(10, &e));
    DEBUG(rationalize(10, e));
    DEBUG(e);
    return 0;

    testSimplex();

    assert((-Number(0)-Number(2)) == (Number(0) - Number(2)));
    assert((Number(2)-Number(0)) == (Number(2) - -Number(0)));

    DenseMatrix<double> a(3, 3);
    a(0, 0) = 1;
    a(0, 1) = 2;
    a(0, 2) = 0;
    a(1, 0) = 3;
    a(1, 1) = 4;
    a(1, 2) = 4;
    a(2, 0) = 5;
    a(2, 1) = 6;
    a(2, 2) = 3;
    DenseLUP<double> lup(a);
    Vector<double> b;
    b.append(3);
    b.append(7);
    b.append(8);
    Vector<double> x = lup.solve(b);
    for(int i = 0; i < b.getSize(); ++i) DEBUG(x[i]);

    DenseMatrix<double> b1(3, 3);
    b1(0, 0) = 1;
    b1(0, 1) = -1;
    b1(0, 2) = 2;
    b1(1, 0) = -2;
    b1(1, 1) = 1;
    b1(1, 2) = 1;
    b1(2, 0) = -1;
    b1(2, 1) = 2;
    b1(2, 2) = 1;

    DenseLUP<double> lup2(b1);

    DenseMatrix<double> c = lup2.inverse();

    for(int i = 0; i < c.rows; ++i)
    {
        for(int j = 0; j < c.columns; ++j)
        {
            cout << (c(i, j)) << " ";
        }
        cout << endl;
    }

    DenseMatrix<double> b2(3, 3);
    b2(0, 0) = 1;
    b2(0, 1) = 4;
    b2(0, 2) = 5;
    b2(1, 0) = 4;
    b2(1, 1) = 20;
    b2(1, 2) = 32;
    b2(2, 0) = 5;
    b2(2, 1) = 32;
    b2(2, 2) = 64;

    PrimeTable pt(1000000);
    DEBUG(pt.isPrime(91));
    DEBUG(pt.isPrime(107));
    DEBUG(pt.isPrime(17));
    DEBUG(pt.isPrime(1));
    DEBUG(pt.isPrime(2));
    DEBUG(pt.isPrime(3));
    for(int i = 0; i < 100; ++i)
    {
        DEBUG(i);
        DEBUG(pt.isPrime(i));
    }
    Number(99).sqrt().debug();

    (Number(-11) % Number(103)).debug();

    Number n(2);
    Number m = n.power(128);
    m.debug();
    m >>= 125;
    m.debug();
    m <<= 125;
    m.debug();
    m = gcd(m, Number(3));
    m = modInverse(Number(4), Number(7));
    m.debug();
    DEBUG(isPrime(Number((8616460799ull))));//no
    DEBUG(isPrime(Number((3ull))));//yes

    Vector<unsigned char> igits = m.toDigitVector();
    for(int i = 0; i < igits.getSize(); ++i) DEBUG(int(igits[i]));

	return 0;
}
Esempio n. 26
0
int main()
{
  int x1, x2;
  double y1, y2;

  cout << "Please enter two integers: " << endl;
  cin >> x1;
  cin >> x2;

  // Instantiate "int" objects
  Number <int> m (x1);
  Number <int> n (x2);

  cout << "Calling printValue() on objects 'm' and 'n': " << endl;
  m.printValue();
  n.printValue();

  cout << "Applying '+=' operator to 'm' with input 'n': " << endl;
  m += n;
  m.printValue();

  cout << "Applying '+' operator to define new variable 'sum': " << endl;
  Number<int> sum = m + n;
  sum.printValue();

  // Repeating for doubles
  cout << "Now please enter two doubles and repeat: " << endl;
  cin >> y1;
  cin >> y2;

  Number <double> x (y1);
  Number <double> y (y2);
  
  cout << "Calling printValue() on double objects 'x' and 'y': " << endl;
  x.printValue();
  y.printValue();

  cout << "Applying '+=' operator: " << endl;
  x += y;
  x.printValue();

  cout << "Applying '+' operator to define new variable 'z': " << endl;
  Number<double> z = x + y;
  z.printValue();
}
Number Number::operator/(const Number num1) const 
{
	return calculator.divi(value, num1);
}
Esempio n. 28
0
    Number operator = (const Number x) {
		mod = x.GetMod();
		num = x.GetNum() % mod;
        return *this;
	}
Esempio n. 29
0
void BlockParser::parseVarPart(QString stream, int& pos) {
	skip(stream, pos);
	if (stream.mid(pos,4).compare("var ") == 0) {
		pos+=4;
		skip(stream, pos);
		if (!checkForEndOfStream(stream, pos) &&
				stream.mid(pos,4).compare("int ") != 0 && stream.mid(pos,7).compare("double ") != 0)
		{
			QString errorTypeName = stream.mid(pos);
			errorTypeName.truncate(errorTypeName.indexOf(" "));
			error(unexpectedSymbol, QString::number(pos+1), "int\' or \'double", errorTypeName);
			return;
		}

		while (pos < stream.length() &&
			   (stream.mid(pos,4).compare("int ") == 0 || stream.mid(pos,7).compare("double ") == 0))
		{
			Number::Type curType;
			if (stream.mid(pos,4).compare("int ") == 0) {
				curType = Number::intType;
				pos+=4;
			} else {
				curType = Number::doubleType;
				pos+=7;
			}
			skip(stream, pos);
			while (pos < stream.length() && stream.at(pos).toAscii() != ';') {
				skip(stream, pos);
				QString variable = parseIdentifier(stream, pos);
				if ((mReservedVariables.contains(variable)) || (isFunction(variable))) {
					hasParseErrors = true;
					mErrorReporter->addError(QObject::tr("Using reserved variable %1").arg(variable), mCurrentId);
					return;
				}
				if (hasParseErrors) {
					return;
				}
				skip(stream, pos);

				Number n;
				if (checkForEndOfStream(stream, pos)) {
					return;
				}
				switch (stream.at(pos).toAscii()) {
				case '=':
					pos++;
					skip(stream, pos);
					n = parseExpression(stream, pos);
					n.setProperty("Type", curType);
					mVariables[variable] = n;
					break;
				case ',':
					pos++;
					mVariables[variable] = n;
					skip(stream, pos);
					if (pos == stream.length()) {
						error(unexpectedEndOfStream, QString::number(pos+1));
						return;
					}
					if (stream.at(pos).toAscii() == ';') {
						error(unexpectedSymbol, QString::number(pos+1), "\'letter",
							  QString(stream.at(pos).toAscii()));
						return;
					}
					break;
				default:
					if (!checkForColon(stream, pos)) {
						return;
					}
					mVariables[variable] = n;
					break;
				}
				skip(stream, pos);
			}

			if (hasParseErrors) {
				return;
			}
			pos++;
			skip(stream, pos);
		}
	}
}
Esempio n. 30
0
	// перегрузка оператора *
	Number operator*(Number n2)
	{
		return Number(x * n2.get_x());
	}