evalpoly.js (2154B)
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 C13 = [ 36 4.16666666666666019037e-02, // 0x3FA55555, 0x5555554C 37 -1.38888888888741095749e-03, // 0xBF56C16C, 0x16C15177 38 2.48015872894767294178e-05 // 0x3EFA01A0, 0x19CB1590 39 ]; 40 var C46 = [ 41 -2.75573143513906633035e-07, // 0xBE927E4F, 0x809C52AD 42 2.08757232129817482790e-09, // 0x3E21EE9E, 0xBDB4B1C4 43 -1.13596475577881948265e-11 // 0xBDA8FAE9, 0xBE8838D4 44 ]; 45 46 // Header to add to output files: 47 var header = licenseHeader( 'Apache-2.0', 'js', { 48 'year': ( new Date() ).getFullYear(), 49 'copyright': 'The Stdlib Authors' 50 }); 51 header += '\n/* This is a generated file. Do not edit directly. */\n'; 52 53 54 // MAIN // 55 56 /** 57 * Main execution sequence. 58 * 59 * @private 60 */ 61 function main() { 62 var fpath; 63 var opts; 64 var str; 65 66 opts = { 67 'encoding': 'utf8' 68 }; 69 70 fpath = resolve( __dirname, '..', 'lib', 'polyval_c13.js' ); 71 str = header + compile( C13 ); 72 writeFileSync( fpath, str, opts ); 73 74 fpath = resolve( __dirname, '..', 'lib', 'polyval_c46.js' ); 75 str = header + compile( C46 ); 76 writeFileSync( fpath, str, opts ); 77 } 78 79 main();