Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1606x 1606x 1606x 1606x 1606x 1606x 1606x 1606x 1606x 1606x 1606x 1606x 1606x 1606x 1606x 1606x 1606x 1606x 1x 1x 1605x 1605x 1606x 500x 500x 500x 500x 500x 500x 100x 100x 400x 400x 400x 500x 101x 500x 299x 155x 155x 155x 299x 299x 400x 400x 1505x 1505x 1606x 2x 2x 2x 18x 18x 18x 2x 1606x 1503x 1503x 1503x 1503x 7633x 7633x 7633x 1503x 1503x 1503x 1498x 1498x 1503x 5x 5x 1503x 1503x 1505x 1606x 400x 400x 1505x 1606x 1x 1x 1x 1x 1x | /**
* @license Apache-2.0
*
* Copyright (c) 2026 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
'use strict';
// MODULES //
var float64ToFloat32 = require( '@stdlib/number/float64/base/to-float32' );
var floorf = require( '@stdlib/math/base/special/floorf' );
var lnf = require( '@stdlib/math/base/special/lnf' );
var cotf = require( '@stdlib/math/base/special/cotf' );
var FLOAT32_PI = require( '@stdlib/constants/float32/pi' );
var EULERGAMMA = require( '@stdlib/constants/float32/eulergamma' );
var isnanf = require( '@stdlib/math/base/assert/is-nanf' );
var polyvalP = require( './polyval_p.js' );
// MAIN //
/**
* Evaluates the digamma function for a single-precision floating-point number.
*
* @param {number} x - input value
* @returns {number} function value
*
* @example
* var v = digammaf( 1.0 );
* // returns ~-0.577
*
* @example
* var v = digammaf( 2.0 );
* // returns ~0.423
*
* @example
* var v = digammaf( 3.0 );
* // returns ~0.923
*
* @example
* var v = digammaf( -2.5 );
* // returns ~1.103
*
* @example
* var v = digammaf( 0.0 );
* // returns NaN
*
* @example
* var v = digammaf( NaN );
* // returns NaN
*/
function digammaf(x) {
var negative;
var nz;
var xx;
var p;
var q;
var s;
var w;
var y;
var z;
var i;
var n;
xx = float64ToFloat32(x);
nz = 0.0;
negative = false;
if (isnanf(xx)) {
return xx;
}
// Handle negative arguments using reflection formula...
if (xx <= 0.0) {
negative = true;
q = xx;
p = floorf(q);
// Check for singularity (negative integer or zero)...
if (p === q) {
return NaN;
}
// Compute fractional part...
nz = float64ToFloat32(q - p);
if (nz === 0.5) {
nz = 0.0;
} else {
if (nz > 0.5) {
p += 1.0;
nz = float64ToFloat32(q - p);
}
nz = float64ToFloat32(FLOAT32_PI * cotf(float64ToFloat32(FLOAT32_PI * nz))); // eslint-disable-line max-len
}
xx = float64ToFloat32(1.0 - xx);
}
// Use direct formula for small positive integers...
if (xx <= 10.0 && xx === floorf(xx)) {
y = 0.0;
n = xx;
for (i = 1; i < n; i++) {
w = i;
y = float64ToFloat32(y + float64ToFloat32(1.0 / w));
}
y = float64ToFloat32(y - EULERGAMMA);
} else {
// Use recurrence to make x large enough for asymptotic expansion...
s = xx;
w = 0.0;
while (s < 10.0) {
w = float64ToFloat32(w + float64ToFloat32(1.0 / s));
s = float64ToFloat32(s + 1.0);
}
// Asymptotic expansion...
if (s < 1.0e8) {
z = float64ToFloat32(1.0 / float64ToFloat32(s * s));
y = float64ToFloat32(z * polyvalP(z));
} else {
y = 0.0;
}
y = float64ToFloat32(lnf(s) - float64ToFloat32(0.5 / s) - y - w);
}
if (negative) {
y = float64ToFloat32(y - nz);
}
return y;
}
// EXPORTS //
module.exports = digammaf;
|