'use strict'; // MAIN // /** * Evaluates a rational function, i.e., the ratio of two polynomials described by the coefficients stored in \\(P\\) and \\(Q\\). * * ## Notes * * - Coefficients should be sorted in ascending degree. * - The implementation uses [Horner's rule][horners-method] for efficient computation. * * [horners-method]: https://en.wikipedia.org/wiki/Horner%27s_method * * * @private * @param {number} x - value at which to evaluate the rational function * @returns {number} evaluated rational function */ function evalrational( x ) { var ax; var s1; var s2; if ( x === 0.0 ) { return 0.25; } if ( x < 0.0 ) { ax = -x; } else { ax = x; } if ( ax <= 1.0 ) { s1 = 1.0 + (x * (2.5 + (x * (3.14 + (x * -1.0))))); s2 = 4.0 + (x * (-3.5 + (x * (2.2 + (x * 1.25))))); } else { x = 1.0 / x; s1 = -1.0 + (x * (3.14 + (x * (2.5 + (x * 1.0))))); s2 = 1.25 + (x * (2.2 + (x * (-3.5 + (x * 4.0))))); } return s1 / s2; } // EXPORTS // module.exports = evalrational;