Example #1
0
TValBool Real::Greater ( const Real & cv ) const
{
	// if both are undefined:
	if ( IsUndefined() && cv.IsUndefined() )
		return TValBool::tfalse;

	// if only one is undefined:
	else if ( IsUndefined() || cv.IsUndefined() )
		return TValBool::tundef;

	// else they are real numbers.
	return rvalue > cv.value();
}
Example #2
0
bool Integer::operator>(Numeric* c)const{
  Integer* entier = dynamic_cast<Integer*>(c);
  if(entier==NULL){
    Real* reel = dynamic_cast<Real*>(c);
    if (reel == NULL){
      Rational* rationnel = dynamic_cast<Rational*>(c);
      if (rationnel == NULL)
        return false;
      return ((double)_value > rationnel->toDouble());
    }
    return ((double)_value > reel->getValue());
  }
  return (_value > entier->getValue());
}
Example #3
0
void SqrtRep::computeApproxValue(const extLong& relPrec,
                                 const extLong& absPrec) {
  extLong r = relPrec + relPrec + EXTLONG_EIGHT; // chenli: ???
  extLong a = absPrec + absPrec + EXTLONG_EIGHT;
  extLong pr = - lMSB() + r;
  extLong p  = pr < a ? pr : a;

  Real val = child->getAppValue(r, a);
  if (incrementalEvalFlag) {
    if (appValue() == CORE_REAL_ZERO)
      appValue() = val;
    appValue() = val.sqrt(p, appValue().BigFloatValue());
  } else
    appValue() = val.sqrt(p);
}
Example #4
0
TValBool Real::Equal ( const Real & cv ) const
{
	// if both are undefined then are equals.
	if ( IsUndefined() && cv.IsUndefined() )
		return TValBool::ttrue;

	// if only one is undefined:
	else if ( IsUndefined() || cv.IsUndefined() )
		return TValBool::tundef;

	// else they are real numbers.
	return (rvalue >= cv.value() - RealPrecision::Tol.precision()  &&
		rvalue <= cv.value() + RealPrecision::Tol.precision() ) ?
		TValBool::ttrue : TValBool::tfalse;
}
Example #5
0
void computeExactFlags_temp(ConstRep* t, const Real &value) {
  // Chen Li: the following is incorrect:
  //    uMSB = lMSB = value.MSB();
  // because the value could be a BigFloat which is an interval.
  if (value.isExact()) {
    t->uMSB() = t->lMSB() = value.MSB();
  } else {
    t->uMSB() = value.uMSB();
    t->lMSB() = value.lMSB();
    core_error("Leaves in DAG is not exact!", __FILE__, __LINE__, true);
  }

  t->sign() = value.sign();
  // t->length() = value.length();
  t->measure() = value.height(); // for rationals and integers,
  // measure = height.

  // BFMSS[2,5] bound.
  value.ULV_E(t->u25(), t->l25(), t->v2p(), t->v2m(), t->v5p(), t->v5m());

  // The original BFMSS parameters can be set from the BFMSS[2,5] parameters.
  // Here we just need them locally.
  extLong u_e = t->u25() + t->v2p() + ceilLg5(t->v5p());
  extLong l_e = t->l25() + t->v2m() + ceilLg5(t->v5m());

#ifdef ORIGINAL_BFMSS
  // To go back to the original BFMSS :
  t->u25() = u_e;
  t->l25() = l_e;
  t->v2p() = t->v2m() = t->v5p() = t->v5m() = EXTLONG_ZERO;
#elif defined BFMSS_2_ONLY
  // To go back to BFMSS[2] only :
  t->u25() = t->u25() + ceilLg5(t->v5p());
  t->l25() = t->l25() + ceilLg5(t->v5m());
  t->v5p() = t->v5m() = EXTLONG_ZERO;
#endif

  if (l_e == EXTLONG_ZERO) {           // no divisions introduced
    t->high() = u_e;
    t->low() = EXTLONG_ONE - u_e; // - (u_e - 1)
  } else {
    t->high() = u_e - l_e + EXTLONG_ONE;
    t->low() = EXTLONG_TWO - t->high();
  }

  t->lc() = l_e;
  t->tc() = u_e;

  // set BigRat value
  if (rationalReduceFlag) {
    t->ratFlag() = 1;
    t->ratValue() = new BigRat(value.BigRatValue());
  }

  t->flagsComputed() = true;
}
void Complex::mul(Object *b)
{
     if(b->getType() == "Complex")
     {
         Complex *c = (Complex *)b; 
         this->real = (this->real)*(c->getValue1())-(this->imag)*(c->getValue2());
         this->imag = (this->real)*(c->getValue2())+(this->imag)*(c->getValue1()); 
     } 
     else if(b->getType() == "Real") 
     {
          Real *c = (Real *)b;
          this->real *= c->getValue(); 
          this->imag *= c->getValue(); 
     }
     else if(b->getType() == "Rational")
     {
          //Rational->Real 
          Real *c = (Real *)new Real(0.0);//这种垃圾如何回收? 
          Rational *d = (Rational *)b; 
          c->changeValue((double)(d->getValue1())/(d->getValue2()));  
          this->mul(c); //递归 
          delete c;          //这里回收挖~ 
     }
     else if(b->getType() == "Integer")
     {
          //Integer->Rational
          Rational *c = (Rational *)new Rational(0,1);
          Integer *d = (Integer *)b;
          c->changeValue1(d->getValue());
          this->mul(c);  //递归 
          delete c; 
     } 
     else
     {
         cerr << "Error calcution"  << endl; 
     } 
}
Example #7
0
int main() {
	int n, m, w;
	Real ans;

	scanf("%d%d%d", &n, &m, &w);
	for (int i = 0; i < m; ++i) {
		scanf("%d", &com[i].w);
	}
	for (int i = 0; i < m; ++i) {
		scanf("%d", &com[i].c);
	}
	for (int i = 0; i < m; ++i) {
		scanf("%d", &com[i].a);
	}
	for (int i = 0; i < n; ++i) {
		ans += gao(m, w, com);
		for (int j = 0; j < m; ++j) {
			com[j].c -= com[j].a;
		}
	}
	ans.show();

	return 0;
}
Example #8
0
 inline static Real epsilon()
 {
   Real r;
   r.fill(NumTraits<T>::epsilon());
   return r;
 }
Example #9
0
/** Viterbi search to find the best probable output sequence.
*/
vector<size_t> LinearChain::viterbi(Real &node, Real &edge, bool standard) {
	/** Initializing.
	*/
	vector<vector<size_t> > psi;
    vector<vector<long double> > delta;
	size_t prev_max_j = defaultY_;
	long double prev_maxj = -100000.0;
    size_t i, j, k;
    size_t m_example_size = node.size() / sizeY_;

	/** Setting the omega.
	*/
	double omega;
	if (option_.inferenceType_ == ZEROOUT)
		omega = 1.0;
	else if (option_.inferenceType_ == TP1 || option_.inferenceType_ == ZERO1)
		omega = remainWeight_[0];
	else
		omega = 0.0;
		
	if (standard)
		omega = 0.0;
		
	/** Recursion.
	*/
    for (i = 0; i < m_example_size-1; i++) {
        vector<size_t> psi_i;
        vector<long double> delta_i;

		long double maxj = -10000.0;
		size_t max_j = 0;

        for (j = 0; j < sizeY_; j++) {
            long double max = -10000.0;
            size_t max_k = 0;
            if (i == 0) {
                max = 1.0; //m_M[MAT3(i,defaultY_,j)];
                max_k = defaultY_;
            } else {
                vector<size_t>::iterator it, end_it;
            	if (option_.inferenceType_ == SFB) {
					 it = param_.activeSet2_[i-1].begin();
					 end_it = param_.activeSet2_[i-1].end();
            	} else {
					 it = param_.activeSet_[j].begin();
					 end_it = param_.activeSet_[j].end();
            	}
            	if (option_.inferenceType_ == TP2 || option_.inferenceType_ == ZERO2)
                	omega = remainWeight_[j];
                if (standard) {
                	it = param_.allState_.begin();
                	end_it = param_.allState_.end();                
                	omega = 0.0;
                }                	
                
				for ( ; it != end_it; ++it) {
					double val = delta[i-1][*it] * edge[MAT2(*it,j)];
	                if (val > max) {
	                    max = val;
	                    max_k = *it;
	                }
	            }
				// See [Siddiqi and Moore, 2005, ICML]
				if (max < prev_maxj * omega) {
					max = prev_maxj * omega;
					max_k = prev_max_j;
				}
            } ///< for j
			
			/**
			*/
			max = max * node[MAT2(i, j)]; // / m_AlphaScale[i];
            delta_i.push_back(max);
            psi_i.push_back(max_k);

			if (max > maxj) {
				maxj = max;
				max_j = j;
			}
        } // for j

        delta.push_back(delta_i);
        psi.push_back(psi_i);

		prev_max_j = max_j;
		prev_maxj = maxj;
	
    } // for i

	/** Last state.
	*/
	vector<size_t> psi_i(sizeY_, 0);
	vector<long double> delta_i(sizeY_, -10000.0);
	long double max = -10000.0;
	size_t max_k = 0;
	for (size_t k=0; k < sizeY_; k++) {
		double val = delta[m_example_size-2][k]; 
		if (val > max) {
			max = val;
			max_k = k;
		}
	}
	//max /= m_AlphaScale[m_example_size-1];
	delta_i[defaultY_] = max;
	psi_i[defaultY_] = max_k;
	delta.push_back(delta_i);
	psi.push_back(psi_i);

	/** Back-tracking.
	*/
    vector<size_t> y_example;
    size_t prev_y = defaultY_;
    for (i = m_example_size-1; i >= 1; i--) {
        size_t y = psi[i][prev_y];
        y_example.push_back(y);
        prev_y = y;
    }
    reverse(y_example.begin(), y_example.end());
    long double prob = delta[m_example_size-1][defaultY_];

	return y_example;
}
Example #10
0
inline Real
operator/(Real const& a, Real const& b)
{
  return a.impl() / b.impl();
}
Example #11
0
// FIXME: Make sure that zero has the same floating point
// semantics as x.
inline Real
operator-(Real const& x)
{
  Real zero;
  return zero - x.impl();
}
Example #12
0
inline Real
operator-(Real const& a, Real const& b)
{
  return a.impl() - b.impl();
}
Example #13
0
inline Real
operator*(Real const& a, Real const& b)
{
  return a.impl() * b.impl();
}
Example #14
0
inline bool
operator>(Real const& a, Real const& b)
{
  return a.impl().compare(b.impl()) == llvm::APFloat::cmpGreaterThan;
}
Example #15
0
// Arithmetic
inline Real
operator+(Real const& a, Real const& b)
{
  return a.impl() + b.impl();
}
Example #16
0
void Scanner::getNumber(char *str, char *token_ptr)
{
    /*
     Write some code to Extract the number and convert it to a literal number.
     */
    char ch = *line_ptr;
    bool int_type = true;
    
    do
    {
        *(token_ptr++) = ch;
        ch = *(++line_ptr);
    }
    while (char_table[ch] == DIGIT);
    
    if (ch == '.')
    {
        //Then we might have a dot or dotdot
        ch = *(++line_ptr);
        if (ch == '.')
        {
            //We have a dotdot, back up ptr and our number is an int.
            int_type = true;
            --line_ptr;
        }
        else
        {
            int_type = false;
            *(token_ptr++) = '.';
            //We have a floating point number
            do
            {
                *(token_ptr++) = ch;
                ch = *(line_ptr++);
            }
            while (char_table[ch] == DIGIT);
        }
    }
    if (ch == 'e' || ch == 'E')
    {
        int_type = false;
        *(token_ptr++) = ch;
        ch = *(++line_ptr);
        if (ch == '+' || ch == '-')
        {
            *(token_ptr++) = ch;
            ch = *(++line_ptr);
        }
        do
        {
            *(token_ptr++) = ch;
            ch = *(++line_ptr);
        }
        while (char_table[ch] == DIGIT);
    }
    *token_ptr = '\0';
    new_token->setCode(NUMBER);
    if (int_type)
    {
        Integer* integer = new Integer();
        integer->setLiteral((int)atoi(str));
        new_token = integer;
    }
    else
    {
        Real* real = new Real();
        real->setLiteral((float)atof(str));
        new_token = real;
    }
}
Example #17
0
// Ordering, defined for signed floating point values by default.
inline bool
operator<(Real const& a, Real const& b)
{
  return a.impl().compare(b.impl()) == llvm::APFloat::cmpLessThan;
}
Example #18
0
 inline static Real dummy_precision()
 {
   Real r;
   r.fill(NumTraits<T>::dummy_precision());
   return r;
 }
/*** Evaluate this object ***/
Object* SpecialFunction::evaluate()
{
	if(args.size() == 0)
		throw Excep(getLineNumber(), getColumnNumber(), "Expected argument to special function!");

	std::auto_ptr<Object> arg1(args.at(0)->evaluate());

	if(id == SPF_INDEX)
	{
		if(args.size() != 2)
			throw Excep(getLineNumber(), getColumnNumber(), "Invalid number of arguments passed to special function!");

		std::auto_ptr<Object> arg2(args.at(1)->evaluate());

		if(arg2->getType() == OBJ_TEXT)
		{
			if(arg1->getType() != OBJ_TEXT)
				throw InvalidTypeException(getLineNumber(), getColumnNumber(), OBJ_TEXT, arg1->getType(), 1);

			Text* cast1 = static_cast<Text*>(arg1.get());
			Text* cast2 = static_cast<Text*>(arg2.get());

			size_t index = cast2->getValue().find(cast1->getValue());

			if(index != std::string::npos)
				return new Integer(index + 1);

			return new Integer(0);
		}

		if(arg2->getType() == OBJ_SEQUENCE)
		{
				Sequence* cast = dynamic_cast<Sequence*>(arg2.get());

				for(unsigned int i = 0; i < cast->getLength(); i++)
				{
					std::auto_ptr<Logical> eqOp(static_cast<Logical*>(Equal(arg1->clone(), cast->getObject(i)->clone()).evaluate()));
					if(eqOp->getValue() == true)
						return new Integer(i + 1);
				}

				return new Integer(0);
		}

		throw InvalidTypeException(getLineNumber(), getColumnNumber(), OBJ_TEXT | OBJ_SEQUENCE, arg2->getType(), 2);
	}

	if(args.size() > 1)
		throw Excep(getLineNumber(), getColumnNumber(), "Invalid number of arguments passed to special function!");

	if(id == SPF_ABS)
	{
		if(arg1->getType() == OBJ_INTEGER)
		{
			Integer* cast = static_cast<Integer*>(arg1.get());
			if(cast->getValue() < 0)
				return new Integer(-cast->getValue());
			return new Integer(cast->getValue());
		}

		if(arg1->getType() == OBJ_REAL)
		{
			Real* cast = static_cast<Real*>(arg1.get());
			if(cast->getValue() < 0)
				return new Real(-cast->getValue());
			return new Real(cast->getValue());
		}

		throw InvalidTypeException(getLineNumber(), getColumnNumber(), OBJ_INTEGER | OBJ_REAL, arg1->getType(), 1);
	}

	if(id == SPF_SIGN)
	{
		if(arg1->getType() == OBJ_INTEGER)
		{
			Integer* cast = static_cast<Integer*>(arg1.get());
			if(cast->getValue() < 0)
				return new Integer(-1);
			if(cast->getValue() > 0)
				return new Integer(1);
			return new Integer(0);
		}

		if(arg1->getType() == OBJ_REAL)
		{
			Real* cast = static_cast<Real*>(arg1.get());
			if(cast->getValue() < 0)
				return new Integer(-1);
			if(cast->getValue() > 0)
				return new Integer(1);
			return new Integer(0);
		}

		throw InvalidTypeException(getLineNumber(), getColumnNumber(), OBJ_INTEGER | OBJ_REAL, arg1->getType(), 1);
	}

	if(id == SPF_SQRT)
	{
		if(arg1->getType() == OBJ_INTEGER)
		{
			Integer* cast = static_cast<Integer*>(arg1.get());

			if(cast->getValue() < 0)
				throw NegativeValueException(getLineNumber(), getColumnNumber(), cast->getValue(), 1);

			double res = sqrt((double) cast->getValue());
			if((long) res == res)
				return new Integer((long) res);
			return new Real(res);
		}

		if(arg1->getType() == OBJ_REAL)
		{
			Real* cast = static_cast<Real*>(arg1.get());

			if(cast->getValue() < 0)
				throw NegativeValueException(getLineNumber(), getColumnNumber(), cast->getValue(), 1);

			double res = sqrt((double) cast->getValue());
			return new Real(res);
		}

		throw InvalidTypeException(getLineNumber(), getColumnNumber(), OBJ_INTEGER | OBJ_REAL, arg1->getType(), 1);
	}

	if(id == SPF_ENTIER)
	{
		if(arg1->getType() == OBJ_INTEGER)
		{
			Integer* cast = static_cast<Integer*>(arg1.get());
			return new Integer(cast->getValue());
		}

		if(arg1->getType() == OBJ_REAL)
		{
			Real* cast = static_cast<Real*>(arg1.get());
			return new Integer(floor(cast->getValue()));
		}

		throw InvalidTypeException(getLineNumber(), getColumnNumber(), OBJ_INTEGER | OBJ_REAL, arg1->getType(), 1);
	}

	if(id == SPF_ROUND)
	{
		if(arg1->getType() == OBJ_INTEGER)
		{
			Integer* cast = static_cast<Integer*>(arg1.get());
			return new Integer(cast->getValue());
		}

		if(arg1->getType() == OBJ_REAL)
		{
			Real* cast = static_cast<Real*>(arg1.get());
			long rounded = cast->getValue() < 0.0 ? ceil(cast->getValue() - 0.5) : floor(cast->getValue() + 0.5);
			return new Integer(rounded);
		}

		throw InvalidTypeException(getLineNumber(), getColumnNumber(), OBJ_INTEGER | OBJ_REAL, arg1->getType(), 1);
	}

	if(id == SPF_RAND)
	{
		if(arg1->getType() == OBJ_INTEGER)
		{
			Integer* cast = static_cast<Integer*>(arg1.get());

			if(cast->getValue() < 0)
				throw NegativeValueException(getLineNumber(), getColumnNumber(), cast->getValue(), 1);

			double f = (double) rand() / RAND_MAX;
			return new Real( f * cast->getValue() );
		}

		if(arg1->getType() == OBJ_REAL)
		{
			Real* cast = static_cast<Real*>(arg1.get());

			if(cast->getValue() < 0)
				throw NegativeValueException(getLineNumber(), getColumnNumber(), cast->getValue(), 1);

			double f = (double) rand() / RAND_MAX;
			return new Real( f * cast->getValue() );
		}

		throw InvalidTypeException(getLineNumber(), getColumnNumber(), OBJ_INTEGER | OBJ_REAL, arg1->getType(), 1);
	}

	if(id == SPF_INTRAND)
	{
		if(arg1->getType() == OBJ_INTEGER)
		{
			Integer* cast = static_cast<Integer*>(arg1.get());
			if(cast->getValue() < 0)
				throw NegativeValueException(getLineNumber(), getColumnNumber(), cast->getValue(), 1);
			return new Integer( rand() % cast->getValue() + 1 );
		}

		if(arg1->getType() == OBJ_REAL)
		{
			Real* cast = static_cast<Real*>(arg1.get());
			if(cast->getValue() < 0)
				throw NegativeValueException(getLineNumber(), getColumnNumber(), cast->getValue(), 1);
			return new Integer( rand() % (long) cast->getValue() + 1 );
		}

		throw InvalidTypeException(getLineNumber(), getColumnNumber(), OBJ_INTEGER | OBJ_REAL, arg1->getType(), 1);
	}

	if(id == SPF_ISEMPTY)
	{
		return new Logical(arg1->getType() == OBJ_EMPTY);
	}

	if(id == SPF_ISLOG)
	{
		return new Logical(arg1->getType() == OBJ_LOGICAL);
	}

	if(id == SPF_ISINT)
	{
		return new Logical(arg1->getType() == OBJ_INTEGER);
	}

	if(id == SPF_ISREAL)
	{
		return new Logical(arg1->getType() == OBJ_REAL);
	}

	if(id == SPF_ISTEXT)
	{
		return new Logical(arg1->getType() == OBJ_TEXT);
	}

	if(id == SPF_ISSEQ)
	{
		return new Logical(arg1->getType() == OBJ_SEQUENCE);
	}

	if(id == SPF_ISPROC)
	{
		return new Logical(arg1->getType() == OBJ_PROCEDURE);
	}

	if(id == SPF_ISFUN)
	{
		return new Logical(arg1->getType() == OBJ_FUNCTION || arg1->getType() == OBJ_SPFUNCTION);
	}

	if(id == SPF_SIN)
	{
		if(arg1->getType() == OBJ_INTEGER)
		{
			Integer* cast = static_cast<Integer*>(arg1.get());
			return new Real(sin((double) cast->getValue()));
		}

		if(arg1->getType() == OBJ_REAL)
		{
			Real* cast = static_cast<Real*>(arg1.get());
			return new Real(sin(cast->getValue()));
		}

		throw InvalidTypeException(getLineNumber(), getColumnNumber(), OBJ_INTEGER | OBJ_REAL, arg1->getType(), 1);
	}

	if(id == SPF_COS)
	{
		if(arg1->getType() == OBJ_INTEGER)
		{
			Integer* cast = static_cast<Integer*>(arg1.get());
			return new Real(cos((double) cast->getValue()));
		}

		if(arg1->getType() == OBJ_REAL)
		{
			Real* cast = static_cast<Real*>(arg1.get());
			return new Real(cos(cast->getValue()));
		}

		throw InvalidTypeException(getLineNumber(), getColumnNumber(), OBJ_INTEGER | OBJ_REAL, arg1->getType(), 1);
	}

	if(id == SPF_TG)
	{
		if(arg1->getType() == OBJ_INTEGER)
		{
			Integer* cast = static_cast<Integer*>(arg1.get());
			return new Real(tan((double) cast->getValue()));
		}

		if(arg1->getType() == OBJ_REAL)
		{
			Real* cast = static_cast<Real*>(arg1.get());
			return new Real(tan(cast->getValue()));
		}

		throw InvalidTypeException(getLineNumber(), getColumnNumber(), OBJ_INTEGER | OBJ_REAL, arg1->getType(), 1);
	}

	if(id == SPF_ARCSIN)
	{
		if(arg1->getType() == OBJ_INTEGER)
		{
			Integer* cast = static_cast<Integer*>(arg1.get());
			if(errno == EDOM)
				throw new Excep(getLineNumber(), getColumnNumber(), "Invalid value passed to special function!");
			return new Real(exp((double) cast->getValue()));
		}

		if(arg1->getType() == OBJ_REAL)
		{
			Real* cast = static_cast<Real*>(arg1.get());
			if(errno == EDOM)
				throw new Excep(getLineNumber(), getColumnNumber(), "Invalid value passed to special function!");
			return new Real(exp(cast->getValue()));
		}

		throw InvalidTypeException(getLineNumber(), getColumnNumber(), OBJ_INTEGER | OBJ_REAL, arg1->getType(), 1);
	}

	if(id == SPF_ARCTG)
	{
		if(arg1->getType() == OBJ_INTEGER)
		{
			Integer* cast = static_cast<Integer*>(arg1.get());
			if(errno == EDOM)
				throw new Excep(getLineNumber(), getColumnNumber(), "Invalid value passed to special function!");
			return new Real(exp((double) cast->getValue()));
		}

		if(arg1->getType() == OBJ_REAL)
		{
			Real* cast = static_cast<Real*>(arg1.get());
			if(errno == EDOM)
				throw new Excep(getLineNumber(), getColumnNumber(), "Invalid value passed to special function!");
			return new Real(exp(cast->getValue()));
		}

		throw InvalidTypeException(getLineNumber(), getColumnNumber(), OBJ_INTEGER | OBJ_REAL, arg1->getType(), 1);
	}

	if(id == SPF_EXP)
	{
		if(arg1->getType() == OBJ_INTEGER)
		{
			Integer* cast = static_cast<Integer*>(arg1.get());
			return new Real(exp((double) cast->getValue()));
		}

		if(arg1->getType() == OBJ_REAL)
		{
			Real* cast = static_cast<Real*>(arg1.get());
			return new Real(exp(cast->getValue()));
		}

		throw InvalidTypeException(getLineNumber(), getColumnNumber(), OBJ_INTEGER | OBJ_REAL, arg1->getType(), 1);
	}

	if(id == SPF_LN)
	{
		if(arg1->getType() == OBJ_INTEGER)
		{
			Integer* cast = static_cast<Integer*>(arg1.get());
			return new Real(log((double) cast->getValue()));
		}

		if(arg1->getType() == OBJ_REAL)
		{
			Real* cast = static_cast<Real*>(arg1.get());
			return new Real(log(cast->getValue()));
		}

		throw InvalidTypeException(getLineNumber(), getColumnNumber(), OBJ_INTEGER | OBJ_REAL, arg1->getType(), 1);
	}

	if(id == SPF_LG)
	{
		if(arg1->getType() == OBJ_INTEGER)
		{
			Integer* cast = static_cast<Integer*>(arg1.get());
			return new Real(log10((double) cast->getValue()));
		}

		if(arg1->getType() == OBJ_REAL)
		{
			Real* cast = static_cast<Real*>(arg1.get());
			return new Real(log10(cast->getValue()));
		}

		throw InvalidTypeException(getLineNumber(), getColumnNumber(), OBJ_INTEGER | OBJ_REAL, arg1->getType(), 1);
	}

	throw Excep(getLineNumber(), getColumnNumber(), "Invalid special function!");
}
Example #20
0
//  Update  input, info
//---------------------------------------------------------------------------------------------------------------
bool App::frameRenderingQueued(const FrameEvent& evt)
{
	if (!BaseApp::frameRenderingQueued(evt))
		return false;

	//  pos on minimap *
	if (ndPos)
	{	Real w = scn->sc->td.fTerWorldSize;
		Real x = (0.5 - mCamera->getPosition().z / w);
		Real y = (0.5 + mCamera->getPosition().x / w);
		ndPos->setPosition(xm1+(xm2-xm1)*x, ym1+(ym2-ym1)*y, 0);
		//--------------------------------
		float angrot = mCamera->getOrientation().getYaw().valueDegrees();
		float psx = 0.9f * pSet->size_minimap, psy = psx*asp;  // *par len

		const static float d2r = PI_d/180.f;
		static float px[4],py[4];
		for (int i=0; i<4; i++)
		{
			float ia = 135.f + float(i)*90.f;
			float p = -(angrot + ia) * d2r;
			px[i] = psx*cosf(p);  py[i] =-psy*sinf(p);
		}
		if (mpos)  {	mpos->beginUpdate(0);
			mpos->position(px[0],py[0], 0);  mpos->textureCoord(0, 1);	mpos->position(px[1],py[1], 0);  mpos->textureCoord(1, 1);
			mpos->position(px[3],py[3], 0);  mpos->textureCoord(0, 0);	mpos->position(px[2],py[2], 0);  mpos->textureCoord(1, 0);
			mpos->end();  }
	}
	
	//  status overlay
	if (fStFade > 0.f)
	{	fStFade -= evt.timeSinceLastFrame;
		//Real a = std::min(1.0f, fStFade*0.9f);
		//ColourValue cv(0.0,0.5,a, a );
		//ovStat->setColour(cv);	ovSt->setColour(cv);
		if (fStFade <= 0.f)
		{	ovSt->hide();	ovSt->setMaterialName("");  }
	}

	#define isKey(a)  mInputWrapper->isKeyDown(SDL_SCANCODE_##a)
	const Real q = (shift ? 0.05 : ctrl ? 4.0 :1.0) * 20 * evt.timeSinceLastFrame;


	// key,mb info  ==================
	if (pSet->inputBar)
	{
		// TODO: This is definitely not bullet-proof.
		const int Kmax = SDL_SCANCODE_SLEEP;  // last key
		static float tkey[Kmax+1] = {0.f,};  // key delay time
		int i;
		static bool first=true;
		if (first)
		{	first=false;
			for (i=Kmax; i > 0; --i)  tkey[i] = 0.f;
		}
		String ss = "";
		//  pressed
		for (i=Kmax; i > 0; --i)
			if  (mInputWrapper->isKeyDown(SDL_Scancode(i)))
				tkey[i] = 0.2f;  // min time to display

		//  modif
		const static int
			lc = SDL_SCANCODE_LCTRL,  rc = SDL_SCANCODE_RCTRL,
			la = SDL_SCANCODE_LALT,   ra = SDL_SCANCODE_RALT,
			ls = SDL_SCANCODE_LSHIFT, rs = SDL_SCANCODE_RSHIFT;

		if (tkey[lc] > 0.f || tkey[rc] > 0.f)	ss += "Ctrl ";
		if (tkey[la] > 0.f || tkey[ra] > 0.f)	ss += "Alt ";
		if (tkey[ls] > 0.f || tkey[rs] > 0.f)	ss += "Shift ";

		//  mouse buttons
		if (mbLeft)  ss += "LMB ";
		if (mbRight)  ss += "RMB ";
		if (mbMiddle)  ss += "MMB ";

		//  all
		for (i=Kmax; i > 0; --i)
		{
			if (tkey[i] > 0.f)
			{	tkey[i] -= evt.timeSinceLastFrame;  //dec time
				if (i!=lc && i!=la && i!=ls && i!=rc && i!=ra && i!=rs)
				{
					String s = String(SDL_GetKeyName(SDL_GetKeyFromScancode(static_cast<SDL_Scancode>(i))));
					ss += s + " ";
				}
		}	}
		
		//  mouse wheel
		static int mzd = 0;
		if (mz > 0)  mzd = 30;
		if (mz < 0)  mzd = -30;
		if (mzd > 0)  {  ss += "Wheel up";  --mzd;  }
		if (mzd < 0)  {  ss += "Wheel dn";  ++mzd;  }
		//ovInfo->setCaption(ss);
		ovDbg->setCaption(ss);
	}

	//  keys up/dn - trklist

	WP wf = MyGUI::InputManager::getInstance().getKeyFocusWidget();
	static float dirU = 0.f,dirD = 0.f;
	if (bGuiFocus && wf != (WP)gcom->trkDesc[0])
	{	if (isKey(UP)  ||isKey(KP_8))  dirD += evt.timeSinceLastFrame;  else
		if (isKey(DOWN)||isKey(KP_2))  dirU += evt.timeSinceLastFrame;  else
		{	dirU = 0.f;  dirD = 0.f;  }
		int d = ctrl ? 4 : 1;
		if (dirU > 0.0f) {  gcom->trkListNext( d);  dirU = -0.2f;  }
		if (dirD > 0.0f) {  gcom->trkListNext(-d);  dirD = -0.2f;  }
	}

	
	///  Update Info texts  . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 

	//  Road Point
	//----------------------------------------------------------------
	SplineRoad* road = scn->road;
	if (edMode == ED_Road && bEdit() && scn->road)
	{
		int ic = road->iChosen;  bool bCur = ic >= 0;
		SplinePoint& sp = bCur ? road->getPoint(ic) : road->newP;
		std::string s;
		Txt *rdTxt = gui->rdTxt, *rdVal = gui->rdVal, *rdKey = gui->rdKey,
			*rdTxtSt = gui->rdTxtSt, *rdValSt = gui->rdValSt;

		static bool first = true;
		if (first)  // once, static text
		{	first = false;
															rdKey[0]->setCaption("Home");
			rdTxt[1]->setCaption(TR("#{Road_Width}"));		rdKey[1]->setCaption("/ *");
			rdTxt[2]->setCaption(TR("#{Road_Roll}"));		rdKey[2]->setCaption("1 2");
			rdTxt[3]->setCaption(TR("#{Road_Yaw}"));		rdKey[3]->setCaption("3 4");
															rdKey[4]->setCaption(TR("#{InputRoadAngType}"));
			rdTxt[5]->setCaption(TR("#{Road_Snap}"));		rdKey[5]->setCaption("5 6");
			rdTxt[6]->setCaption(TR("#{Road_Pipe}"));		rdKey[6]->setCaption("O P");//[ ]
			rdTxt[7]->setCaption(TR("#{Road_Column}"));		rdKey[7]->setCaption("End");
															rdKey[8]->setCaption("9 0");//- =
			rdTxt[9]->setCaption(TR("#{Road_ChkR}"));		rdKey[9]->setCaption("K L");
		}

		rdTxt[0]->setCaption(TR(sp.onTer ? "#{Road_OnTerrain}" : "#{Road_Height}"));
		rdVal[0]->setCaption(sp.onTer ? "" : fToStr(sp.pos.y,1,3));

		rdVal[1]->setCaption(fToStr(sp.width,2,4));
		rdVal[2]->setCaption(fToStr(sp.aRoll,1,3));
		rdVal[3]->setCaption(fToStr(sp.aYaw,1,3));
		rdTxt[4]->setCaption(toStr(sp.aType)+" "+TR("#{Road_Angle"+csAngType[sp.aType]+"}"));
		rdVal[5]->setCaption(fToStr(angSnap,0,1));
		
		rdTxt[6]->setCaption(sp.onPipe ? TR("#{Road_OnPipe}") : TR("#{Road_Pipe}"));
		rdTxt[6]->setTextColour(sp.onPipe ? MyGUI::Colour(1.0,0.45,0.2) : MyGUI::Colour(0.86,0.86,0));
		rdVal[6]->setCaption(sp.pipe==0.f ? "" : fToStr(sp.pipe,2,4));
		
		rdTxt[7]->setVisible(!sp.onTer);	rdKey[7]->setVisible(!sp.onTer);
		rdVal[7]->setCaption(sp.onTer ? "" : toStr(sp.cols));
		
		rdTxt[8]->setCaption(toStr(sp.idMtr)+" "+road->getMtrStr(ic));

		rdTxt[9]->setTextColour(sp.loopChk ? MyGUI::Colour(0.5,1,1) : MyGUI::Colour(0.75,0.64,0.96));
		rdTxt[9]->setCaption(sp.loopChk ? TR("#{Road_Loop}") : TR("#{Road_ChkR}"));
		rdVal[9]->setCaption( sp.chkR == 0.f ? "" : fToStr(sp.chkR,1,3)+"  "+ (sp.chk1st ? "#D0D0FF(1)":"") );

		if (road->vSel.size() > 0)  s = TR("#{Road_sel}")+": "+toStr(road->vSel.size());
		else  s = fToStr(road->iChosen+1,0,2)+"/"+toStr(road->vSegs.size());
		rdVal[10]->setCaption(s);

		rdTxt[10]->setCaption(TR(bCur ? "#{Road_Cur}" : "#{Road_New}"));
		rdTxt[10]->setTextColour(bCur ? MyGUI::Colour(0.85,0.75,1) : MyGUI::Colour(0.3,1,0.1));

		rdKey[10]->setCaption(road->bMerge ? "Mrg":"");


		//  road stats  --------------------------------
		if (mWndRoadStats && mWndRoadStats->getVisible())
		{
			static bool first = true;
			if (first)  // once, static text
			{	first = false;
				rdTxtSt[0]->setCaption(TR("#{Road_Length}"));
				rdTxtSt[1]->setCaption(TR("#{Road_Width}"));
				rdTxtSt[2]->setCaption(TR("#{Road_Height}"));

				rdTxtSt[3]->setCaption(TR("#{TrackInAir}"));
				rdTxtSt[4]->setCaption(TR("#{TrackPipes}"));
				rdTxtSt[5]->setCaption(TR("#{Road_OnPipe}"));
				rdTxtSt[6]->setCaption("BnkAng");

				rdTxtSt[7]->setCaption("lod points");
				rdTxtSt[8]->setCaption("segs Merge");
				rdTxtSt[9]->setCaption("vis");
				rdTxtSt[10]->setCaption("tris");
			}			
			rdValSt[0]->setCaption(fToStr(road->st.Length,0,4));
			rdValSt[1]->setCaption(fToStr(road->st.WidthAvg,2,5));
			rdValSt[2]->setCaption(fToStr(road->st.HeightDiff,2,5));

			rdValSt[3]->setCaption(fToStr(road->st.OnTer,1,4)+"%");
			rdValSt[4]->setCaption(fToStr(road->st.Pipes,1,4)+"%");
			rdValSt[5]->setCaption(fToStr(road->st.OnPipe,1,4)+"%");
			rdValSt[6]->setCaption(fToStr(road->st.bankAvg,0,2)+" /"+fToStr(road->st.bankMax,0,2));

			int lp = !bCur ? -1 : road->vSegs[road->iChosen].lpos.size();
			rdValSt[7]->setCaption(toStr(lp));
			rdValSt[8]->setCaption(fToStr(road->segsMrg+1,0,2));
			rdValSt[9]->setCaption(fToStr(road->iVis,0,2));
			rdValSt[10]->setCaption(fToStr(road->iTris/1000.f,1,4)+"k");
		}

		//  edit  . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
		Vector3 vx = mCamera->getRight();	   vx.y = 0;  vx.normalise();  // on xz
		Vector3 vz = mCamera->getDirection();  vz.y = 0;  vz.normalise();
		Vector3 vy = Vector3::UNIT_Y;

		if (isKey(LEFT) ||isKey(KP_4))  road->Move(-vx*q);
		if (isKey(RIGHT)||isKey(KP_6))  road->Move( vx*q);
		if (isKey(DOWN) ||isKey(KP_2))  road->Move(-vz*q);
		if (isKey(UP)   ||isKey(KP_8))  road->Move( vz*q);

		if (isKey(KP_MINUS)) road->Move(-vy*q);  if (isKey(KP_MULTIPLY)) road->AddWidth( q*0.4f);
		if (isKey(KP_PLUS))  road->Move( vy*q);  if (isKey(KP_DIVIDE))   road->AddWidth(-q*0.4f);

		if (iSnap == 0 && !alt)
		{	if (isKey(3))	road->AddYaw(-q*3,0,alt);	if (isKey(1))	road->AddRoll(-q*3,0,alt);
			if (isKey(4))	road->AddYaw( q*3,0,alt);	if (isKey(2))	road->AddRoll( q*3,0,alt);
		}
		if (isKey(LEFTBRACKET) ||isKey(O))  road->AddPipe(-q*0.2);
		if (isKey(RIGHTBRACKET)||isKey(P))  road->AddPipe( q*0.2);

		Real qc = ctrl ? q*0.2f/4.f : q*0.2f;  // ctrl no effect
		if (isKey(K))  road->AddChkR(-qc, ctrl);  // chk
		if (isKey(L))  road->AddChkR( qc, ctrl);

		if (mz > 0)			road->NextPoint();
		else if (mz < 0)	road->PrevPoint();
	}

	///  Terrain  Brush
	//--------------------------------------------------------------------------------------------------------------------------------
	else if (edMode < ED_Road)
	{
		Txt *brTxt = gui->brTxt, *brVal = gui->brVal, *brKey = gui->brKey;

		static bool first = true;
		if (first)  // once, static text
		{	first = false;

			brTxt[0]->setCaption(TR("#{Brush_Size}"));		brKey[0]->setCaption("- =");
			brTxt[1]->setCaption(TR("#{Brush_Force}"));		brKey[1]->setCaption("[ ]");
			brTxt[2]->setCaption(TR("#{Brush_Power}"));		brKey[2]->setCaption("K L");//; \'
			brTxt[3]->setCaption(TR("#{Brush_Shape}"));		brKey[3]->setCaption("ctrl");//-K L

			brTxt[4]->setCaption(TR("#{Brush_Freq}"));		brKey[4]->setCaption("O P");
			brTxt[5]->setCaption(TR("#{Brush_Octaves}"));	brKey[5]->setCaption("N M");//, .
			brTxt[6]->setCaption(TR("#{Brush_Offset}"));	brKey[6]->setCaption("9 0");
		}
		brVal[0]->setCaption(fToStr(mBrSize[curBr],1,4));
		brVal[1]->setCaption(fToStr(mBrIntens[curBr],1,4));
		brVal[2]->setCaption(fToStr(mBrPow[curBr],2,4));
		brVal[3]->setCaption(TR("#{Brush_Shape"+csBrShape[mBrShape[curBr]]+"}"));

		bool brN = mBrShape[curBr] >= BRS_Noise;  int i;
		for (i=4; i<=6; ++i)
		{	brTxt[i]->setVisible(brN);  brVal[i]->setVisible(brN);  brKey[i]->setVisible(brN);	}

		if (brN)
		{	brVal[4]->setCaption(fToStr(mBrFq[curBr],2,4));
			brVal[5]->setCaption(toStr(mBrOct[curBr]));
			brVal[6]->setCaption(fToStr(mBrNOf[curBr],1,4));
		}

		bool edH = edMode != ED_Height;
		const static MyGUI::Colour clrEF[2] = {MyGUI::Colour(0.7,1.0,0.7), MyGUI::Colour(0.6,0.8,1.0)};
		const MyGUI::Colour& clr = clrEF[!edH ? 0 : 1];
		i=7;
		{	brTxt[i]->setTextColour(clr);	brVal[i]->setTextColour(clr);  brKey[i]->setTextColour(clr);  }

		if (edMode == ED_Filter)
		{
			brTxt[7]->setCaption(TR("#{Brush_Filter}"));	brKey[7]->setCaption("  1 2");
			brVal[7]->setCaption(fToStr(mBrFilt,1,3));
		}
		else if (!edH && road && road->bHitTer)
		{
			brTxt[7]->setCaption(TR("#{Brush_Height}"));	brKey[7]->setCaption("RMB");
			brVal[7]->setCaption(fToStr(terSetH,1,4));
		}else
		{	brTxt[7]->setCaption("");  brVal[7]->setCaption("");  brKey[7]->setCaption("");  }
		
		brTxt[8]->setCaption(edH ? "" : TR("#{Brush_CurrentH}"));
		brVal[8]->setCaption(edH ? "" : fToStr(road->posHit.y,1,4));
		brKey[8]->setCaption(brLockPos ? TR("#{Lock}") : "");
		
		
		//  edit  . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
		if (mz != 0 && bEdit())
			if (alt){			mBrPow[curBr]   *= 1.f - 0.4f*q*mz;  updBrush();  }
			else if (!shift){	mBrSize[curBr]  *= 1.f - 0.4f*q*mz;  updBrush();  }
			else				mBrIntens[curBr]*= 1.f - 0.4f*q*mz/0.05;

		if (isKey(MINUS)){   mBrSize[curBr]  *= 1.f - 0.04f*q;  updBrush();  }
		if (isKey(EQUALS)){  mBrSize[curBr]  *= 1.f + 0.04f*q;  updBrush();  }
		if (isKey(LEFTBRACKET))   mBrIntens[curBr]*= 1.f - 0.04f*q;
		if (isKey(RIGHTBRACKET))  mBrIntens[curBr]*= 1.f + 0.04f*q;
		if (isKey(SEMICOLON)  || (!ctrl && isKey(K)))
						{	mBrPow[curBr]   *= 1.f - 0.04f*q;  updBrush();  }
		if (isKey(APOSTROPHE) || (!ctrl && isKey(L)))
						{	mBrPow[curBr]   *= 1.f + 0.04f*q;  updBrush();  }

		if (isKey(O)){		mBrFq[curBr]    *= 1.f - 0.04f*q;  updBrush();  }
		if (isKey(P)){		mBrFq[curBr]    *= 1.f + 0.04f*q;  updBrush();  }
		if (isKey(9)){		mBrNOf[curBr]   -= 0.3f*q;		   updBrush();  }
		if (isKey(0)){		mBrNOf[curBr]   += 0.3f*q;		   updBrush();  }

		if (isKey(1)){		mBrFilt         *= 1.f - 0.04f*q;  updBrush();  }
		if (isKey(2)){		mBrFilt         *= 1.f + 0.04f*q;  updBrush();  }
		
		if (mBrIntens[curBr] < 0.1f)  mBrIntens[curBr] = 0.1;  // rest in updBrush
	}

	///  Start  box, road dir
	//----------------------------------------------------------------
	else if (edMode == ED_Start && road)
	{
		Txt *stTxt = gui->stTxt;
		Vector3 p;  if (ndCar)  p = ndCar->getPosition();
		stTxt[0]->setCaption("");
		stTxt[1]->setCaption(TR("#{Road_Width} ")+fToStr(road->vStBoxDim.z,1,4));
		stTxt[2]->setCaption(TR("#{Road_Height} ")+fToStr(road->vStBoxDim.y,1,4));
		stTxt[3]->setCaption("road dir "+ (road->iDir == 1 ? String("+1") : String("-1")) );

		//  edit
		if (isKey(LEFTBRACKET) ||isKey(O)){  road->AddBoxH(-q*0.2);  UpdStartPos();  }
		if (isKey(RIGHTBRACKET)||isKey(P)){  road->AddBoxH( q*0.2);  UpdStartPos();  }
		if (isKey(SEMICOLON)   ||isKey(K)){  road->AddBoxW(-q*0.2);  UpdStartPos();  }
		if (isKey(APOSTROPHE)  ||isKey(L)){  road->AddBoxW( q*0.2);  UpdStartPos();  }
		//if (mz > 0 && bEdit())	// snap rot by 15 deg ..
	}
	///  Fluids
	//----------------------------------------------------------------
	else if (edMode == ED_Fluids)
	{
		Txt *flTxt = gui->flTxt;
		if (scn->sc->fluids.empty())
		{
			if (flTxt[0])	flTxt[0]->setCaption("None");
			for (int i=1; i < gui->FL_TXT; ++i)
				if (flTxt[i])  flTxt[i]->setCaption("");
		}else
		{	FluidBox& fb = scn->sc->fluids[iFlCur];
			flTxt[0]->setCaption(TR("#{Road_Cur}/#{RplAll}")+":  "+toStr(iFlCur+1)+" / "+toStr(scn->sc->fluids.size()));
			flTxt[1]->setCaption(fb.name);
			flTxt[2]->setCaption("Pos:  "+fToStr(fb.pos.x,1,4)+" "+fToStr(fb.pos.y,1,4)+" "+fToStr(fb.pos.z,1,4));
			flTxt[3]->setCaption("");
			//flTxt[3]->setCaption("Rot:  "+fToStr(fb.rot.x,1,4));
			flTxt[3]->setCaption("Size:  "+fToStr(fb.size.x,1,4)+" "+fToStr(fb.size.y,1,4)+" "+fToStr(fb.size.z,1,4));
			flTxt[4]->setCaption("Tile:  "+fToStr(fb.tile.x,3,5)+" "+fToStr(fb.tile.y,3,5));

			//  edit
			if (isKey(LEFTBRACKET) ||isKey(O)){  fb.tile   *= 1.f - 0.04f*q;  bRecreateFluids = true;  }
			if (isKey(RIGHTBRACKET)||isKey(P)){  fb.tile   *= 1.f + 0.04f*q;  bRecreateFluids = true;  }
			if (isKey(SEMICOLON)   ||isKey(K)){  fb.tile.y *= 1.f - 0.04f*q;  bRecreateFluids = true;  }
			if (isKey(APOSTROPHE)  ||isKey(L)){  fb.tile.y *= 1.f + 0.04f*q;  bRecreateFluids = true;  }

			if (mz != 0 && bEdit())  // wheel prev/next
			{	int fls = scn->sc->fluids.size();
				if (fls > 0)  {  iFlCur = (iFlCur-mz+fls)%fls;  UpdFluidBox();  }
			}
		}
	}
	///  Objects
	//----------------------------------------------------------------
	else if (edMode == ED_Objects)
	{
		Txt *objTxt = gui->objTxt;
		int objs = scn->sc->objects.size();
		bool bNew = iObjCur == -1;
		const Object& o = bNew || scn->sc->objects.empty() ? objNew : scn->sc->objects[iObjCur];
		const Quaternion& q = o.nd->getOrientation();
		//Quaternion q(o.rot.w(),o.rot.x(),o.rot.y(),o.rot.z());
		objTxt[0]->setCaption((bNew ? "#80FF80New#B0D0B0     " : "#A0D0FFCur#B0B0D0     ")
							+(vObjSel.empty() ? (bNew ? "-" : toStr(iObjCur+1))+" / "+toStr(objs)
							: "#00FFFFSel  "+toStr(vObjSel.size())));
		objTxt[1]->setCaption(bNew ? vObjNames[iObjTNew] : o.name);
		objTxt[2]->setCaption(String(objEd==EO_Move  ?"#60FF60":"")+"Pos:  "+fToStr(o.pos[0],1,4)+" "+fToStr(o.pos[2],1,4)+" "+fToStr(-o.pos[1],1,4));
		objTxt[3]->setCaption(String(objEd==EO_Rotate?"#FFA0A0":"")+"Rot:  y "+fToStr(q.getYaw().valueDegrees(),0,3)+" p "+fToStr(q.getPitch().valueDegrees(),0,3)+" r "+fToStr(q.getRoll().valueDegrees(),0,3));
		objTxt[4]->setCaption(String(objEd==EO_Scale ?"#60F0FF":"")+"Scale:  "+fToStr(o.scale.x,2,4)+" "+fToStr(o.scale.y,2,4)+" "+fToStr(o.scale.z,2,4));

		objTxt[5]->setCaption(String("Sim: ") + (objSim?"ON":"off") + "      "+toStr(world->getNumCollisionObjects()));
		objTxt[5]->setTextColour(objSim ? MyGUI::Colour(1.0,0.9,1.0) : MyGUI::Colour(0.77,0.77,0.8));

		//  edit
		if (mz != 0 && bEdit())  // wheel prev/next
		{
			if (objs > 0)  {  iObjCur = (iObjCur-mz+objs)%objs;  UpdObjPick();  }
		}
	}
	mz = 0;  // mouse wheel

	
	//  rebuild road after end of selection change
	static bool bSelChngOld = false;
	if (road)
	{
		road->fLodBias = pSet->road_dist;  // after rebuild

		if (bSelChngOld && !road->bSelChng)
			road->RebuildRoad(true);

		bSelChngOld = road->bSelChng;
		road->bSelChng = false;
	}

	///  upd road lods
	static int dti = 5, ti = dti-1;  ++ti;
	if (road && ti >= dti)
	{	ti = 0;
		road->UpdLodVis(pSet->road_dist, edMode == ED_PrvCam);
	}

	return true;
}
Example #21
0
Token* Scanner::getNumber(char *str, char *token_ptr)
{
    /*
     Write some code to Extract the number and convert it to a literal number.
     */
    char ch = *line_ptr;
    bool int_type = true;
    
    do
    {
        *(token_ptr++) = ch;
        ch = *(++line_ptr);
    }
    while (char_table[ch] == DIGIT);
    
    if (ch == '.')
    {
        //Then we might have a dot or dotdot
        ch = *(++line_ptr);
        if (ch == '.')
        {
            //We have a dotdot, back up ptr and our number is an int.
            int_type = true;
            --line_ptr;
        }
        else
        {
            int_type = false;
            *(token_ptr++) = '.';
            //We have a floating point number
            do
            {
                *(token_ptr++) = ch;
                ch = *(line_ptr++);
            }
            while (char_table[ch] == DIGIT);
        }
    }
    if (ch == 'e' || ch == 'E')
    {
        int_type = false;
        *(token_ptr++) = ch;
        ch = *(++line_ptr);
        if (ch == '+' || ch == '-')
        {
            *(token_ptr++) = ch;
            ch = *(++line_ptr);
        }
        do
        {
            *(token_ptr++) = ch;
            ch = *(++line_ptr);
        }
        while (char_table[ch] == DIGIT);
    }
    *token_ptr = '\0';
	
    if (int_type)
    {
        //tok->setLiteral((int)atoi(str));	//old remove
		Integer* tok = new Integer((int)atoi(str));
		tok->setCode(NUMBER);
		return tok;
        //tok->setType(INTEGER_LIT);	//old remove
    }
    else
    {
        //tok->setLiteral((float)atof(str));	//old remove
		Real* tok = new Real((float)atof(str));
		tok->setCode(NUMBER);
		tok->setTokenString(string(str));
		return tok;
        //tok->setType(REAL_LIT);	//old remove
    }
}
Example #22
0
File: Pi.cpp Project: hyln9/nV
var Pi(uint n) {
	Real* r = new Real(n);
	pi_chudnovsky(r->mpf, static_cast<long>(LOG_2_10 * r->precision()));
	return r;
}
Example #23
0
// Equality comparison
// Returns true when the two floating point values have the same value.
inline bool
operator==(Real const& a, Real const& b)
{
  return a.impl().compare(b.impl()) == llvm::APFloat::cmpEqual;
}
Example #24
0
void
PrintVisitor::visit(const Real& node)
{
  m_os << node.get_value();
}