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


C++ Polynomial::Degree方法代码示例

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


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

示例1: FFTStretch

static size_t FFTStretch(Polynomial<T> & p)
{
  size_t n = 1;
  size_t d = p.Degree();

  while (1)
  {
    if (d <= n)
      break;
      
    n <<= 1;

    if (n == 0)
      Polynomial<T>::Xoverflow();
  }

  n <<= 1;

  p = p.Stretch(n);

  return n;
}
开发者ID:heavilessrose,项目名称:my-sync,代码行数:22,代码来源:polynomial.cpp

示例2: Divide

bool Polynomial::Divide(const Polynomial & divisor_polynomial,
                        Polynomial & quotient_polynomial,
                        Polynomial & remainder_polynomial) const
{
    //------------------------------------------------------------------
    //  If the divisor is zero then fail.
    //------------------------------------------------------------------

    int divisor_degree = divisor_polynomial.Degree();

    bool non_zero_divisor_flag = ((divisor_polynomial.Degree() != 0)
                                     || (divisor_polynomial[0] != 0.0));

    if (non_zero_divisor_flag)
    {
        //--------------------------------------------------------------
        //  If this dividend polynomial's degree is not greater than
        //  or equal to the divisor polynomial's degree then do the division.
        //--------------------------------------------------------------

        remainder_polynomial = *this;
        int dividend_degree = Degree();
        quotient_polynomial = 0.0;
        int quotient_maximum_degree = dividend_degree - divisor_degree + 1;
        quotient_polynomial.SetLength(quotient_maximum_degree);
        quotient_polynomial.m_degree = -1;
        double * quotient_coefficient_ptr =
            quotient_polynomial.m_coefficient_vector_ptr;
        double * dividend_coefficient_ptr =
            remainder_polynomial.m_coefficient_vector_ptr;
        double leading_divisor_coefficient = divisor_polynomial[divisor_degree];

        //--------------------------------------------------------------
        //  Loop and subtract each scaled divisor polynomial
        //  to perform the division.
        //--------------------------------------------------------------

        int dividend_index = dividend_degree;

        for (dividend_index = dividend_degree;
             dividend_index >= divisor_degree;
             --dividend_index)
        {
            //----------------------------------------------------------
            //  Subtract the scaled divisor from the dividend.
            //----------------------------------------------------------

            double scale_value = remainder_polynomial[dividend_index] / leading_divisor_coefficient;

            //----------------------------------------------------------
            //  Increase the order of the quotient polynomial.
            //----------------------------------------------------------

            quotient_polynomial.m_degree += 1;
            int j = 0;

            for (j = quotient_polynomial.m_degree; j >= 1; --j)
            {
                quotient_coefficient_ptr[j] = quotient_coefficient_ptr[j - 1];
            }

            quotient_coefficient_ptr[0] = scale_value;

            //----------------------------------------------------------
            //  Subtract the scaled divisor from the dividend.
            //----------------------------------------------------------

            int dividend_degree_index = dividend_index;

            for (j = divisor_degree; j >=0; --j)
            {
                dividend_coefficient_ptr[dividend_degree_index] -= divisor_polynomial[j] * scale_value;
                --dividend_degree_index;
            }
        }

        //--------------------------------------------------------------
        //  Adjust the order of the current dividend polynomial.
        //  This is the remainder polynomial.
        //--------------------------------------------------------------

        remainder_polynomial.AdjustPolynomialDegree();
        quotient_polynomial.AdjustPolynomialDegree();
    }
    else
    {
        quotient_polynomial = DBL_MAX;
        remainder_polynomial = 0.0;
    }

    return non_zero_divisor_flag;
}
开发者ID:MafuraG,项目名称:CalcTF,代码行数:92,代码来源:Polynomial.cpp


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