evalrational.js (4757B)
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 0.24339294433593750202, 37 -0.49092470516353571651, 38 0.0557616214776046784287, 39 -0.00320912498879085894856, 40 0.000451534528645796438704, 41 -0.933241270357061460782e-5 42 ]; 43 var Q1 = [ 44 1.0, 45 -0.279960334310344432495, 46 0.0419676223309986037706, 47 -0.00413421406552171059003, 48 0.00024978985622317935355, 49 -0.101855788418564031874e-4 50 ]; 51 var P2 = [ 52 0.577215664901532860516, 53 0.243210646940107164097, 54 0.0417364673988216497593, 55 0.00390252087072843288378, 56 0.000249606367151877175456, 57 0.110108440976732897969e-4 58 ]; 59 var Q2 = [ 60 1.0, 61 0.295201277126631761737, 62 0.043460910607305495864, 63 0.00434930582085826330659, 64 0.000255784226140488490982, 65 0.10991819782396112081e-4 66 ]; 67 var P3 = [ 68 -0.0537258300023595030676, 69 0.0445163473292365591906, 70 0.0128677673534519952905, 71 0.00097541770457391752726, 72 0.769875101573654070925e-4, 73 0.328032510000383084155e-5, 74 0.0 75 ]; 76 var Q3 = [ 77 1.0, 78 0.33383194553034051422, 79 0.0487798431291407621462, 80 0.00479039708573558490716, 81 0.000270776703956336357707, 82 0.106951867532057341359e-4, 83 0.236276623974978646399e-7 84 ]; 85 var P4 = [ 86 -2.49710190602259410021, 87 -2.60013301809475665334, 88 -0.939260435377109939261, 89 -0.138448617995741530935, 90 -0.00701721240549802377623, 91 -0.229257310594893932383e-4, 92 0.0, 93 0.0, 94 0.0 95 ]; 96 var Q4 = [ 97 1.0, 98 0.706039025937745133628, 99 0.15739599649558626358, 100 0.0106117950976845084417, 101 -0.36910273311764618902e-4, 102 0.493409563927590008943e-5, 103 -0.234055487025287216506e-6, 104 0.718833729365459760664e-8, 105 -0.1129200113474947419e-9 106 ]; 107 var P5 = [ 108 -4.78558028495135619286, 109 -1.89197364881972536382, 110 -0.211407134874412820099, 111 -0.000189204758260076688518, 112 0.00115140923889178742086, 113 0.639949204213164496988e-4, 114 0.139348932445324888343e-5, 115 0.0, 116 0.0 117 ]; 118 var Q5 = [ 119 1.0, 120 0.244345337378188557777, 121 0.00873370754492288653669, 122 -0.00117592765334434471562, 123 -0.743743682899933180415e-4, 124 -0.21750464515767984778e-5, 125 0.471001264003076486547e-8, 126 -0.833378440625385520576e-10, 127 0.699841545204845636531e-12 128 ]; 129 var P6 = [ 130 -10.3948950573308896825, 131 -2.85827219671106697179, 132 -0.347728266539245787271, 133 -0.0251156064655346341766, 134 -0.00119459173416968685689, 135 -0.382529323507967522614e-4, 136 -0.785523633796723466968e-6, 137 -0.821465709095465524192e-8 138 ]; 139 var Q6 = [ 140 1.0, 141 0.208196333572671890965, 142 0.0195687657317205033485, 143 0.00111079638102485921877, 144 0.408507746266039256231e-4, 145 0.955561123065693483991e-6, 146 0.118507153474022900583e-7, 147 0.222609483627352615142e-14 148 ]; 149 150 // Header to add to output files: 151 var header = licenseHeader( 'Apache-2.0', 'js', { 152 'year': ( new Date() ).getFullYear(), 153 'copyright': 'The Stdlib Authors' 154 }); 155 header += '\n/* This is a generated file. Do not edit directly. */\n'; 156 157 158 // MAIN // 159 160 /** 161 * Main execution sequence. 162 * 163 * @private 164 */ 165 function main() { 166 var fpath; 167 var opts; 168 var str; 169 170 opts = { 171 'encoding': 'utf8' 172 }; 173 174 fpath = resolve( __dirname, '..', 'lib', 'rational_p1q1.js' ); 175 str = header + compile( P1, Q1 ); 176 writeFileSync( fpath, str, opts ); 177 178 fpath = resolve( __dirname, '..', 'lib', 'rational_p2q2.js' ); 179 str = header + compile( P2, Q2 ); 180 writeFileSync( fpath, str, opts ); 181 182 fpath = resolve( __dirname, '..', 'lib', 'rational_p3q3.js' ); 183 str = header + compile( P3, Q3 ); 184 writeFileSync( fpath, str, opts ); 185 186 fpath = resolve( __dirname, '..', 'lib', 'rational_p4q4.js' ); 187 str = header + compile( P4, Q4 ); 188 writeFileSync( fpath, str, opts ); 189 190 fpath = resolve( __dirname, '..', 'lib', 'rational_p5q5.js' ); 191 str = header + compile( P5, Q5 ); 192 writeFileSync( fpath, str, opts ); 193 194 fpath = resolve( __dirname, '..', 'lib', 'rational_p6q6.js' ); 195 str = header + compile( P6, Q6 ); 196 writeFileSync( fpath, str, opts ); 197 } 198 199 main();