Path: blob/master/waterbox/libc/functions/math/__polevll.c
2 views
/* origin: OpenBSD /usr/src/lib/libm/src/polevll.c */1/*2* Copyright (c) 2008 Stephen L. Moshier <[email protected]>3*4* Permission to use, copy, modify, and distribute this software for any5* purpose with or without fee is hereby granted, provided that the above6* copyright notice and this permission notice appear in all copies.7*8* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES9* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF10* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR11* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES12* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN13* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF14* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.15*/16/*17* Evaluate polynomial18*19*20* SYNOPSIS:21*22* int N;23* long double x, y, coef[N+1], polevl[];24*25* y = polevll( x, coef, N );26*27*28* DESCRIPTION:29*30* Evaluates polynomial of degree N:31*32* 2 N33* y = C + C x + C x +...+ C x34* 0 1 2 N35*36* Coefficients are stored in reverse order:37*38* coef[0] = C , ..., coef[N] = C .39* N 040*41* The function p1evll() assumes that coef[N] = 1.0 and is42* omitted from the array. Its calling arguments are43* otherwise the same as polevll().44*45*46* SPEED:47*48* In the interest of speed, there are no checks for out49* of bounds arithmetic. This routine is used by most of50* the functions in the library. Depending on available51* equipment features, the user may wish to rewrite the52* program in microcode or assembly language.53*54*/5556#include "libm.h"5758#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 102459#else60/*61* Polynomial evaluator:62* P[0] x^n + P[1] x^(n-1) + ... + P[n]63*/64long double __polevll(long double x, const long double *P, int n)65{66long double y;6768y = *P++;69do {70y = y * x + *P++;71} while (--n);7273return y;74}7576/*77* Polynomial evaluator:78* x^n + P[0] x^(n-1) + P[1] x^(n-2) + ... + P[n]79*/80long double __p1evll(long double x, const long double *P, int n)81{82long double y;8384n -= 1;85y = x + *P++;86do {87y = y * x + *P++;88} while (--n);8990return y;91}92#endif939495