time-to-botec

Benchmark sampling in different programming languages
Log | Files | Refs | README

dceval.js (2615B)


      1 /**
      2 * @license Apache-2.0
      3 *
      4 * Copyright (c) 2018 The Stdlib Authors.
      5 *
      6 * Licensed under the Apache License, Version 2.0 (the "License");
      7 * you may not use this file except in compliance with the License.
      8 * You may obtain a copy of the License at
      9 *
     10 *    http://www.apache.org/licenses/LICENSE-2.0
     11 *
     12 * Unless required by applicable law or agreed to in writing, software
     13 * distributed under the License is distributed on an "AS IS" BASIS,
     14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     15 * See the License for the specific language governing permissions and
     16 * limitations under the License.
     17 *
     18 *
     19 * ## Notice
     20 *
     21 * The code is adapted from the Fortran routine from the FNLIB library of the [SLATEC Common Mathematical Library]{@link http://www.netlib.no/netlib/slatec/fnlib/}.
     22 *
     23 * The original code was developed by W. Fullerton of Los Alamos Scientific Laboratory, a governmental institution, and is therefore public domain.
     24 */
     25 
     26 'use strict';
     27 
     28 // VARIABLES //
     29 
     30 var ALGMCS = [
     31 	+0.1276642195630062933333333333333e-30,
     32 	-0.3401102254316748799999999999999e-29,
     33 	+0.1025680058010470912000000000000e-27,
     34 	-0.3547598158101070547199999999999e-26,
     35 	+0.1429227355942498147573333333333e-24,
     36 	-0.6831888753985766870111999999999e-23,
     37 	+0.3962837061046434803679306666666e-21,
     38 	-0.2868042435334643284144622399999e-19,
     39 	+0.2683181998482698748957538846666e-17,
     40 	-0.3399615005417721944303330599666e-15,
     41 	+0.6221098041892605227126015543416e-13,
     42 	-0.1809129475572494194263306266719e-10,
     43 	+0.9810825646924729426157171547487e-8,
     44 	-0.1384948176067563840732986059135e-4,
     45 	+0.1666389480451863247205729650822e+0
     46 ];
     47 var LEN = ALGMCS.length;
     48 
     49 
     50 // MAIN //
     51 
     52 /**
     53 * Evaluate the n-term Chebyshev series at `x`.
     54 *
     55 * ## References
     56 *
     57 * -   Broucke, Roger. 1973. "Algorithm: Ten Subroutines for the Manipulation of Chebyshev Series." _Communications of the ACM_ 16 (4). New York, NY, USA: ACM: 254–56. doi:[10.1145/362003.362037](https://doi.org/10.1145/362003.362037).
     58 * -   Fox, Leslie, and Ian Bax Parker. 1968. _Chebyshev polynomials in numerical analysis_. Oxford Mathematical Handbooks. London, United Kingdom: Oxford University Press. <https://books.google.com/books?id=F8NzsEtJCD0C>.
     59 *
     60 * @private
     61 * @param {number} x - value at which the series is to be evaluated
     62 * @returns {number} series value
     63 */
     64 function dcseval( x ) {
     65 	var twox;
     66 	var b2;
     67 	var b1;
     68 	var b0;
     69 	var i;
     70 
     71 	if ( x < -1.1 || x > 1.1 ) {
     72 		return NaN;
     73 	}
     74 	b1 = 0.0;
     75 	b0 = 0.0;
     76 	twox = 2.0 * x;
     77 	for ( i = 0; i < LEN; i++ ) {
     78 		b2 = b1;
     79 		b1 = b0;
     80 		b0 = (twox*b1) - b2 + ALGMCS[ i ];
     81 	}
     82 	return ( b0-b2 ) * 0.5;
     83 }
     84 
     85 
     86 // EXPORTS //
     87 
     88 module.exports = dcseval;