vDSP_vpoly
Evaluates a single-precision polynomial using specified coefficients, variables, and strides.
Declaration
extern void vDSP_vpoly(const float *__A, vDSP_Stride __IA, const float *__B, vDSP_Stride __IB, float *__C, vDSP_Stride __IC, vDSP_Length __N, vDSP_Length __P);Parameters
- __A:
A vector that contains
__P + 1coefficients. - __IA:
The distance between the elements in the input vector
A. - __B:
A vector that contains the variables.
- __IB:
The distance between the elements in the input vector
B. - __C:
A vector that receives the result of the calculation.
- __IC:
The distance between the elements in the output vector
C. - __N:
The number of variables that the function processes to produce the same number of output elements.
- __P:
The degree of the polynomial.
Discussion
For example, the following code evaluates the polynomial with the coefficients [10.0, 20.0, 30.0] and the variables [7.0, 5.0]:
let stride = 1
let coefficients: [Float] = [10, 20, 30]
let variables: [Float] = [7, 5]
let result = [Float](
unsafeUninitializedCapacity: variables.count) {
buffer, initializedCount in
vDSP_vpoly(coefficients, stride,
variables, stride,
buffer.baseAddress!, stride,
vDSP_Length(variables.count),
vDSP_Length(coefficients.count - 1))
initializedCount = 2
}
// Prints "[660.0, 380.0]".
// result[0] = (10 * 7²) + (20 * 7¹) + (30 * 7⁰) = 660
// result[1] = (10 * 5²) + (20 * 5¹) + (30 * 5⁰) = 380
print(result)