asymptotic_expansion.js (1605B)
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_53_0/libs/math/doc/sf_and_dist/html/math_toolkit/special/sf_gamma/digamma.html}. The implementation follows the original but has been modified for JavaScript. 22 * 23 * ```text 24 * (C) Copyright John Maddock 2006. 25 * 26 * Use, modification and distribution are subject to the 27 * Boost Software License, Version 1.0. (See accompanying file 28 * LICENSE or copy at http://www.boost.org/LICENSE_1_0.txt) 29 * ``` 30 */ 31 32 'use strict'; 33 34 // MODULES // 35 36 var ln = require( './../../../../base/special/ln' ); 37 var polyval = require( './polyval_p.js' ); 38 39 40 // MAIN // 41 42 /** 43 * Evaluates the digamma function via asymptotic expansion. 44 * 45 * @private 46 * @param {number} x - input value 47 * @returns {number} function value 48 */ 49 function digamma( x ) { 50 var y; 51 var z; 52 x -= 1.0; 53 y = ln(x) + ( 1.0 / (2.0*x) ); 54 z = 1.0 / (x*x); 55 return y - ( z*polyval( z ) ); 56 } 57 58 59 // EXPORTS // 60 61 module.exports = digamma;