evalpoly.js (2695B)
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 C = [ 36 0.25721014990011306473e-1, 37 0.82475966166999631057e-1, 38 -0.25328157302663562668e-2, 39 0.60992926669463371e-3, 40 -0.33543297638406e-3, 41 0.250505279903e-3 42 ]; 43 var D = [ 44 0.0833333333333333333333333333333, 45 -0.00277777777777777777777777777778, 46 0.000793650793650793650793650793651, 47 -0.000595238095238095238095238095238 48 ]; 49 var AK1 = [ 50 0.0, 51 1.0, 52 1.0, 53 1.5, 54 2.66666666666666666666666666667, 55 5.20833333333333333333333333333, 56 10.8 57 ]; 58 var AK2 = [ 59 1.0, 60 1.0, 61 0.333333333333333333333333333333, 62 0.0277777777777777777777777777778, 63 -0.00370370370370370370370370370370, 64 0.000231481481481481481481481481481, 65 0.0000587889476778365667254556143445 66 ]; 67 68 // Header to add to output files: 69 var header = licenseHeader( 'Apache-2.0', 'js', { 70 'year': ( new Date() ).getFullYear(), 71 'copyright': 'The Stdlib Authors' 72 }); 73 header += '\n/* This is a generated file. Do not edit directly. */\n'; 74 75 76 // MAIN // 77 78 /** 79 * Main execution sequence. 80 * 81 * @private 82 */ 83 function main() { 84 var fpath; 85 var opts; 86 var str; 87 88 opts = { 89 'encoding': 'utf8' 90 }; 91 92 fpath = resolve( __dirname, '..', 'lib', 'polyval_c.js' ); 93 str = header + compile( C ); 94 writeFileSync( fpath, str, opts ); 95 96 fpath = resolve( __dirname, '..', 'lib', 'polyval_d.js' ); 97 str = header + compile( D ); 98 writeFileSync( fpath, str, opts ); 99 100 fpath = resolve( __dirname, '..', 'lib', 'polyval_ak1.js' ); 101 str = header + compile( AK1 ); 102 writeFileSync( fpath, str, opts ); 103 104 fpath = resolve( __dirname, '..', 'lib', 'polyval_ak2.js' ); 105 str = header + compile( AK2 ); 106 writeFileSync( fpath, str, opts ); 107 } 108 109 main();