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


C++ Expression::ScalarFactor方法代码示例

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


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

示例1: simplify

Expression Expression::simplify() const {
  Expression postfactor = *this;
  Expression prefactor = postfactor.ScalarFactor();
  if (prefactor != Expression(1)) {
    return prefactor * postfactor.simplify();
  }
  if (name == "*" && arg2->name == "*") {
    if (arg2->arg1->kindIs("constant"))
      return (*arg2->arg1 * *arg1 * *arg2->arg2).simplify();
    if (arg2->arg2->kindIs("constant"))
      return (*arg2->arg2 * *arg1 * *arg2->arg1).simplify();
    return (*arg1 * *arg2->arg1 * *arg2->arg2).simplify();
  }
  if (kindIs("unary") && name == "-") {
    Expression minusthis = arg1->simplify();
    if (minusthis.kindIs("*/") && minusthis.arg1->kindIs("constant")) {
      minusthis.arg1 = new Expression(-minusthis.arg1->value);
      return minusthis;
    }
    if (minusthis.kindIs("*/") && minusthis.arg1->kindIs("*/") && minusthis.arg1->arg1->kindIs("constant")) {
      minusthis.arg1->arg1 = new Expression(-minusthis.arg1->arg1->value);
      return minusthis;
    }
    return -minusthis;
  }
  Expression out;
  out.name = name;
  out.type = type;
  out.kind = kind;
  out.alias = alias;
  if (arg1) out.arg1 = new Expression(arg1->simplify());
  if (arg2) out.arg2 = new Expression(arg2->simplify());
  if (arg3) out.arg3 = new Expression(arg3->simplify());
  return *this;
}
开发者ID:Chris-Haglund,项目名称:deft,代码行数:35,代码来源:Expression.cpp

示例2: ScalarFactor

Expression Expression::ScalarFactor() {
  if (kindIs("constant")) {
    Expression out(value);
    value = 1;
    return out;
  }
  if (typeIs("double")) {
    // If we have type "double" then we *are* a scalar!
    Expression out(*this);
    *this = Expression(1);
    return out;
  }
  if (kindIs("*/") && name == "*") {
    Expression sf1 = arg1->ScalarFactor();
    Expression sf2 = arg2->ScalarFactor();
    *this = *arg1 * *arg2; // to handle cases where arg1 or arg2 becomes 1.
    return sf1*sf2;
  }
  if (kindIs("*/") && name == "/") {
    Expression sf1 = arg1->ScalarFactor();
    Expression sf2 = arg2->ScalarFactor();
    *this = *arg1 / *arg2; // to handle cases where arg1 or arg2 becomes 1.
    return sf1/sf2;
  }
  if (kindIs("linear function")) {
    return arg1->ScalarFactor();
  }
  if (kindIs("unary") && name == "-") {
    Expression postfactor = *arg1;
    Expression prefactor = postfactor.ScalarFactor();
    *this = postfactor;
    return -prefactor;
  }
  return Expression(1);
}
开发者ID:Chris-Haglund,项目名称:deft,代码行数:35,代码来源:Expression.cpp


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