File Coverage

lib/PDL/Math/polevl.c
Criterion Covered Total %
statement 14 14 100.0
branch 4 4 100.0
condition n/a
subroutine n/a
pod n/a
total 18 18 100.0


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