Skip to content

Commit e7eae81

Browse files
committed
refactor: precompute constant and adjust tolerance
--- 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: passed - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: passed - 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 c4ef550 commit e7eae81

File tree

5 files changed

+9
-19
lines changed

5 files changed

+9
-19
lines changed

lib/node_modules/@stdlib/stats/base/dists/gumbel/stdev/lib/main.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,11 @@
2121
// MODULES //
2222

2323
var isnan = require( '@stdlib/math/base/assert/is-nan' );
24-
var sqrt = require( '@stdlib/math/base/special/sqrt' );
25-
var PI = require( '@stdlib/constants/float64/pi' );
2624

2725

2826
// VARIABLES //
2927

30-
var SQRT6 = sqrt( 6.0 );
28+
var PI_OVER_SQRT6 = 1.282549830161864; // Pi divided by the square root of 6
3129

3230

3331
// MAIN //
@@ -67,7 +65,7 @@ function stdev( mu, beta ) {
6765
) {
6866
return NaN;
6967
}
70-
return ( PI / SQRT6 ) * beta;
68+
return PI_OVER_SQRT6 * beta;
7169
}
7270

7371

lib/node_modules/@stdlib/stats/base/dists/gumbel/stdev/manifest.json

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,7 @@
3939
"libpath": [],
4040
"dependencies": [
4141
"@stdlib/math/base/napi/binary",
42-
"@stdlib/math/base/assert/is-nan",
43-
"@stdlib/math/base/special/sqrt",
44-
"@stdlib/constants/float64/pi"
42+
"@stdlib/math/base/assert/is-nan"
4543
]
4644
},
4745
{
@@ -57,8 +55,6 @@
5755
"libpath": [],
5856
"dependencies": [
5957
"@stdlib/math/base/assert/is-nan",
60-
"@stdlib/math/base/special/sqrt",
61-
"@stdlib/constants/float64/pi",
6258
"@stdlib/constants/float64/eps"
6359
]
6460
},
@@ -74,9 +70,7 @@
7470
"libraries": [],
7571
"libpath": [],
7672
"dependencies": [
77-
"@stdlib/math/base/assert/is-nan",
78-
"@stdlib/math/base/special/sqrt",
79-
"@stdlib/constants/float64/pi"
73+
"@stdlib/math/base/assert/is-nan"
8074
]
8175
}
8276
]

lib/node_modules/@stdlib/stats/base/dists/gumbel/stdev/src/main.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818

1919
#include "stdlib/stats/base/dists/gumbel/stdev.h"
2020
#include "stdlib/math/base/assert/is_nan.h"
21-
#include "stdlib/math/base/special/sqrt.h"
22-
#include "stdlib/constants/float64/pi.h"
21+
22+
static const double PI_OVER_SQRT6 = 1.282549830161864; // Pi divided by the square root of 6
2323

2424
/**
2525
* Returns the standard deviation for a Gumbel distribution with location `mu` and scale `beta`.
@@ -33,14 +33,12 @@
3333
* // returns ~1.283
3434
*/
3535
double stdlib_base_dists_gumbel_stdev( const double mu, const double beta ) {
36-
double SQRT6 = stdlib_base_sqrt( 6.0 );
37-
3836
if (
3937
stdlib_base_is_nan( mu ) ||
4038
stdlib_base_is_nan( beta ) ||
4139
beta <= 0.0
4240
) {
4341
return 0.0/0.0; // NaN
4442
}
45-
return ( STDLIB_CONSTANT_FLOAT64_PI / SQRT6 ) * beta;
43+
return PI_OVER_SQRT6 * beta;
4644
}

lib/node_modules/@stdlib/stats/base/dists/gumbel/stdev/test/test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ tape( 'the function returns the standard deviation of a Gumbel distribution', fu
9696
t.equal( y, expected[i], 'mu:'+mu[i]+', beta: '+beta[i]+', y: '+y+', expected: '+expected[i] );
9797
} else {
9898
delta = abs( y - expected[ i ] );
99-
tol = 2.0 * EPS * abs( expected[ i ] );
99+
tol = 1.0 * EPS * abs( expected[ i ] );
100100
t.ok( delta <= tol, 'within tolerance. mu: '+mu[i]+'. beta: '+beta[i]+'. y: '+y+'. E: '+expected[ i ]+'. Δ: '+delta+'. tol: '+tol+'.' );
101101
}
102102
}

lib/node_modules/@stdlib/stats/base/dists/gumbel/stdev/test/test.native.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ tape( 'the function returns the standard deviation of a Gumbel distribution', op
105105
t.equal( y, expected[i], 'mu:'+mu[i]+', beta: '+beta[i]+', y: '+y+', expected: '+expected[i] );
106106
} else {
107107
delta = abs( y - expected[ i ] );
108-
tol = 2.0 * EPS * abs( expected[ i ] );
108+
tol = 1.0 * EPS * abs( expected[ i ] );
109109
t.ok( delta <= tol, 'within tolerance. mu: '+mu[i]+'. beta: '+beta[i]+'. y: '+y+'. E: '+expected[ i ]+'. Δ: '+delta+'. tol: '+tol+'.' );
110110
}
111111
}

0 commit comments

Comments
 (0)