Skip to content

Commit 0d93dab

Browse files
committed
feat: update the JS implementation
--- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed ---
1 parent 2ebec87 commit 0d93dab

File tree

6 files changed

+268
-161
lines changed

6 files changed

+268
-161
lines changed

lib/node_modules/@stdlib/math/base/special/hyp2f1/lib/hyp2f1ra.js

Lines changed: 0 additions & 125 deletions
This file was deleted.

lib/node_modules/@stdlib/math/base/special/hyp2f1/lib/hys2f1.js

Lines changed: 106 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,108 @@
2020

2121
// MODULES //
2222

23-
var isNonPositiveInteger = require( '@stdlib/math/base/assert/is-nonpositive-integer' );
2423
var PINF = require( '@stdlib/constants/float64/pinf' );
24+
var round = require( '@stdlib/math/base/special/round' );
2525
var abs = require( '@stdlib/math/base/special/abs' );
26-
var hyp2f1ra = require( './hyp2f1ra.js' );
26+
var isNonPositiveInteger = require( './utils.js' ).isNonPositiveInteger;
2727

2828

2929
// VARIABLES //
3030

31+
var MACHEP = 1.11022302462515654042E-16;
3132
var EPS = 1.0e-13;
3233
var MAX_ITERATIONS = 10000;
3334

3435

36+
// FUNCTIONS //
37+
38+
/**
39+
* Evaluates the Gaussian hypergeometric function by two-term recurrence in `a`.
40+
*
41+
* @private
42+
* @param {number} a - input value
43+
* @param {number} b - input value
44+
* @param {number} c - input value
45+
* @param {number} x - input value
46+
* @param {number} loss - starting loss of significance
47+
* @returns {Object} the function value and error
48+
*/
49+
function hyp2f1ra( a, b, c, x, loss ) {
50+
var f2Val;
51+
var f1Val;
52+
var f0Val;
53+
var err;
54+
var da;
55+
var f1;
56+
var f0;
57+
var t;
58+
var n;
59+
60+
loss = 0.0;
61+
err = 0.0;
62+
63+
if ( ( c < 0.0 && a <= c ) || ( c >= 0.0 && a >= c ) ) {
64+
da = round( a - c );
65+
}
66+
else {
67+
da = round( a );
68+
}
69+
70+
t = a - da;
71+
if ( abs( da ) > MAX_ITERATIONS ) {
72+
loss = 1.0;
73+
return {
74+
'value': NaN,
75+
'error': loss
76+
};
77+
}
78+
79+
if ( da < 0.0 ) {
80+
f2Val = 0.0;
81+
f1 = hys2f1( t, b, c, x, err );
82+
loss += f1.error;
83+
err = f1.error;
84+
f0 = hys2f1( t - 1.0, b, c, x, err );
85+
loss += f0.error;
86+
t -= 1.0;
87+
f1Val = f1.value;
88+
f0Val = f0.value;
89+
for ( n = 1; n < -da; ++n ) {
90+
f2Val = f1Val;
91+
f1Val = f0Val;
92+
93+
// eslint-disable-next-line max-len
94+
f0Val = -(((((2.0 * t) - c) - (t * x) + (b * x)) * f1Val) + ((t * (x - 1.0)) * f2Val)) / (c - t);
95+
t -= 1.0;
96+
}
97+
}
98+
else {
99+
f2Val = 0.0;
100+
f1 = hys2f1( t, b, c, x, err );
101+
loss += f1.error;
102+
err = f1.error;
103+
f0 = hys2f1( t + 1.0, b, c, x, err ); // CHECK IF err is THE SAME OR NEW ONE
104+
loss += f0.error;
105+
t += 1.0;
106+
f1Val = f1.value;
107+
f0Val = f0.value;
108+
for ( n = 1; n < da; ++n ) {
109+
f2Val = f1Val;
110+
f1Val = f0Val;
111+
112+
// eslint-disable-next-line max-len
113+
f0Val = -(((((2.0 * t) - c) - (t * x) + (b * x)) * f1Val) + ((c - t) * f2Val)) / (t * (x - 1.0));
114+
t += 1.0;
115+
}
116+
}
117+
118+
return {
119+
'value': f0Val,
120+
'error': loss
121+
};
122+
}
123+
124+
35125
// MAIN //
36126

37127
/**
@@ -44,7 +134,6 @@ var MAX_ITERATIONS = 10000;
44134
* @param {number} x - input value
45135
* @param {number} loss - starting loss of significance
46136
* @returns {Object} the function value and error
47-
*
48137
*/
49138
function hys2f1( a, b, c, x, loss ) {
50139
var intFlag;
@@ -66,19 +155,19 @@ function hys2f1( a, b, c, x, loss ) {
66155
a = f;
67156
}
68157

69-
if ( isNonPositiveInteger( b ) && abs( b ) < abs( a ) ) {
158+
if ( isNonPositiveInteger( b ) && ( abs( b ) < abs( a ) ) ) {
70159
f = b;
71160
b = a;
72161
a = f;
73162
intFlag = 1;
74163
}
75164

76165
// eslint-disable-next-line max-len
77-
if ( ( ( abs( a ) > abs( c ) + 1 ) || intFlag ) && ( abs( c - a ) > 2 ) && ( abs( a ) > 2 ) ) {
166+
if ( ( ( abs( a ) > abs( c ) + 1.0 ) || intFlag ) && ( abs( c - a ) > 2.0 ) && ( abs( a ) > 2.0 ) ) {
78167
return hyp2f1ra( a, b, c, x, loss );
79168
}
80169

81-
i = 0;
170+
i = 0.0;
82171
umax = 0.0;
83172
f = a;
84173
g = b;
@@ -90,7 +179,10 @@ function hys2f1( a, b, c, x, loss ) {
90179
do {
91180
if ( abs( h ) < EPS ) {
92181
loss = 1.0;
93-
return PINF;
182+
return {
183+
'value': PINF,
184+
'error': loss
185+
};
94186
}
95187
m = k + 1.0;
96188
u *= ( ( f + k ) * ( g + k ) * x / ( ( h + k ) * m ) );
@@ -100,14 +192,17 @@ function hys2f1( a, b, c, x, loss ) {
100192
umax = k;
101193
}
102194
k = m;
103-
i += 1;
195+
i += 1.0;
104196
if ( i > MAX_ITERATIONS ) {
105197
loss = 1.0;
106-
return s;
198+
return {
199+
'value': s,
200+
'error': loss
201+
};
107202
}
108-
} while ( s === 0 || abs( u / s ) > EPS );
203+
} while ( s === 0.0 || abs( u / s ) > MACHEP );
109204

110-
loss = ( ( EPS * umax ) / abs( s ) ) + ( EPS * i );
205+
loss = ( ( MACHEP * umax ) / abs( s ) ) + ( MACHEP * i );
111206
return {
112207
'value': s,
113208
'error': loss

0 commit comments

Comments
 (0)