Create FUNDING.yml
[wdl/wdl-ol.git] / WDL / cmath / horner.h
blobd943457f2f2618dd07120ee74faa30ab25040223
1 /*
2 horner.h
3 Copyright (C) 2011 and later Lubomir I. Ivanov (neolit123 [at] gmail)
5 This software is provided 'as-is', without any express or implied
6 warranty. In no event will the authors be held liable for any damages
7 arising from the use of this software.
9 Permission is granted to anyone to use this software for any purpose,
10 including commercial applications, and to alter it and redistribute it
11 freely, subject to the following restrictions:
13 1. The origin of this software must not be misrepresented; you must not
14 claim that you wrote the original software. If you use this software
15 in a product, an acknowledgment in the product documentation would be
16 appreciated but is not required.
17 2. Altered source versions must be plainly marked as such, and must not be
18 misrepresented as being the original software.
19 3. This notice may not be removed or altered from any source distribution.
23 algorithm to evaluate integer order polynomials using horner's scheme.
26 #ifndef _HORNER_H_
27 #define _HORNER_H_
29 #include "custom_math.h"
30 #include "complex_number.h"
32 /* settings */
33 #ifndef _HORNER_INLINE
34 #define _HORNER_INLINE _CMATH_INLINE
35 #else
36 #define _HORNER_INLINE
37 #endif
39 /* real */
40 _HORNER_INLINE
41 cmath_t horner_eval
42 (const cmath_t *coeff, const cmath_t x, cmath_uint16_t order)
44 register cmath_t y = coeff[0];
45 register cmath_uint16_t n = 1;
46 order += 1;
47 while(n < order)
49 y = y*x + coeff[n];
50 n++;
52 return y;
55 /* complex */
56 _HORNER_INLINE
57 cnum_s horner_eval_c
58 (const cnum_s *coeff, const cnum_s x, cmath_uint16_t order)
60 register cmath_uint16_t n = 1;
61 cnum_s y = coeff[0];
62 order += 1;
63 while(n < order)
65 y = cnum_add(cnum_mul(y, x), coeff[n]);
66 n++;
68 return y;
71 #endif /* _HORNER_H_ */