evalrational.js (3722B)
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 36 // S(x) for small x: 37 var PS = [ 38 3.18016297876567817986E11, 39 -4.42979518059697779103E10, 40 2.54890880573376359104E9, 41 -6.29741486205862506537E7, 42 7.08840045257738576863E5, 43 -2.99181919401019853726E3, 44 0.0 45 ]; 46 47 var QS = [ 48 6.07366389490084639049E11, 49 2.24411795645340920940E10, 50 4.19320245898111231129E8, 51 5.17343888770096400730E6, 52 4.55847810806532581675E4, 53 2.81376268889994315696E2, 54 1.00000000000000000000E0 55 ]; 56 57 // Auxiliary function f(x): 58 var PF = [ 59 3.76329711269987889006E-20, 60 1.34283276233062758925E-16, 61 1.72010743268161828879E-13, 62 1.02304514164907233465E-10, 63 3.05568983790257605827E-8, 64 4.63613749287867322088E-6, 65 3.45017939782574027900E-4, 66 1.15220955073585758835E-2, 67 1.43407919780758885261E-1, 68 4.21543555043677546506E-1, 69 0.0 70 ]; 71 72 var QF = [ 73 1.25443237090011264384E-20, 74 4.52001434074129701496E-17, 75 5.88754533621578410010E-14, 76 3.60140029589371370404E-11, 77 1.12699224763999035261E-8, 78 1.84627567348930545870E-6, 79 1.55934409164153020873E-4, 80 6.44051526508858611005E-3, 81 1.16888925859191382142E-1, 82 7.51586398353378947175E-1, 83 1.00000000000000000000E0 84 ]; 85 86 // Auxiliary function g(x): 87 var PG = [ 88 1.86958710162783235106E-22, 89 8.36354435630677421531E-19, 90 1.37555460633261799868E-15, 91 1.08268041139020870318E-12, 92 4.45344415861750144738E-10, 93 9.82852443688422223854E-8, 94 1.15138826111884280931E-5, 95 6.84079380915393090172E-4, 96 1.87648584092575249293E-2, 97 1.97102833525523411709E-1, 98 5.04442073643383265887E-1, 99 0.0 100 ]; 101 102 var QG = [ 103 1.86958710162783236342E-22, 104 8.39158816283118707363E-19, 105 1.38796531259578871258E-15, 106 1.10273215066240270757E-12, 107 4.60680728146520428211E-10, 108 1.04314589657571990585E-7, 109 1.27545075667729118702E-5, 110 8.14679107184306179049E-4, 111 2.53603741420338795122E-2, 112 3.37748989120019970451E-1, 113 1.47495759925128324529E0, 114 1.00000000000000000000E0 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_psqs.js' ); 142 str = header + compile( PS, QS ); 143 writeFileSync( fpath, str, opts ); 144 145 fpath = resolve( __dirname, '..', 'lib', 'rational_pfqf.js' ); 146 str = header + compile( PF, QF ); 147 writeFileSync( fpath, str, opts ); 148 149 fpath = resolve( __dirname, '..', 'lib', 'rational_pgqg.js' ); 150 str = header + compile( PG, QG ); 151 writeFileSync( fpath, str, opts ); 152 } 153 154 main();