time-to-botec

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

evalpoly.js (2520B)


      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 /*
     20 * This script compiles modules for evaluating polynomial functions. If any polynomial coefficients change, this script should be rerun to update the compiled files.
     21 */
     22 'use strict';
     23 
     24 // MODULES //
     25 
     26 var resolve = require( 'path' ).resolve;
     27 var writeFileSync = require( '@stdlib/fs/write-file' ).sync;
     28 var licenseHeader = require( '@stdlib/_tools/licenses/header' );
     29 var compile = require( './../../../../base/tools/evalpoly-compile' );
     30 
     31 
     32 // VARIABLES //
     33 
     34 // Polynomial coefficients ordered in ascending degree...
     35 var T_ODD = [
     36 	1.33333333333201242699e-01, // T1 => 3FC11111, 1110FE7A
     37 	2.18694882948595424599e-02, // T3 => 3FABA1BA, 1BB341FE
     38 	3.59207910759131235356e-03, // T5 => 3F6D6D22, C9560328
     39 	5.88041240820264096874e-04, // T7 => 3F4344D8, F2F26501
     40 	7.81794442939557092300e-05, // T9 => 3F147E88, A03792A6
     41 	-1.85586374855275456654e-05 // T11 => BEF375CB, DB605373
     42 ];
     43 var T_EVEN = [
     44 	5.39682539762260521377e-02, // T2 => 3FABA1BA, 1BB341FE
     45 	8.86323982359930005737e-03, // T4 => 3F8226E3, E96E8493
     46 	1.45620945432529025516e-03, // T6 => 3F57DBC8, FEE08315
     47 	2.46463134818469906812e-04, // T8 => 3F3026F7, 1A8D1068
     48 	7.14072491382608190305e-05, // T10 => 3F12B80F, 32F0A7E9
     49 	2.59073051863633712884e-05  // T12 => 3EFB2A70, 74BF7AD4
     50 ];
     51 
     52 // Header to add to output files:
     53 var header = licenseHeader( 'Apache-2.0', 'js', {
     54 	'year': ( new Date() ).getFullYear(),
     55 	'copyright': 'The Stdlib Authors'
     56 });
     57 header += '\n/* This is a generated file. Do not edit directly. */\n';
     58 
     59 
     60 // MAIN //
     61 
     62 /**
     63 * Main execution sequence.
     64 *
     65 * @private
     66 */
     67 function main() {
     68 	var fpath;
     69 	var opts;
     70 	var str;
     71 
     72 	opts = {
     73 		'encoding': 'utf8'
     74 	};
     75 
     76 	fpath = resolve( __dirname, '..', 'lib', 'polyval_t_odd.js' );
     77 	str = header + compile( T_ODD );
     78 	writeFileSync( fpath, str, opts );
     79 
     80 	fpath = resolve( __dirname, '..', 'lib', 'polyval_t_even.js' );
     81 	str = header + compile( T_EVEN );
     82 	writeFileSync( fpath, str, opts );
     83 }
     84 
     85 main();