evalpoly.js (3359B)
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 P3 = [ 36 -2.0, 37 -4.0 38 ]; 39 var P4 = [ 40 16.0, 41 8.0 42 ]; 43 var P5 = [ 44 -16.0, 45 -88.0, 46 -16.0 47 ]; 48 var P6 = [ 49 272.0, 50 416.0, 51 32.0 52 ]; 53 var P7 = [ 54 -272.0, 55 -2880.0, 56 -1824.0, 57 -64.0 58 ]; 59 var P8 = [ 60 7936.0, 61 24576.0, 62 7680.0, 63 128.0 64 ]; 65 var P9 = [ 66 -7936.0, 67 -137216.0, 68 -185856.0, 69 -31616.0, 70 -256.0 71 ]; 72 var P10 = [ 73 353792.0, 74 1841152.0, 75 1304832.0, 76 128512.0, 77 512.0 78 ]; 79 var P11 = [ 80 -353792.0, 81 -9061376.0, 82 -21253376.0, 83 -8728576.0, 84 -518656.0, 85 -1024.0 86 ]; 87 var P12 = [ 88 22368256.0, 89 175627264.0, 90 222398464.0, 91 56520704.0, 92 2084864.0, 93 2048.0 94 ]; 95 96 // Header to add to output files: 97 var header = licenseHeader( 'Apache-2.0', 'js', { 98 'year': ( new Date() ).getFullYear(), 99 'copyright': 'The Stdlib Authors' 100 }); 101 header += '\n/* This is a generated file. Do not edit directly. */\n'; 102 103 104 // MAIN // 105 106 /** 107 * Main execution sequence. 108 * 109 * @private 110 */ 111 function main() { 112 var fpath; 113 var opts; 114 var str; 115 116 opts = { 117 'encoding': 'utf8' 118 }; 119 120 fpath = resolve( __dirname, '..', 'lib', 'polyval_p3.js' ); 121 str = header + compile( P3 ); 122 writeFileSync( fpath, str, opts ); 123 124 fpath = resolve( __dirname, '..', 'lib', 'polyval_p4.js' ); 125 str = header + compile( P4 ); 126 writeFileSync( fpath, str, opts ); 127 128 fpath = resolve( __dirname, '..', 'lib', 'polyval_p5.js' ); 129 str = header + compile( P5 ); 130 writeFileSync( fpath, str, opts ); 131 132 fpath = resolve( __dirname, '..', 'lib', 'polyval_p6.js' ); 133 str = header + compile( P6 ); 134 writeFileSync( fpath, str, opts ); 135 136 fpath = resolve( __dirname, '..', 'lib', 'polyval_p7.js' ); 137 str = header + compile( P7 ); 138 writeFileSync( fpath, str, opts ); 139 140 fpath = resolve( __dirname, '..', 'lib', 'polyval_p8.js' ); 141 str = header + compile( P8 ); 142 writeFileSync( fpath, str, opts ); 143 144 fpath = resolve( __dirname, '..', 'lib', 'polyval_p9.js' ); 145 str = header + compile( P9 ); 146 writeFileSync( fpath, str, opts ); 147 148 fpath = resolve( __dirname, '..', 'lib', 'polyval_p10.js' ); 149 str = header + compile( P10 ); 150 writeFileSync( fpath, str, opts ); 151 152 fpath = resolve( __dirname, '..', 'lib', 'polyval_p11.js' ); 153 str = header + compile( P11 ); 154 writeFileSync( fpath, str, opts ); 155 156 fpath = resolve( __dirname, '..', 'lib', 'polyval_p12.js' ); 157 str = header + compile( P12 ); 158 writeFileSync( fpath, str, opts ); 159 } 160 161 main();