time-to-botec

Benchmark sampling in different programming languages
Log | Files | Refs | README

evalpoly.js (7580B)


      1 /**
      2 * @license Apache-2.0
      3 *
      4 * Copyright (c) 2019 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 // The tables below are from Fukushima, Toshio. 2009. "Fast computation of complete elliptic integrals and Jacobian elliptic functions." _Celestial Mechanics and Dynamical Astronomy_ 105 (4): 305. doi:[10.1007/s10569-009-9228-z](https://doi.org/10.1007/s10569-009-9228-z).
     35 
     36 // Table 2 for expansion about x = 0.05:
     37 var P1 = [
     38 	1.550973351780472328,
     39 	-0.400301020103198524,
     40 	-0.078498619442941939,
     41 	-0.034318853117591992,
     42 	-0.019718043317365499,
     43 	-0.013059507731993309,
     44 	-0.009442372874146547,
     45 	-0.007246728512402157,
     46 	-0.005807424012956090,
     47 	-0.004809187786009338
     48 ];
     49 
     50 // Table 3 for expansion about 0.15:
     51 var P2 = [
     52 	1.510121832092819728,
     53 	-0.417116333905867549,
     54 	-0.090123820404774569,
     55 	-0.043729944019084312,
     56 	-0.027965493064761785,
     57 	-0.020644781177568105,
     58 	-0.016650786739707238,
     59 	-0.014261960828842520,
     60 	-0.012759847429264803,
     61 	-0.011799303775587354,
     62 	-0.011197445703074968
     63 ];
     64 
     65 // Table 4 for expansion about 0.25:
     66 var P3 = [
     67 	1.467462209339427155,
     68 	-0.436576290946337775,
     69 	-0.105155557666942554,
     70 	-0.057371843593241730,
     71 	-0.041391627727340220,
     72 	-0.034527728505280841,
     73 	-0.031495443512532783,
     74 	-0.030527000890325277,
     75 	-0.030916984019238900,
     76 	-0.032371395314758122,
     77 	-0.034789960386404158
     78 ];
     79 
     80 // Table 5 for expansion about 0.35:
     81 var P4 = [
     82 	1.422691133490879171,
     83 	-0.459513519621048674,
     84 	-0.125250539822061878,
     85 	-0.078138545094409477,
     86 	-0.064714278472050002,
     87 	-0.062084339131730311,
     88 	-0.065197032815572477,
     89 	-0.072793895362578779,
     90 	-0.084959075171781003,
     91 	-0.102539850131045997,
     92 	-0.127053585157696036,
     93 	-0.160791120691274606
     94 ];
     95 
     96 // Table 6 for expansion about 0.45:
     97 var P5 = [
     98 	1.375401971871116291,
     99 	-0.487202183273184837,
    100 	-0.153311701348540228,
    101 	-0.111849444917027833,
    102 	-0.108840952523135768,
    103 	-0.122954223120269076,
    104 	-0.152217163962035047,
    105 	-0.200495323642697339,
    106 	-0.276174333067751758,
    107 	-0.393513114304375851,
    108 	-0.575754406027879147,
    109 	-0.860523235727239756,
    110 	-1.308833205758540162
    111 ];
    112 
    113 // Table 7 for expansion about 0.55:
    114 var P6 = [
    115 	1.325024497958230082,
    116 	-0.521727647557566767,
    117 	-0.194906430482126213,
    118 	-0.171623726822011264,
    119 	-0.202754652926419141,
    120 	-0.278798953118534762,
    121 	-0.420698457281005762,
    122 	-0.675948400853106021,
    123 	-1.136343121839229244,
    124 	-1.976721143954398261,
    125 	-3.531696773095722506,
    126 	-6.446753640156048150,
    127 	-11.97703130208884026
    128 ];
    129 
    130 // Table 8 for expansion about 0.65:
    131 var P7 = [
    132 	1.270707479650149744,
    133 	-0.566839168287866583,
    134 	-0.262160793432492598,
    135 	-0.292244173533077419,
    136 	-0.440397840850423189,
    137 	-0.774947641381397458,
    138 	-1.498870837987561088,
    139 	-3.089708310445186667,
    140 	-6.667595903381001064,
    141 	-14.89436036517319078,
    142 	-34.18120574251449024,
    143 	-80.15895841905397306,
    144 	-191.3489480762984920,
    145 	-463.5938853480342030,
    146 	-1137.380822169360061
    147 ];
    148 
    149 // Table 9 for expansion about 0.75:
    150 var P8 = [
    151 	1.211056027568459525,
    152 	-0.630306413287455807,
    153 	-0.387166409520669145,
    154 	-0.592278235311934603,
    155 	-1.237555584513049844,
    156 	-3.032056661745247199,
    157 	-8.181688221573590762,
    158 	-23.55507217389693250,
    159 	-71.04099935893064956,
    160 	-221.8796853192349888,
    161 	-712.1364793277635425,
    162 	-2336.125331440396407,
    163 	-7801.945954775964673,
    164 	-26448.19586059191933,
    165 	-90799.48341621365251,
    166 	-315126.0406449163424,
    167 	-1104011.344311591159
    168 ];
    169 
    170 // Table 10 for expansion about 0.825:
    171 var P9 = [
    172 	1.161307152196282836,
    173 	-0.701100284555289548,
    174 	-0.580551474465437362,
    175 	-1.243693061077786614,
    176 	-3.679383613496634879,
    177 	-12.81590924337895775,
    178 	-49.25672530759985272,
    179 	-202.1818735434090269,
    180 	-869.8602699308701437,
    181 	-3877.005847313289571,
    182 	-17761.70710170939814,
    183 	-83182.69029154232061,
    184 	-396650.4505013548170,
    185 	-1920033.413682634405
    186 ];
    187 
    188 // Table 11 for expansion about 0.875:
    189 var P10 = [
    190 	1.124617325119752213,
    191 	-0.770845056360909542,
    192 	-0.844794053644911362,
    193 	-2.490097309450394453,
    194 	-10.23971741154384360,
    195 	-49.74900546551479866,
    196 	-267.0986675195705196,
    197 	-1532.665883825229947,
    198 	-9222.313478526091951,
    199 	-57502.51612140314030,
    200 	-368596.1167416106063,
    201 	-2415611.088701091428,
    202 	-16120097.81581656797,
    203 	-109209938.5203089915,
    204 	-749380758.1942496220,
    205 	-5198725846.725541393,
    206 	-36409256888.12139973
    207 ];
    208 
    209 // Table 2 for the expansion of K(m) around 0.05
    210 var P11 = [
    211 	1.591003453790792180,
    212 	0.416000743991786912,
    213 	0.245791514264103415,
    214 	0.179481482914906162,
    215 	0.144556057087555150,
    216 	0.123200993312427711,
    217 	0.108938811574293531,
    218 	0.098853409871592910,
    219 	0.091439629201749751,
    220 	0.085842591595413900,
    221 	0.081541118718303215
    222 ];
    223 
    224 // Table 2 for the expansion of E(m) around 0.05
    225 var P12 = [
    226 	1.550973351780472328,
    227 	-0.400301020103198524,
    228 	-0.078498619442941939,
    229 	-0.034318853117591992,
    230 	-0.019718043317365499,
    231 	-0.013059507731993309,
    232 	-0.009442372874146547,
    233 	-0.007246728512402157,
    234 	-0.005807424012956090,
    235 	-0.004809187786009338
    236 ];
    237 
    238 // Header to add to output files:
    239 var header = licenseHeader( 'Apache-2.0', 'js', {
    240 	'year': ( new Date() ).getFullYear(),
    241 	'copyright': 'The Stdlib Authors'
    242 });
    243 header += '\n/* This is a generated file. Do not edit directly. */\n';
    244 
    245 
    246 // MAIN //
    247 
    248 /**
    249 * Main execution sequence.
    250 *
    251 * @private
    252 */
    253 function main() {
    254 	var fpath;
    255 	var opts;
    256 	var str;
    257 
    258 	opts = {
    259 		'encoding': 'utf8'
    260 	};
    261 
    262 	fpath = resolve( __dirname, '..', 'lib', 'poly_p1.js' );
    263 	str = header + compile( P1 );
    264 	writeFileSync( fpath, str, opts );
    265 
    266 	fpath = resolve( __dirname, '..', 'lib', 'poly_p2.js' );
    267 	str = header + compile( P2 );
    268 	writeFileSync( fpath, str, opts );
    269 
    270 	fpath = resolve( __dirname, '..', 'lib', 'poly_p3.js' );
    271 	str = header + compile( P3 );
    272 	writeFileSync( fpath, str, opts );
    273 
    274 	fpath = resolve( __dirname, '..', 'lib', 'poly_p4.js' );
    275 	str = header + compile( P4 );
    276 	writeFileSync( fpath, str, opts );
    277 
    278 	fpath = resolve( __dirname, '..', 'lib', 'poly_p5.js' );
    279 	str = header + compile( P5 );
    280 	writeFileSync( fpath, str, opts );
    281 
    282 	fpath = resolve( __dirname, '..', 'lib', 'poly_p6.js' );
    283 	str = header + compile( P6 );
    284 	writeFileSync( fpath, str, opts );
    285 
    286 	fpath = resolve( __dirname, '..', 'lib', 'poly_p7.js' );
    287 	str = header + compile( P7 );
    288 	writeFileSync( fpath, str, opts );
    289 
    290 	fpath = resolve( __dirname, '..', 'lib', 'poly_p8.js' );
    291 	str = header + compile( P8 );
    292 	writeFileSync( fpath, str, opts );
    293 
    294 	fpath = resolve( __dirname, '..', 'lib', 'poly_p9.js' );
    295 	str = header + compile( P9 );
    296 	writeFileSync( fpath, str, opts );
    297 
    298 	fpath = resolve( __dirname, '..', 'lib', 'poly_p10.js' );
    299 	str = header + compile( P10 );
    300 	writeFileSync( fpath, str, opts );
    301 
    302 	fpath = resolve( __dirname, '..', 'lib', 'poly_p11.js' );
    303 	str = header + compile( P11 );
    304 	writeFileSync( fpath, str, opts );
    305 
    306 	fpath = resolve( __dirname, '..', 'lib', 'poly_p12.js' );
    307 	str = header + compile( P12 );
    308 	writeFileSync( fpath, str, opts );
    309 }
    310 
    311 main();