1 /*
2 * Copyright (C) 2004-2010 NXP Software
3 * Copyright (C) 2010 The Android Open Source Project
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18 #include "LVM_Types.h"
19 #include "LVM_Macros.h"
20 #include "ScalarArithmetic.h"
21
22 /*-------------------------------------------------------------------------*/
23 /* FUNCTION: */
24 /* LVM_Polynomial */
25 /* */
26 /* DESCRIPTION: */
27 /* This function performs polynomial expansion */
28 /* Y = (A0 + A1*X + A2*X2 + A3*X3 + �.. + AN*xN) << AN+1 */
29 /* */
30 /* LVM_INT32 LVM_Polynomial(LVM_UINT16 N, */
31 /* LVM_INT32 *pCoefficients, */
32 /* LVM_INT32 X) */
33 /* */
34 /* PARAMETERS: */
35 /* */
36 /* N is the polynomial order */
37 /* pCoefficients is the ptr to polynomial coefficients A0,A1.. in Q.31 */
38 /* X is the input variable */
39 /* */
40 /* RETURNS: */
41 /* The result of the polynomial expansion in Q1.31 format */
42 /*-------------------------------------------------------------------------*/
LVM_Polynomial(LVM_UINT16 N,LVM_FLOAT * pCoefficients,LVM_FLOAT X)43 LVM_FLOAT LVM_Polynomial(LVM_UINT16 N, LVM_FLOAT* pCoefficients, LVM_FLOAT X) {
44 LVM_INT32 i;
45 LVM_FLOAT Y, A, XTemp, Temp, sign;
46
47 Y = *pCoefficients; /* Y=A0*/
48 pCoefficients++;
49
50 if (X == -1.0f) {
51 Temp = -1;
52 sign = Temp;
53 for (i = 1; i <= N; i++) {
54 Y += ((*pCoefficients) * sign);
55 pCoefficients++;
56 sign *= Temp;
57 }
58
59 } else {
60 XTemp = X;
61 for (i = N - 1; i >= 0; i--) {
62 A = *pCoefficients;
63 pCoefficients++;
64
65 Temp = A * XTemp;
66 Y += Temp;
67
68 Temp = XTemp * X;
69 XTemp = Temp;
70 }
71 }
72 return Y;
73 }
74