UNPKG

@woosh/meep-engine

Version:

Pure JavaScript game engine. Fully featured and production ready.

32 lines (26 loc) 911 B
/** * Evaluate a univariate polynomial with real coefficients at a complex point, * via Horner's method. * * p(z) = coeffs[0] + coeffs[1] · z + ... + coeffs[degree] · z^degree * * The result is written into `result` as `[Re(p(z)), Im(p(z))]`. * * @param {number[]|Float32Array|Float64Array} result 2-element output buffer * @param {number[]|Float32Array|Float64Array} coeffs ascending-power, length ≥ degree + 1 * @param {number} degree polynomial degree, ≥ 0 * @param {number} zr real part of z * @param {number} zi imaginary part of z */ export function complex_horner_eval(result, coeffs, degree, zr, zi) { let pr = coeffs[degree]; let pi = 0; for (let i = degree - 1; i >= 0; i--) { const new_pr = pr * zr - pi * zi + coeffs[i]; const new_pi = pr * zi + pi * zr; pr = new_pr; pi = new_pi; } result[0] = pr; result[1] = pi; }