当前位置: 首页>>代码示例>>C++>>正文


C++ Rational::sgn方法代码示例

本文整理汇总了C++中Rational::sgn方法的典型用法代码示例。如果您正苦于以下问题:C++ Rational::sgn方法的具体用法?C++ Rational::sgn怎么用?C++ Rational::sgn使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Rational的用法示例。


在下文中一共展示了Rational::sgn方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: absCmp

/** Equivalent to calling (this->abs()).cmp(b.abs()) */
int Rational::absCmp(const Rational& q) const{
  const Rational& r = *this;
  int rsgn = r.sgn();
  int qsgn = q.sgn();
  if(rsgn == 0){
    return (qsgn == 0) ? 0 : -1;
  }else if(qsgn == 0){
    Assert(rsgn != 0);
    return 1;
  }else if((rsgn > 0) && (qsgn > 0)){
    return r.cmp(q);
  }else if((rsgn < 0) && (qsgn < 0)){
    // if r < q < 0, q.cmp(r) = +1, (r.abs()).cmp(q.abs()) = +1
    // if q < r < 0, q.cmp(r) = -1, (r.abs()).cmp(q.abs()) = -1
    // if q = r < 0, q.cmp(r) =  0, (r.abs()).cmp(q.abs()) =  0
    return q.cmp(r);
  }else if((rsgn < 0) && (qsgn > 0)){
    Rational rpos = -r;
    return rpos.cmp(q);
  }else {
    Assert(rsgn > 0 && (qsgn < 0));
    Rational qpos = -q;
    return r.cmp(qpos);
  }
}
开发者ID:g2graman,项目名称:CVC4,代码行数:26,代码来源:rational_gmp_imp.cpp

示例2: isolate

bool QuantArith::isolate( Node v, std::map< Node, Node >& msum, Node & veq, Kind k ) {
  if( msum.find(v)!=msum.end() ){
    std::vector< Node > children;
    Rational r = msum[v].isNull() ? Rational(1) : msum[v].getConst<Rational>();
    if ( r.sgn()!=0 ){
      for( std::map< Node, Node >::iterator it = msum.begin(); it != msum.end(); ++it ){
        if( it->first.isNull() || it->first!=v ){
          Node m;
          if( !it->first.isNull() ){
            if ( !it->second.isNull() ){
              m = NodeManager::currentNM()->mkNode( MULT, it->second, it->first );
            }else{
              m = it->first;
            }
          }else{
            m = it->second;
          }
          children.push_back(m);
        }
      }
      veq = children.size()>1 ? NodeManager::currentNM()->mkNode( PLUS, children ) :
                                (children.size()==1 ? children[0] : NodeManager::currentNM()->mkConst( Rational(0) ));
      if( !r.isNegativeOne() ){
        if( r.isOne() ){
          veq = negate(veq);
        }else{
          //TODO
          return false;
        }
      }
      veq = Rewriter::rewrite( veq );
      veq = NodeManager::currentNM()->mkNode( k, r.sgn()==1 ? v : veq, r.sgn()==1 ? veq : v );
      return true;
    }
    return false;
  }else{
    return false;
  }
}
开发者ID:xcodevn,项目名称:CVC4,代码行数:39,代码来源:quant_util.cpp

示例3: seperatingDelta

void DeltaRational::seperatingDelta(Rational& res, const DeltaRational& a, const DeltaRational& b){
  Assert(res.sgn() > 0);

  int cmp = a.cmp(b);
  if(cmp != 0){
    bool aLeqB = cmp < 0;

    const DeltaRational& min = aLeqB ? a : b;
    const DeltaRational& max = aLeqB ? b : a;

    const Rational& pinf = min.getInfinitesimalPart();
    const Rational& cinf = max.getInfinitesimalPart();

    const Rational& pmaj = min.getNoninfinitesimalPart();
    const Rational& cmaj = max.getNoninfinitesimalPart();

    if(pmaj == cmaj){
      Assert(pinf < cinf);
      // any value of delta preserves the order
    }else if(pinf == cinf){
      Assert(pmaj < cmaj);
      // any value of delta preserves the order
    }else{
      Assert(pinf != cinf && pmaj != cmaj);
      Rational denDiffAbs = (cinf - pinf).abs();

      Rational numDiff = (cmaj - pmaj);
      Assert(numDiff.sgn() >= 0);
      Assert(denDiffAbs.sgn() > 0);
      Rational ratio = numDiff / denDiffAbs;
      Assert(ratio.sgn() > 0);

      if(ratio < res){
        res = ratio;
      }
    }
  }
}
开发者ID:CVC4,项目名称:CVC4,代码行数:38,代码来源:delta_rational.cpp

示例4: JudgeLessThan

Boolean* Rational::JudgeLessThan(Number* obj){
    Rational* toCheck = SCAST_RATIONAL(this->sub(obj->toExact()));
    return new Boolean(toCheck->sgn() < 0 );
}
开发者ID:yuchenlin,项目名称:SchemeCalc,代码行数:4,代码来源:rational.cpp

示例5: getMin

Number* Rational::getMin(Number* obj){
    Rational* toCheck = SCAST_RATIONAL(this->sub(obj->toExact()));
    return new Rational(toCheck->sgn()<0 ? (*this) :(*(SCAST_RATIONAL(obj))));
}
开发者ID:yuchenlin,项目名称:SchemeCalc,代码行数:4,代码来源:rational.cpp

示例6: parse

bool IDLAssertion::parse(TNode node, int c, bool negated) {

  // Only unit coefficients allowed
  if (c != 1 && c != -1) {
    return false;
  }

  // Assume we're ok
  bool ok = true;

  // The kind of the node
  switch(node.getKind()) {

  case kind::NOT:
    // We parse the negation
    ok = parse(node[0], c, true);
    // Setup the kind
    if (ok) {
      d_op = negateOp(d_op);
    }
    break;

  case kind::EQUAL:
  case kind::LT:
  case kind::LEQ:
  case kind::GT:
  case kind::GEQ: {
    // All relation operators are parsed on both sides
    d_op = node.getKind();
    ok = parse(node[0], c, negated);
    if (ok) {
      ok = parse(node[1],-c, negated);
    }
    break;
  }

  case kind::CONST_RATIONAL: {
    // Constants
    Rational m = node.getConst<Rational>();
    if (m.isIntegral()) {
      d_c +=  m.getNumerator() * (-c);
    } else {
      ok = false;
    }
    break;
  }
  case kind::MULT: {
    // Only unit multiplication of variables
    if (node.getNumChildren() == 2 && node[0].isConst()) {
      Rational a = node[0].getConst<Rational>();
      if (a == 1 || a == -1) {
        ok = parse(node[1], c * a.sgn(), negated);
      } else {
        ok = false;
      }
    } else {
      ok = false;
    }
    break;
  }

  case kind::PLUS: {
    for(unsigned i = 0; i < node.getNumChildren(); ++i) {
      ok = parse(node[i], c, negated);
      if(!ok) {
        break;
      }
    }
    break;
  }

  case kind::MINUS: {
    ok = parse(node[0], c, negated);
    if (ok) {
      ok = parse(node[1], -c, negated);
    }
    break;
  }

  case kind::UMINUS: {
    ok = parse(node[0], -c, negated);
    break;
  }

  default: {
    if (c > 0) {
      if (d_x.isNull()) {
        d_x = node;
      } else {
        ok = false;
      }
    } else {
      if (d_y.isNull()) {
        d_y = node;
      } else {
        ok = false;
      }
    }
    break;
  }
//.........这里部分代码省略.........
开发者ID:g2graman,项目名称:CVC4,代码行数:101,代码来源:idl_assertion.cpp


注:本文中的Rational::sgn方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。