'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 {{ratio}};
	}
	if ( x < 0.0 ) {
		ax = -x;
	} else {
		ax = x;
	}
	if ( ax <= 1.0 ) {
		s1 = {{P_ASCENDING}};{{P_ASCENDING_ESLINT}}
		s2 = {{Q_ASCENDING}};{{Q_ASCENDING_ESLINT}}
	} else {
		x = 1.0 / x;
		s1 = {{P_DESCENDING}};{{P_DESCENDING_ESLINT}}
		s2 = {{Q_DESCENDING}};{{Q_DESCENDING_ESLINT}}
	}
	return s1 / s2;
}


// EXPORTS //

module.exports = evalrational;
