time-to-botec

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

evalrational.js (2616B)


      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 /*
     37 * arcsin(x) = x + x^3 P(x^2)/Q(x^2)
     38 * 0 <= x <= 0.625
     39 * Peak relative error = 1.2e-18
     40 */
     41 var P = [
     42 	-8.198089802484824371615e0,
     43 	1.956261983317594739197e1,
     44 	-1.626247967210700244449e1,
     45 	5.444622390564711410273e0,
     46 	-6.019598008014123785661e-1,
     47 	4.253011369004428248960e-3
     48 ];
     49 var Q = [
     50 	-4.918853881490881290097e1,
     51 	1.395105614657485689735e2,
     52 	-1.471791292232726029859e2,
     53 	7.049610280856842141659e1,
     54 	-1.474091372988853791896e1,
     55 	1.0
     56 ];
     57 
     58 /*
     59 * arcsin(1-x) = pi/2 - sqrt(2x)(1+R(x))
     60 * 0 <= x <= 0.5
     61 * Peak relative error = 4.2e-18
     62 */
     63 var R = [
     64 	2.853665548261061424989e1,
     65 	-2.556901049652824852289e1,
     66 	6.968710824104713396794e0,
     67 	-5.634242780008963776856e-1,
     68 	2.967721961301243206100e-3
     69 ];
     70 var S = [
     71 	3.424398657913078477438e2,
     72 	-3.838770957603691357202e2,
     73 	1.470656354026814941758e2,
     74 	-2.194779531642920639778e1,
     75 	1.0
     76 ];
     77 
     78 // Header to add to output files:
     79 var header = licenseHeader( 'Apache-2.0', 'js', {
     80 	'year': ( new Date() ).getFullYear(),
     81 	'copyright': 'The Stdlib Authors'
     82 });
     83 header += '\n/* This is a generated file. Do not edit directly. */\n';
     84 
     85 
     86 // MAIN //
     87 
     88 /**
     89 * Main execution sequence.
     90 *
     91 * @private
     92 */
     93 function main() {
     94 	var fpath;
     95 	var opts;
     96 	var str;
     97 
     98 	opts = {
     99 		'encoding': 'utf8'
    100 	};
    101 
    102 	fpath = resolve( __dirname, '..', 'lib', 'rational_pq.js' );
    103 	str = header + compile( P, Q );
    104 	writeFileSync( fpath, str, opts );
    105 
    106 	fpath = resolve( __dirname, '..', 'lib', 'rational_rs.js' );
    107 	str = header + compile( R, S );
    108 	writeFileSync( fpath, str, opts );
    109 }
    110 
    111 main();