本文整理汇总了C++中Real类的典型用法代码示例。如果您正苦于以下问题:C++ Real类的具体用法?C++ Real怎么用?C++ Real使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Real类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Greater
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();
}
示例2: return
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());
}
示例3: lMSB
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);
}
示例4: if
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;
}
示例5: computeExactFlags_temp
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;
}
示例6: if
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;
}
}
示例7: main
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;
}
示例8: epsilon
inline static Real epsilon()
{
Real r;
r.fill(NumTraits<T>::epsilon());
return r;
}
示例9: if
/** 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) {
//.........这里部分代码省略.........
示例10:
inline Real
operator/(Real const& a, Real const& b)
{
return a.impl() / b.impl();
}
示例11: while
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;
}
}
示例12: dummy_precision
inline static Real dummy_precision()
{
Real r;
r.fill(NumTraits<T>::dummy_precision());
return r;
}
示例13: Excep
/*** 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)
//.........这里部分代码省略.........
示例14: float
// 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);
}
//.........这里部分代码省略.........
示例15: while
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
}
}