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 /*-------------------------------------------------------------------------*/ 43 LVM_FLOAT LVM_Polynomial(LVM_UINT16 N, 44 LVM_FLOAT *pCoefficients, 45 LVM_FLOAT X) 46 { 47 LVM_INT32 i; 48 LVM_FLOAT Y,A,XTemp,Temp,sign; 49 50 Y = *pCoefficients; /* Y=A0*/ 51 pCoefficients++; 52 53 if(X == -1.0f) 54 { 55 Temp = -1; 56 sign = Temp; 57 for(i = 1; i <= N; i++) 58 { 59 Y += ((*pCoefficients) * sign); 60 pCoefficients++; 61 sign *= Temp; 62 } 63 64 } 65 else 66 { 67 XTemp = X; 68 for(i = N-1; i >= 0; i--) 69 { 70 A = *pCoefficients; 71 pCoefficients++; 72 73 Temp = A * XTemp; 74 Y += Temp; 75 76 Temp = XTemp * X; 77 XTemp = Temp; 78 } 79 } 80 return Y; 81 } 82