time-to-botec

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

evalrational.js (4841B)


      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 // Coefficients for erfinv on [0, 0.5]:
     37 var P1 = [
     38 	-5.08781949658280665617e-4,
     39 	-8.36874819741736770379e-3,
     40 	3.34806625409744615033e-2,
     41 	-1.26926147662974029034e-2,
     42 	-3.65637971411762664006e-2,
     43 	2.19878681111168899165e-2,
     44 	8.22687874676915743155e-3,
     45 	-5.38772965071242932965e-3,
     46 	0.0,
     47 	0.0
     48 ];
     49 var Q1 = [
     50 	1.0,
     51 	-9.70005043303290640362e-1,
     52 	-1.56574558234175846809,
     53 	1.56221558398423026363,
     54 	6.62328840472002992063e-1,
     55 	-7.1228902341542847553e-1,
     56 	-5.27396382340099713954e-2,
     57 	7.95283687341571680018e-2,
     58 	-2.33393759374190016776e-3,
     59 	8.86216390456424707504e-4
     60 ];
     61 
     62 // Coefficients for erfinv for 0.5 > 1-x >= 0:
     63 var P2 = [
     64 	-2.02433508355938759655e-1,
     65 	1.05264680699391713268e-1,
     66 	8.37050328343119927838,
     67 	1.76447298408374015486e1,
     68 	-1.88510648058714251895e1,
     69 	-4.46382324441786960818e1,
     70 	1.7445385985570866523e1,
     71 	2.11294655448340526258e1,
     72 	-3.67192254707729348546
     73 ];
     74 var Q2 = [
     75 	1.0,
     76 	6.24264124854247537712,
     77 	3.9713437953343869095,
     78 	-2.86608180499800029974e1,
     79 	-2.01432634680485188801e1,
     80 	4.85609213108739935468e1,
     81 	1.08268667355460159008e1,
     82 	-2.26436933413139721736e1,
     83 	1.72114765761200282724
     84 ];
     85 
     86 // Coefficients for erfinv for sqrt( -log(1-x) ):
     87 var P3 = [
     88 	-1.31102781679951906451e-1,
     89 	-1.63794047193317060787e-1,
     90 	1.17030156341995252019e-1,
     91 	3.87079738972604337464e-1,
     92 	3.37785538912035898924e-1,
     93 	1.42869534408157156766e-1,
     94 	2.90157910005329060432e-2,
     95 	2.14558995388805277169e-3,
     96 	-6.79465575181126350155e-7,
     97 	2.85225331782217055858e-8,
     98 	-6.81149956853776992068e-10
     99 ];
    100 var Q3 = [
    101 	1.0,
    102 	3.46625407242567245975,
    103 	5.38168345707006855425,
    104 	4.77846592945843778382,
    105 	2.59301921623620271374,
    106 	8.48854343457902036425e-1,
    107 	1.52264338295331783612e-1,
    108 	1.105924229346489121e-2,
    109 	0.0,
    110 	0.0,
    111 	0.0
    112 ];
    113 
    114 var P4 = [
    115 	-3.50353787183177984712e-2,
    116 	-2.22426529213447927281e-3,
    117 	1.85573306514231072324e-2,
    118 	9.50804701325919603619e-3,
    119 	1.87123492819559223345e-3,
    120 	1.57544617424960554631e-4,
    121 	4.60469890584317994083e-6,
    122 	-2.30404776911882601748e-10,
    123 	2.66339227425782031962e-12
    124 ];
    125 var Q4 = [
    126 	1.0,
    127 	1.3653349817554063097,
    128 	7.62059164553623404043e-1,
    129 	2.20091105764131249824e-1,
    130 	3.41589143670947727934e-2,
    131 	2.63861676657015992959e-3,
    132 	7.64675292302794483503e-5,
    133 	0.0,
    134 	0.0
    135 ];
    136 
    137 var P5 = [
    138 	-1.67431005076633737133e-2,
    139 	-1.12951438745580278863e-3,
    140 	1.05628862152492910091e-3,
    141 	2.09386317487588078668e-4,
    142 	1.49624783758342370182e-5,
    143 	4.49696789927706453732e-7,
    144 	4.62596163522878599135e-9,
    145 	-2.81128735628831791805e-14,
    146 	9.9055709973310326855e-17
    147 ];
    148 var Q5 = [
    149 	1.0,
    150 	5.91429344886417493481e-1,
    151 	1.38151865749083321638e-1,
    152 	1.60746087093676504695e-2,
    153 	9.64011807005165528527e-4,
    154 	2.75335474764726041141e-5,
    155 	2.82243172016108031869e-7,
    156 	0.0,
    157 	0.0
    158 ];
    159 
    160 // Header to add to output files:
    161 var header = licenseHeader( 'Apache-2.0', 'js', {
    162 	'year': ( new Date() ).getFullYear(),
    163 	'copyright': 'The Stdlib Authors'
    164 });
    165 header += '\n/* This is a generated file. Do not edit directly. */\n';
    166 
    167 
    168 // MAIN //
    169 
    170 /**
    171 * Main execution sequence.
    172 *
    173 * @private
    174 */
    175 function main() {
    176 	var fpath;
    177 	var opts;
    178 	var str;
    179 
    180 	opts = {
    181 		'encoding': 'utf8'
    182 	};
    183 
    184 	fpath = resolve( __dirname, '..', 'lib', 'rational_p1q1.js' );
    185 	str = header + compile( P1, Q1 );
    186 	writeFileSync( fpath, str, opts );
    187 
    188 	fpath = resolve( __dirname, '..', 'lib', 'rational_p2q2.js' );
    189 	str = header + compile( P2, Q2 );
    190 	writeFileSync( fpath, str, opts );
    191 
    192 	fpath = resolve( __dirname, '..', 'lib', 'rational_p3q3.js' );
    193 	str = header + compile( P3, Q3 );
    194 	writeFileSync( fpath, str, opts );
    195 
    196 	fpath = resolve( __dirname, '..', 'lib', 'rational_p4q4.js' );
    197 	str = header + compile( P4, Q4 );
    198 	writeFileSync( fpath, str, opts );
    199 
    200 	fpath = resolve( __dirname, '..', 'lib', 'rational_p5q5.js' );
    201 	str = header + compile( P5, Q5 );
    202 	writeFileSync( fpath, str, opts );
    203 }
    204 
    205 main();