add legacy getloadavg api
[musl.git] / src / math / __polevll.c
bloba27286514d739bedf87888cf94c5930fa1f3ba28
1 /* origin: OpenBSD /usr/src/lib/libm/src/polevll.c */
2 /*
3 * Copyright (c) 2008 Stephen L. Moshier <steve@moshier.net>
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 * Evaluate polynomial
21 * SYNOPSIS:
23 * int N;
24 * long double x, y, coef[N+1], polevl[];
26 * y = polevll( x, coef, N );
29 * DESCRIPTION:
31 * Evaluates polynomial of degree N:
33 * 2 N
34 * y = C + C x + C x +...+ C x
35 * 0 1 2 N
37 * Coefficients are stored in reverse order:
39 * coef[0] = C , ..., coef[N] = C .
40 * N 0
42 * The function p1evll() assumes that coef[N] = 1.0 and is
43 * omitted from the array. Its calling arguments are
44 * otherwise the same as polevll().
47 * SPEED:
49 * In the interest of speed, there are no checks for out
50 * of bounds arithmetic. This routine is used by most of
51 * the functions in the library. Depending on available
52 * equipment features, the user may wish to rewrite the
53 * program in microcode or assembly language.
57 #include "libm.h"
60 * Polynomial evaluator:
61 * P[0] x^n + P[1] x^(n-1) + ... + P[n]
63 long double __polevll(long double x, const long double *P, int n)
65 long double y;
67 y = *P++;
68 do {
69 y = y * x + *P++;
70 } while (--n);
72 return y;
76 * Polynomial evaluator:
77 * x^n + P[0] x^(n-1) + P[1] x^(n-2) + ... + P[n]
79 long double __p1evll(long double x, const long double *P, int n)
81 long double y;
83 n -= 1;
84 y = x + *P++;
85 do {
86 y = y * x + *P++;
87 } while (--n);
89 return y;