Skip to content

Commit 1a0d851

Browse files
committed
refactor: precompute constant
--- 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: 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 e7eae81 commit 1a0d851

File tree

3 files changed

+12
-15
lines changed

3 files changed

+12
-15
lines changed

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +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_SQUARED = require( '@stdlib/constants/float64/pi-squared' );
24+
25+
26+
// VARIABLES //
27+
28+
var STDEV_CONST = 0.36151205519132795; // sqrt( (1/3) - (2/π²) )
2629

2730

2831
// MAIN //
@@ -62,7 +65,7 @@ function stdev( mu, s ) {
6265
) {
6366
return NaN;
6467
}
65-
return s * sqrt( ( 1.0/3.0 ) - ( 2/PI_SQUARED ) );
68+
return s * STDEV_CONST;
6669
}
6770

6871

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

Lines changed: 3 additions & 9 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-squared"
42+
"@stdlib/math/base/assert/is-nan"
4543
]
4644
},
4745
{
@@ -57,9 +55,7 @@
5755
"libpath": [],
5856
"dependencies": [
5957
"@stdlib/math/base/assert/is-nan",
60-
"@stdlib/constants/float64/eps",
61-
"@stdlib/math/base/special/sqrt",
62-
"@stdlib/constants/float64/pi-squared"
58+
"@stdlib/constants/float64/eps"
6359
]
6460
},
6561
{
@@ -75,9 +71,7 @@
7571
"libpath": [],
7672
"dependencies": [
7773
"@stdlib/math/base/assert/is-nan",
78-
"@stdlib/constants/float64/eps",
79-
"@stdlib/math/base/special/sqrt",
80-
"@stdlib/constants/float64/pi-squared"
74+
"@stdlib/constants/float64/eps"
8175
]
8276
}
8377
]

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

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

1919
#include "stdlib/stats/base/dists/cosine/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_squared.h"
21+
22+
static const double STDLIB_COSINE_STDEV_CONST = 0.36151205519132795; // sqrt( (1/3) - (2/π²) )
2323

2424
/**
2525
* Returns the standard deviation for a raised cosine distribution with location `mu` and scale `s`.
@@ -40,5 +40,5 @@ double stdlib_base_dists_cosine_stdev( const double mu, const double s ) {
4040
) {
4141
return 0.0/0.0; // NaN
4242
}
43-
return s * stdlib_base_sqrt( ( 1.0/3.0 ) - ( 2/STDLIB_CONSTANT_FLOAT64_PI_SQUARED ) );
43+
return s * STDLIB_COSINE_STDEV_CONST;
4444
}

0 commit comments

Comments
 (0)