Changeset 759a6a for src


Ignore:
Timestamp:
May 2, 2012, 1:36:49 PM (14 years ago)
Author:
Julian Iseringhausen <isering@…>
Children:
6fee21
Parents:
728149
Message:

Unrolled loops for evaluating polynomials with Horner scheme.

git-svn-id: https://svn.version.fz-juelich.de/scafacos/trunk@1780 5161e1c8-67bf-11de-9fd5-51895aff932f

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/base/polynomial.hpp

    r728149 r759a6a  
    4242  vmg_float operator()(const vmg_float& val) const
    4343  {
    44     vmg_float result = coeff.back();
    45     for (int i=coeff.size()-2; i>=0; --i)
    46       result = coeff[i] + result * val;
    47     return result;
     44    switch (coeff.size())
     45      {
     46      case 1:
     47        return coeff[0];
     48      case 2:
     49        return coeff[1] * val + coeff[0];
     50      case 3:
     51        return (coeff[2] * val + coeff[1]) * val + coeff[0];
     52      case 4:
     53        return ((coeff[3] * val + coeff[2]) * val + coeff[1]) * val + coeff[0];
     54      case 5:
     55        return (((coeff[4] * val + coeff[3]) * val + coeff[2]) * val + coeff[1]) * val + coeff[0];
     56      case 6:
     57        return ((((coeff[5] * val + coeff[4]) * val + coeff[3]) * val + coeff[2]) * val + coeff[1]) * val + coeff[0];
     58      case 7:
     59        return (((((coeff[6]*val+coeff[5])*val+coeff[4])*val+coeff[3])*val+coeff[2])*val+coeff[1])*val+coeff[0];
     60      case 8:
     61        return ((((((coeff[7]*val+coeff[6])*val+coeff[5])*val+coeff[4])*val+coeff[3])*val+coeff[2])*val+coeff[1])*val+coeff[0];
     62      default:
     63        vmg_float result = coeff.back();
     64        for (int i=coeff.size()-2; i>=0; --i)
     65          result = coeff[i] + result * val;
     66        return result;
     67      }
     68
    4869  }
    4970
Note: See TracChangeset for help on using the changeset viewer.