evalpoly.js (1992B)
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 /* 35 * Polynomial coefficients ordered in ascending degree. 36 * 37 * |1/cbrt(x) - p(x)| < 2**-23.5 (~[-7.93e-8, 7.929e-8]) 38 */ 39 var P = [ 40 1.87595182427177009643, // 0x3ffe03e6, 0x0f61e692 41 -1.88497979543377169875, // 0xbffe28e0, 0x92f02420 42 1.621429720105354466140, // 0x3ff9f160, 0x4a49d6c2 43 -0.758397934778766047437, // 0xbfe844cb, 0xbee751d9 44 0.145996192886612446982 // 0x3fc2b000, 0xd4e4edd7 45 ]; 46 47 // Header to add to output files: 48 var header = licenseHeader( 'Apache-2.0', 'js', { 49 'year': ( new Date() ).getFullYear(), 50 'copyright': 'The Stdlib Authors' 51 }); 52 header += '\n/* This is a generated file. Do not edit directly. */\n'; 53 54 55 // MAIN // 56 57 /** 58 * Main execution sequence. 59 * 60 * @private 61 */ 62 function main() { 63 var fpath; 64 var opts; 65 var str; 66 67 opts = { 68 'encoding': 'utf8' 69 }; 70 71 fpath = resolve( __dirname, '..', 'lib', 'polyval_p.js' ); 72 str = header + compile( P ); 73 writeFileSync( fpath, str, opts ); 74 } 75 76 main();