time-to-botec

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

evalpoly.js (5571B)


      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/evalpoly-compile' );
     30 
     31 
     32 // VARIABLES //
     33 
     34 // Polynomial coefficients ordered in ascending degree...
     35 
     36 // Coefficients for approximation to erf on [0, 0.84375)
     37 var PP = [
     38 	-3.25042107247001499370e-1, // 0xBFD4CD7D, 0x691CB913
     39 	-2.84817495755985104766e-2, // 0xBF9D2A51, 0xDBD7194F
     40 	-5.77027029648944159157e-3, // 0xBF77A291, 0x236668E4
     41 	-2.37630166566501626084e-5  // 0xBEF8EAD6, 0x120016AC
     42 ];
     43 var QQ = [
     44 	3.97917223959155352819e-1, // 0x3FD97779, 0xCDDADC09
     45 	6.50222499887672944485e-2, // 0x3FB0A54C, 0x5536CEBA
     46 	5.08130628187576562776e-3, // 0x3F74D022, 0xC4D36B0F
     47 	1.32494738004321644526e-4, // 0x3F215DC9, 0x221C1A10
     48 	-3.96022827877536812320e-6 // 0xBED09C43, 0x42A26120
     49 ];
     50 
     51 // Coefficients for approximation to erf on [0.84375, 1.25)
     52 var PA = [
     53 	4.14856118683748331666e-1,  // 0x3FDA8D00, 0xAD92B34D
     54 	-3.72207876035701323847e-1, // 0xBFD7D240, 0xFBB8C3F1
     55 	3.18346619901161753674e-1,  // 0x3FD45FCA, 0x805120E4
     56 	-1.10894694282396677476e-1, // 0xBFBC6398, 0x3D3E28EC
     57 	3.54783043256182359371e-2,  // 0x3FA22A36, 0x599795EB
     58 	-2.16637559486879084300e-3  // 0xBF61BF38, 0x0A96073F
     59 ];
     60 var QA = [
     61 	1.06420880400844228286e-1, // 0x3FBB3E66, 0x18EEE323
     62 	5.40397917702171048937e-1, // 0x3FE14AF0, 0x92EB6F33
     63 	7.18286544141962662868e-2, // 0x3FB2635C, 0xD99FE9A7
     64 	1.26171219808761642112e-1, // 0x3FC02660, 0xE763351F
     65 	1.36370839120290507362e-2, // 0x3F8BEDC2, 0x6B51DD1C
     66 	1.19844998467991074170e-2  // 0x3F888B54, 0x5735151D
     67 ];
     68 
     69 // Coefficients for approximation to erfc on [1.25, 1/0.35)
     70 var RA = [
     71 	-6.93858572707181764372e-1, // 0xBFE63416, 0xE4BA7360
     72 	-1.05586262253232909814e1,  // 0xC0251E04, 0x41B0E726
     73 	-6.23753324503260060396e1,  // 0xC04F300A, 0xE4CBA38D
     74 	-1.62396669462573470355e2,  // 0xC0644CB1, 0x84282266
     75 	-1.84605092906711035994e2,  // 0xC067135C, 0xEBCCABB2
     76 	-8.12874355063065934246e1,  // 0xC0545265, 0x57E4D2F2
     77 	-9.81432934416914548592     // 0xC023A0EF, 0xC69AC25C
     78 ];
     79 var SA = [
     80 	1.96512716674392571292e1,  // 0x4033A6B9, 0xBD707687
     81 	1.37657754143519042600e2,  // 0x4061350C, 0x526AE721
     82 	4.34565877475229228821e2,  // 0x407B290D, 0xD58A1A71
     83 	6.45387271733267880336e2,  // 0x40842B19, 0x21EC2868
     84 	4.29008140027567833386e2,  // 0x407AD021, 0x57700314
     85 	1.08635005541779435134e2,  // 0x405B28A3, 0xEE48AE2C
     86 	6.57024977031928170135,    // 0x401A47EF, 0x8E484A93
     87 	-6.04244152148580987438e-2 // 0xBFAEEFF2, 0xEE749A62
     88 ];
     89 
     90 // Coefficients for approximation to erfc on [1/0.35, 28]
     91 var RB = [
     92 	-7.99283237680523006574e-1, // 0xBFE993BA, 0x70C285DE
     93 	-1.77579549177547519889e1,  // 0xC031C209, 0x555F995A
     94 	-1.60636384855821916062e2,  // 0xC064145D, 0x43C5ED98
     95 	-6.37566443368389627722e2,  // 0xC083EC88, 0x1375F228
     96 	-1.02509513161107724954e3,  // 0xC0900461, 0x6A2E5992
     97 	-4.83519191608651397019e2   // 0xC07E384E, 0x9BDC383F
     98 ];
     99 var SB = [
    100 	3.03380607434824582924e1, // 0x403E568B, 0x261D5190
    101 	3.25792512996573918826e2, // 0x40745CAE, 0x221B9F0A
    102 	1.53672958608443695994e3, // 0x409802EB, 0x189D5118
    103 	3.19985821950859553908e3, // 0x40A8FFB7, 0x688C246A
    104 	2.55305040643316442583e3, // 0x40A3F219, 0xCEDF3BE6
    105 	4.74528541206955367215e2, // 0x407DA874, 0xE79FE763
    106 	-2.24409524465858183362e1 // 0xC03670E2, 0x42712D62
    107 ];
    108 
    109 // Header to add to output files:
    110 var header = licenseHeader( 'Apache-2.0', 'js', {
    111 	'year': ( new Date() ).getFullYear(),
    112 	'copyright': 'The Stdlib Authors'
    113 });
    114 header += '\n/* This is a generated file. Do not edit directly. */\n';
    115 
    116 
    117 // MAIN //
    118 
    119 /**
    120 * Main execution sequence.
    121 *
    122 * @private
    123 */
    124 function main() {
    125 	var fpath;
    126 	var opts;
    127 	var str;
    128 
    129 	opts = {
    130 		'encoding': 'utf8'
    131 	};
    132 
    133 	fpath = resolve( __dirname, '..', 'lib', 'polyval_pp.js' );
    134 	str = header + compile( PP );
    135 	writeFileSync( fpath, str, opts );
    136 
    137 	fpath = resolve( __dirname, '..', 'lib', 'polyval_qq.js' );
    138 	str = header + compile( QQ );
    139 	writeFileSync( fpath, str, opts );
    140 
    141 	fpath = resolve( __dirname, '..', 'lib', 'polyval_pa.js' );
    142 	str = header + compile( PA );
    143 	writeFileSync( fpath, str, opts );
    144 
    145 	fpath = resolve( __dirname, '..', 'lib', 'polyval_qa.js' );
    146 	str = header + compile( QA );
    147 	writeFileSync( fpath, str, opts );
    148 
    149 	fpath = resolve( __dirname, '..', 'lib', 'polyval_ra.js' );
    150 	str = header + compile( RA );
    151 	writeFileSync( fpath, str, opts );
    152 
    153 	fpath = resolve( __dirname, '..', 'lib', 'polyval_sa.js' );
    154 	str = header + compile( SA );
    155 	writeFileSync( fpath, str, opts );
    156 
    157 	fpath = resolve( __dirname, '..', 'lib', 'polyval_rb.js' );
    158 	str = header + compile( RB );
    159 	writeFileSync( fpath, str, opts );
    160 
    161 	fpath = resolve( __dirname, '..', 'lib', 'polyval_sb.js' );
    162 	str = header + compile( SB );
    163 	writeFileSync( fpath, str, opts );
    164 }
    165 
    166 main();