time-to-botec

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

evalpoly.js (5520B)


      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 var A1 = [
     36 	6.73523010531292681824e-02, // 0x3FB13E001A5562A7
     37 	7.38555086081402883957e-03, // 0x3F7E404FB68FEFE8
     38 	1.19270763183362067845e-03, // 0x3F538A94116F3F5D
     39 	2.20862790713908385557e-04, // 0x3F2CF2ECED10E54D
     40 	2.52144565451257326939e-05  // 0x3EFA7074428CFA52
     41 ];
     42 var A2 = [
     43 	2.05808084325167332806e-02, // 0x3F951322AC92547B
     44 	2.89051383673415629091e-03, // 0x3F67ADD8CCB7926B
     45 	5.10069792153511336608e-04, // 0x3F40B6C689B99C00
     46 	1.08011567247583939954e-04, // 0x3F1C5088987DFB07
     47 	4.48640949618915160150e-05  // 0x3F07858E90A45837
     48 ];
     49 var R = [
     50 	1.39200533467621045958e+00, // 0x3FF645A762C4AB74
     51 	7.21935547567138069525e-01, // 0x3FE71A1893D3DCDC
     52 	1.71933865632803078993e-01, // 0x3FC601EDCCFBDF27
     53 	1.86459191715652901344e-02, // 0x3F9317EA742ED475
     54 	7.77942496381893596434e-04, // 0x3F497DDACA41A95B
     55 	7.32668430744625636189e-06  // 0x3EDEBAF7A5B38140
     56 ];
     57 var S = [
     58 	2.14982415960608852501e-01,  // 0x3FCB848B36E20878
     59 	3.25778796408930981787e-01,  // 0x3FD4D98F4F139F59
     60 	1.46350472652464452805e-01,  // 0x3FC2BB9CBEE5F2F7
     61 	2.66422703033638609560e-02,  // 0x3F9B481C7E939961
     62 	1.84028451407337715652e-03,  // 0x3F5E26B67368F239
     63 	3.19475326584100867617e-05   // 0x3F00BFECDD17E945
     64 ];
     65 var T1 = [
     66 	-3.27885410759859649565e-02, // 0xBFA0C9A8DF35B713
     67 	6.10053870246291332635e-03,  // 0x3F78FCE0E370E344
     68 	-1.40346469989232843813e-03, // 0xBF56FE8EBF2D1AF1
     69 	3.15632070903625950361e-04   // 0x3F34AF6D6C0EBBF7
     70 ];
     71 var T2 = [
     72 	1.79706750811820387126e-02,  // 0x3F9266E7970AF9EC
     73 	-3.68452016781138256760e-03, // 0xBF6E2EFFB3E914D7
     74 	8.81081882437654011382e-04,  // 0x3F4CDF0CEF61A8E9
     75 	-3.12754168375120860518e-04  // 0xBF347F24ECC38C38
     76 ];
     77 var T3 = [
     78 	-1.03142241298341437450e-02, // 0xBF851F9FBA91EC6A
     79 	2.25964780900612472250e-03,  // 0x3F6282D32E15C915
     80 	-5.38595305356740546715e-04, // 0xBF41A6109C73E0EC
     81 	3.35529192635519073543e-04   // 0x3F35FD3EE8C2D3F4
     82 ];
     83 var U = [
     84 	6.32827064025093366517e-01,  // 0x3FE4401E8B005DFF
     85 	1.45492250137234768737e+00,  // 0x3FF7475CD119BD6F
     86 	9.77717527963372745603e-01,  // 0x3FEF497644EA8450
     87 	2.28963728064692451092e-01,  // 0x3FCD4EAEF6010924
     88 	1.33810918536787660377e-02   // 0x3F8B678BBF2BAB09
     89 ];
     90 var V = [
     91 	2.45597793713041134822e+00, // 0x4003A5D7C2BD619C
     92 	2.12848976379893395361e+00, // 0x40010725A42B18F5
     93 	7.69285150456672783825e-01, // 0x3FE89DFBE45050AF
     94 	1.04222645593369134254e-01, // 0x3FBAAE55D6537C88
     95 	3.21709242282423911810e-03  // 0x3F6A5ABB57D0CF61
     96 ];
     97 var W = [
     98 	8.33333333333329678849e-02,  // 0x3FB555555555553B
     99 	-2.77777777728775536470e-03, // 0xBF66C16C16B02E5C
    100 	7.93650558643019558500e-04,  // 0x3F4A019F98CF38B6
    101 	-5.95187557450339963135e-04, // 0xBF4380CB8C0FE741
    102 	8.36339918996282139126e-04,  // 0x3F4B67BA4CDAD5D1
    103 	-1.63092934096575273989e-03  // 0xBF5AB89D0B9E43E4
    104 ];
    105 
    106 // Header to add to output files:
    107 var header = licenseHeader( 'Apache-2.0', 'js', {
    108 	'year': ( new Date() ).getFullYear(),
    109 	'copyright': 'The Stdlib Authors'
    110 });
    111 header += '\n/* This is a generated file. Do not edit directly. */\n';
    112 
    113 
    114 // MAIN //
    115 
    116 /**
    117 * Main execution sequence.
    118 *
    119 * @private
    120 */
    121 function main() {
    122 	var fpath;
    123 	var opts;
    124 	var str;
    125 
    126 	opts = {
    127 		'encoding': 'utf8'
    128 	};
    129 
    130 	fpath = resolve( __dirname, '..', 'lib', 'polyval_a1.js' );
    131 	str = header + compile( A1 );
    132 	writeFileSync( fpath, str, opts );
    133 
    134 	fpath = resolve( __dirname, '..', 'lib', 'polyval_a2.js' );
    135 	str = header + compile( A2 );
    136 	writeFileSync( fpath, str, opts );
    137 
    138 	fpath = resolve( __dirname, '..', 'lib', 'polyval_r.js' );
    139 	str = header + compile( R );
    140 	writeFileSync( fpath, str, opts );
    141 
    142 	fpath = resolve( __dirname, '..', 'lib', 'polyval_s.js' );
    143 	str = header + compile( S );
    144 	writeFileSync( fpath, str, opts );
    145 
    146 	fpath = resolve( __dirname, '..', 'lib', 'polyval_t1.js' );
    147 	str = header + compile( T1 );
    148 	writeFileSync( fpath, str, opts );
    149 
    150 	fpath = resolve( __dirname, '..', 'lib', 'polyval_t2.js' );
    151 	str = header + compile( T2 );
    152 	writeFileSync( fpath, str, opts );
    153 
    154 	fpath = resolve( __dirname, '..', 'lib', 'polyval_t3.js' );
    155 	str = header + compile( T3 );
    156 	writeFileSync( fpath, str, opts );
    157 
    158 	fpath = resolve( __dirname, '..', 'lib', 'polyval_u.js' );
    159 	str = header + compile( U );
    160 	writeFileSync( fpath, str, opts );
    161 
    162 	fpath = resolve( __dirname, '..', 'lib', 'polyval_v.js' );
    163 	str = header + compile( V );
    164 	writeFileSync( fpath, str, opts );
    165 
    166 	fpath = resolve( __dirname, '..', 'lib', 'polyval_w.js' );
    167 	str = header + compile( W );
    168 	writeFileSync( fpath, str, opts );
    169 }
    170 
    171 main();