evalpoly.js (2244B)
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 A = [ 36 1.00000000000000000126e0, 37 3.29771340985225106936e0, 38 4.25697156008121755724e0, 39 2.71149851196553469920e0, 40 8.79691311754530315341e-1, 41 1.33847639578309018650e-1, 42 7.31589045238094711071e-3, 43 4.65128586073990045278e-5 44 ]; 45 var B = [ 46 9.99999999999999998740e-1, 47 3.54771340985225096217e0, 48 5.03278880143316990390e0, 49 3.63800533345137075418e0, 50 1.41172597751831069617e0, 51 2.82974860602568089943e-1, 52 2.54043763932544379113e-2, 53 6.90990488912553276999e-4 54 ]; 55 56 // Header to add to output files: 57 var header = licenseHeader( 'Apache-2.0', 'js', { 58 'year': ( new Date() ).getFullYear(), 59 'copyright': 'The Stdlib Authors' 60 }); 61 header += '\n/* This is a generated file. Do not edit directly. */\n'; 62 63 64 // MAIN // 65 66 /** 67 * Main execution sequence. 68 * 69 * @private 70 */ 71 function main() { 72 var fpath; 73 var opts; 74 var str; 75 76 opts = { 77 'encoding': 'utf8' 78 }; 79 80 fpath = resolve( __dirname, '..', 'lib', 'polyval_a.js' ); 81 str = header + compile( A ); 82 writeFileSync( fpath, str, opts ); 83 84 fpath = resolve( __dirname, '..', 'lib', 'polyval_b.js' ); 85 str = header + compile( B ); 86 writeFileSync( fpath, str, opts ); 87 } 88 89 main();