time-to-botec

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

small_gamma2_series.js (1745B)


      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 * ## Notice
     20 *
     21 * The original C++ code and copyright notice are from the [Boost library]{@link http://www.boost.org/doc/libs/1_37_0/boost/math/special_functions/gamma.hpp}. The implementation has been modified for JavaScript.
     22 *
     23 * ```text
     24 * (C) Copyright John Maddock 2006.
     25 * (C) Copyright Paul A. Bristow 2007.
     26 *
     27 * Use, modification and distribution are subject to the
     28 * Boost Software License, Version 1.0. (See accompanying file
     29 * LICENSE or copy at http://www.boost.org/LICENSE_1_0.txt)
     30 * ```
     31 */
     32 
     33 'use strict';
     34 
     35 /**
     36 * Series representation for upper fraction when `z` is small.
     37 *
     38 * @private
     39 * @param {number} a - function parameter
     40 * @param {number} x - function parameter
     41 * @returns {Function} series function
     42 */
     43 function smallGamma2Series( a, x ) {
     44 	var result;
     45 	var apn;
     46 	var n;
     47 	var r;
     48 
     49 	result = -x;
     50 	x = -x;
     51 	apn = a + 1.0;
     52 	n = 1;
     53 	return next;
     54 
     55 	/**
     56 	* Calculate the next term of the series.
     57 	*
     58 	* @private
     59 	* @returns {number} series expansion term
     60 	*/
     61 	function next() {
     62 		r = result / apn;
     63 		result *= x;
     64 		n += 1;
     65 		result /= n;
     66 		apn += 1.0;
     67 		return r;
     68 	}
     69 }
     70 
     71 
     72 // EXPORTS //
     73 
     74 module.exports = smallGamma2Series;