'use strict';

/*
* The code is adapted from the Fortran routine `dcseval` from the FNLIB library of the [SLATEC Common Mathematical Library]{@link http://www.netlib.org/slatec/fnlib/}.
*
* The original code was developed by W. Fullerton of Los Alamos Scientific Laboratory, a governmental institution, and is therefore public domain software.
*/

// MAIN //

/**
* Evaluate the n-term Chebyshev series `cs` at `x`.
*
* #### References
*
* * R. Broucke, Ten subroutines for the manipulation of Chebyshev series, Algorithm 446, Communications of the A.C.M. 16, (1973) pp. 254-256.
* * L. Fox and I. B. Parker, Chebyshev Polynomials in Numerical Analysis, Oxford University Press, 1968, page 56.
*
* @private
* @param {number} x - value at which the series is to be evaluated
* @param {NumericArray} cs - array of n terms of a Chebyshev series.
* @returns {number} series value
*/
function dcseval( x, cs ) {
	var twox;
	var b2;
	var b1;
	var b0;
	var i;
	var n;

	n = cs.length;
	if ( x < -1.1 || x > 1.1 ) {
		return NaN;
	}

	b1 = 0.0;
	b0 = 0.0;
	twox = 2.0 * x;
	for ( i = 1; i <= n; i++ ) {
		b2 = b1;
		b1 = b0;
		b0 = (twox * b1) - b2 + cs[ n - i ];
	}
	return ( b0 - b2 ) * 0.5;
} // end FUNCTION dcseval()


// EXPORTS //

module.exports = dcseval;

@@ -438,11 +438,8 @@
 %0A* *
- R.
  Bro
@@ -447,14 +447,39 @@
 cke,
+ Roger. 1973. %22Algorithm:
  Ten 
-s
+S
 ubro
@@ -493,17 +493,17 @@
 for the 
-m
+M
 anipulat
@@ -523,31 +523,18 @@
 hev 
-s
+S
 eries
-, Algorithm 446, 
+.%22 *
 Comm
@@ -556,67 +556,164 @@
 he A
-.C.M.
+CM*
  16
-,
  (
-1973) pp. 254-256.%0A* * L. Fox and I. B. Parker, 
+4). New York, NY, USA: ACM: 254%E2%80%9356. doi:%5B10.1145/362003.362037%5D(https://doi.org/10.1145/362003.362037).%0A* * Fox, Leslie, and Ian Bax Parker. 1968. *
 Cheb
@@ -718,17 +718,17 @@
 ebyshev 
-P
+p
 olynomia
@@ -733,17 +733,17 @@
 ials in 
-N
+n
 umerical
@@ -747,56 +747,147 @@
 cal 
-A
+a
 nalysis
-, Oxford University Press, 1968, page 56
+*. Oxford Mathematical Handbooks. London, United Kingdom: Oxford University Press. %3Chttps://books.google.com/books?id=F8NzsEtJCD0C%3E
 .%0A*%0A

Update references