evalrational.js (3675B)
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/evalrational-compile' ); 30 31 32 // VARIABLES // 33 34 // Polynomial coefficients ordered in ascending degree... 35 var P1 = [ 36 -1.4258509801366645672e+11, 37 6.6781041261492395835e+09, 38 -1.1548696764841276794e+08, 39 9.8062904098958257677e+05, 40 -4.4615792982775076130e+03, 41 1.0650724020080236441e+01, 42 -1.0767857011487300348e-02 43 ]; 44 45 var Q1 = [ 46 4.1868604460820175290e+12, 47 4.2091902282580133541e+10, 48 2.0228375140097033958e+08, 49 5.9117614494174794095e+05, 50 1.0742272239517380498e+03, 51 1.0, 52 0.0 53 ]; 54 55 var P2 = [ 56 -1.7527881995806511112e+16, 57 1.6608531731299018674e+15, 58 -3.6658018905416665164e+13, 59 3.5580665670910619166e+11, 60 -1.8113931269860667829e+09, 61 5.0793266148011179143e+06, 62 -7.5023342220781607561e+03, 63 4.6179191852758252278e+00 64 ]; 65 66 var Q2 = [ 67 1.7253905888447681194e+18, 68 1.7128800897135812012e+16, 69 8.4899346165481429307e+13, 70 2.7622777286244082666e+11, 71 6.4872502899596389593e+08, 72 1.1267125065029138050e+06, 73 1.3886978985861357615e+03, 74 1.0 75 ]; 76 77 var PC = [ 78 -4.4357578167941278571e+06, 79 -9.9422465050776411957e+06, 80 -6.6033732483649391093e+06, 81 -1.5235293511811373833e+06, 82 -1.0982405543459346727e+05, 83 -1.6116166443246101165e+03, 84 0.0 85 ]; 86 87 var QC = [ 88 -4.4357578167941278568e+06, 89 -9.9341243899345856590e+06, 90 -6.5853394797230870728e+06, 91 -1.5118095066341608816e+06, 92 -1.0726385991103820119e+05, 93 -1.4550094401904961825e+03, 94 1.0 95 ]; 96 97 var PS = [ 98 3.3220913409857223519e+04, 99 8.5145160675335701966e+04, 100 6.6178836581270835179e+04, 101 1.8494262873223866797e+04, 102 1.7063754290207680021e+03, 103 3.5265133846636032186e+01, 104 0.0 105 ]; 106 107 var QS = [ 108 7.0871281941028743574e+05, 109 1.8194580422439972989e+06, 110 1.4194606696037208929e+06, 111 4.0029443582266975117e+05, 112 3.7890229745772202641e+04, 113 8.6383677696049909675e+02, 114 1.0 115 ]; 116 117 // Header to add to output files: 118 var header = licenseHeader( 'Apache-2.0', 'js', { 119 'year': ( new Date() ).getFullYear(), 120 'copyright': 'The Stdlib Authors' 121 }); 122 header += '\n/* This is a generated file. Do not edit directly. */\n'; 123 124 125 // MAIN // 126 127 /** 128 * Main execution sequence. 129 * 130 * @private 131 */ 132 function main() { 133 var fpath; 134 var opts; 135 var str; 136 137 opts = { 138 'encoding': 'utf8' 139 }; 140 141 fpath = resolve( __dirname, '..', 'lib', 'rational_p1q1.js' ); 142 str = header + compile( P1, Q1 ); 143 writeFileSync( fpath, str, opts ); 144 145 fpath = resolve( __dirname, '..', 'lib', 'rational_p2q2.js' ); 146 str = header + compile( P2, Q2 ); 147 writeFileSync( fpath, str, opts ); 148 149 fpath = resolve( __dirname, '..', 'lib', 'rational_pcqc.js' ); 150 str = header + compile( PC, QC ); 151 writeFileSync( fpath, str, opts ); 152 153 fpath = resolve( __dirname, '..', 'lib', 'rational_psqs.js' ); 154 str = header + compile( PS, QS ); 155 writeFileSync( fpath, str, opts ); 156 } 157 158 main();