rational_approximation.js (1233B)
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 'use strict'; 20 21 // MODULES // 22 23 var rateval = require( './rational_pq.js' ); 24 25 26 // VARIABLES // 27 28 var root1 = 1569415565.0 / 1073741824.0; 29 var root2 = ( 381566830.0 / 1073741824.0 ) / 1073741824.0; 30 var root3 = 0.9016312093258695918615325266959189453125e-19; 31 var Y = 0.99558162689208984; 32 33 34 // MAIN // 35 36 /** 37 * Evaluates the digamma function over interval `[1,2]`. 38 * 39 * @private 40 * @param {number} x - input value 41 * @returns {number} function value 42 */ 43 function digamma( x ) { 44 var g; 45 var r; 46 g = x - root1; 47 g -= root2; 48 g -= root3; 49 r = rateval( x-1.0 ); 50 return (g*Y) + (g*r); 51 } 52 53 54 // EXPORTS // 55 56 module.exports = digamma;