CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (https://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   Calculating polynomials in OF source (https://www.cfd-online.com/Forums/openfoam-programming-development/136445-calculating-polynomials-source.html)

r08n May 28, 2014 13:44

Calculating polynomials in OF source
 
I noticed that the class member Foam:: polynomial::value() seems to calculate a polynomial by actually calculating the powers:

Code:

  167    forAll(coeffs_, i)
  168    {
  169        y += coeffs_[i].first()*pow(x, coeffs_[i].second());
  170    }

while Foam:: polynomialFunction::value () uses the Horner scheme:

Code:

  168    // avoid costly pow() in calculation
  169    scalar powX = x;
  170    for (label i=1; i<coeffs.size(); ++i)
  171    {
  172        val += coeffs[i]*powX;
  173        powX *= x;
  174    }

I'm just curious -- is there any reason to use the 'pow ()' function (rather than multiplication) in the former?


All times are GMT -4. The time now is 15:02.