evalpoly.js (2632B)
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 L = [ 36 5.99999999999994648725e-01, // 0x3FE33333, 0x33333303 37 4.28571428578550184252e-01, // 0x3FDB6DB6, 0xDB6FABFF 38 3.33333329818377432918e-01, // 0x3FD55555, 0x518F264D 39 2.72728123808534006489e-01, // 0x3FD17460, 0xA91D4101 40 2.30660745775561754067e-01, // 0x3FCD864A, 0x93C9DB65 41 2.06975017800338417784e-01 // 0x3FCA7E28, 0x4A454EEF 42 ]; 43 44 // `x - x^2/2 + x^3/3 - x^4/4`... 45 var W = [ 46 0.5, 47 -0.3333333333333333333333, 48 0.25 49 ]; 50 51 var P = [ 52 1.66666666666666019037e-01, // 0x3FC55555, 0x5555553E 53 -2.77777777770155933842e-03, // 0xBF66C16C, 0x16BEBD93 54 6.61375632143793436117e-05, // 0x3F11566A, 0xAF25DE2C 55 -1.65339022054652515390e-06, // 0xBEBBBD41, 0xC5D26BF1 56 4.13813679705723846039e-08 // 0x3E663769, 0x72BEA4D0 57 ]; 58 59 // Header to add to output files: 60 var header = licenseHeader( 'Apache-2.0', 'js', { 61 'year': ( new Date() ).getFullYear(), 62 'copyright': 'The Stdlib Authors' 63 }); 64 header += '\n/* This is a generated file. Do not edit directly. */\n'; 65 66 67 // MAIN // 68 69 /** 70 * Main execution sequence. 71 * 72 * @private 73 */ 74 function main() { 75 var fpath; 76 var opts; 77 var str; 78 79 opts = { 80 'encoding': 'utf8' 81 }; 82 83 fpath = resolve( __dirname, '..', 'lib', 'polyval_l.js' ); 84 str = header + compile( L ); 85 writeFileSync( fpath, str, opts ); 86 87 fpath = resolve( __dirname, '..', 'lib', 'polyval_w.js' ); 88 str = header + compile( W ); 89 writeFileSync( fpath, str, opts ); 90 91 fpath = resolve( __dirname, '..', 'lib', 'polyval_p.js' ); 92 str = header + compile( P ); 93 writeFileSync( fpath, str, opts ); 94 } 95 96 main();