"Fossies" - the Fresh Open Source Software Archive

Member "gretl-2020e/cephes/polevl.c" (2 Oct 2015, 1589 Bytes) of package /linux/misc/gretl-2020e.tar.xz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "polevl.c" see the Fossies "Dox" file reference documentation.

    1 /*                          polevl.c
    2  *                          p1evl.c
    3  *
    4  *  Evaluate polynomial
    5  *
    6  *
    7  *
    8  * SYNOPSIS:
    9  *
   10  * int N;
   11  * double x, y, coef[N+1], polevl[];
   12  *
   13  * y = polevl( x, coef, N );
   14  *
   15  *
   16  *
   17  * DESCRIPTION:
   18  *
   19  * Evaluates polynomial of degree N:
   20  *
   21  *                     2          N
   22  * y  =  C  + C x + C x  +...+ C x
   23  *        0    1     2          N
   24  *
   25  * Coefficients are stored in reverse order:
   26  *
   27  * coef[0] = C  , ..., coef[N] = C  .
   28  *            N                   0
   29  *
   30  *  The function p1evl() assumes that coef[N] = 1.0 and is
   31  * omitted from the array.  Its calling arguments are
   32  * otherwise the same as polevl().
   33  *
   34  *
   35  * SPEED:
   36  *
   37  * In the interest of speed, there are no checks for out
   38  * of bounds arithmetic.  This routine is used by most of
   39  * the functions in the library.  Depending on available
   40  * equipment features, the user may wish to rewrite the
   41  * program in microcode or assembly language.
   42  *
   43  */
   44 
   45 
   46 /*
   47   Cephes Math Library Release 2.1:  December, 1988
   48   Copyright 1984, 1987, 1988 by Stephen L. Moshier
   49   Direct inquiries to 30 Frost Street, Cambridge, MA 02140
   50 */
   51 
   52 double polevl (double x, double *coef, int N)
   53 {
   54     double ans;
   55     int i;
   56     double *p;
   57 
   58     p = coef;
   59     ans = *p++;
   60     i = N;
   61 
   62     do {
   63     ans = ans * x + *p++;
   64     } while (--i);
   65 
   66     return ans;
   67 }
   68 
   69 /* 
   70  * Evaluate polynomial when coefficient of x  is 1.0.
   71  * Otherwise same as polevl.
   72  */
   73 
   74 double p1evl (double x, double *coef, int N)
   75 {
   76     double ans;
   77     double *p;
   78     int i;
   79 
   80     p = coef;
   81     ans = x + *p++;
   82     i = N-1;
   83 
   84     do {
   85     ans = ans * x + *p++;
   86     } while (--i);
   87 
   88     return ans;
   89 }