mirror of
https://github.com/DrBeef/Raze.git
synced 2024-11-16 09:21:12 +00:00
123 lines
3 KiB
C
123 lines
3 KiB
C
|
/* polevl.c
|
|||
|
* p1evl.c
|
|||
|
*
|
|||
|
* Evaluate polynomial
|
|||
|
*
|
|||
|
*
|
|||
|
*
|
|||
|
* SYNOPSIS:
|
|||
|
*
|
|||
|
* int N;
|
|||
|
* double x, y, coef[N+1], polevl[];
|
|||
|
*
|
|||
|
* y = polevl( x, coef, N );
|
|||
|
*
|
|||
|
*
|
|||
|
*
|
|||
|
* DESCRIPTION:
|
|||
|
*
|
|||
|
* Evaluates polynomial of degree N:
|
|||
|
*
|
|||
|
* 2 N
|
|||
|
* y = C + C x + C x +...+ C x
|
|||
|
* 0 1 2 N
|
|||
|
*
|
|||
|
* Coefficients are stored in reverse order:
|
|||
|
*
|
|||
|
* coef[0] = C , ..., coef[N] = C .
|
|||
|
* N 0
|
|||
|
*
|
|||
|
* The function p1evl() assumes that coef[N] = 1.0 and is
|
|||
|
* omitted from the array. Its calling arguments are
|
|||
|
* otherwise the same as polevl().
|
|||
|
*
|
|||
|
*
|
|||
|
* SPEED:
|
|||
|
*
|
|||
|
* In the interest of speed, there are no checks for out
|
|||
|
* of bounds arithmetic. This routine is used by most of
|
|||
|
* the functions in the library. Depending on available
|
|||
|
* equipment features, the user may wish to rewrite the
|
|||
|
* program in microcode or assembly language.
|
|||
|
*
|
|||
|
*/
|
|||
|
|
|||
|
|
|||
|
/*
|
|||
|
Cephes Math Library Release 2.1: December, 1988
|
|||
|
Copyright 1984, 1987, 1988 by Stephen L. Moshier
|
|||
|
|
|||
|
Redistribution and use in source and binary forms, with or without
|
|||
|
modification, are permitted provided that the following conditions are met:
|
|||
|
|
|||
|
1. Redistributions of source code must retain the above copyright notice,
|
|||
|
this list of conditions and the following disclaimer.
|
|||
|
2. Redistributions in binary form must reproduce the above copyright
|
|||
|
notice, this list of conditions and the following disclaimer in the
|
|||
|
documentation and/or other materials provided with the distribution.
|
|||
|
3. Neither the name of the <ORGANIZATION> nor the names of its
|
|||
|
contributors may be used to endorse or promote products derived from
|
|||
|
this software without specific prior written permission.
|
|||
|
|
|||
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|||
|
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|||
|
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|||
|
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
|||
|
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|||
|
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|||
|
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|||
|
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|||
|
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|||
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|||
|
POSSIBILITY OF SUCH DAMAGE.
|
|||
|
|
|||
|
Direct inquiries to 30 Frost Street, Cambridge, MA 02140
|
|||
|
*/
|
|||
|
|
|||
|
|
|||
|
double polevl( x, coef, N )
|
|||
|
double x;
|
|||
|
double coef[];
|
|||
|
int N;
|
|||
|
{
|
|||
|
double ans;
|
|||
|
int i;
|
|||
|
double *p;
|
|||
|
|
|||
|
p = coef;
|
|||
|
ans = *p++;
|
|||
|
i = N;
|
|||
|
|
|||
|
do
|
|||
|
ans = ans * x + *p++;
|
|||
|
while( --i );
|
|||
|
|
|||
|
return( ans );
|
|||
|
}
|
|||
|
|
|||
|
/* p1evl() */
|
|||
|
/* N
|
|||
|
* Evaluate polynomial when coefficient of x is 1.0.
|
|||
|
* Otherwise same as polevl.
|
|||
|
*/
|
|||
|
|
|||
|
double p1evl( x, coef, N )
|
|||
|
double x;
|
|||
|
double coef[];
|
|||
|
int N;
|
|||
|
{
|
|||
|
double ans;
|
|||
|
double *p;
|
|||
|
int i;
|
|||
|
|
|||
|
p = coef;
|
|||
|
ans = x + *p++;
|
|||
|
i = N-1;
|
|||
|
|
|||
|
do
|
|||
|
ans = ans * x + *p++;
|
|||
|
while( --i );
|
|||
|
|
|||
|
return( ans );
|
|||
|
}
|