Skip to content

Commit 1dc536d

Browse files
committed
refactor: pre-calculate 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: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed ---
1 parent 794dd4a commit 1dc536d

File tree

3 files changed

+28
-10
lines changed

3 files changed

+28
-10
lines changed

lib/node_modules/@stdlib/stats/base/dists/halfnormal/kurtosis/lib/main.js

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,23 +20,43 @@
2020

2121
// MODULES //
2222

23-
var PI = require( '@stdlib/constants/float64/pi' );
2423
var isnan = require( '@stdlib/math/base/assert/is-nan' );
2524

2625

26+
// VARIABLES //
27+
28+
var KURTOSIS = 0.8691773036059736; // 8*(π-3) / (π-2)²
29+
30+
2731
// MAIN //
2832

2933
/**
3034
* Returns the excess kurtosis of a half-normal distribution.
3135
*
3236
* @param {PositiveNumber} sigma - scale parameter
3337
* @returns {number} excess kurtosis
38+
*
39+
* @example
40+
* var y = kurtosis( 1.0 );
41+
* // returns ~0.869
42+
*
43+
* @example
44+
* var y = kurtosis( 4.0 );
45+
* // returns ~0.869
46+
*
47+
* @example
48+
* var y = kurtosis( NaN );
49+
* // returns NaN
50+
*
51+
* @example
52+
* var y = kurtosis( 0.0 );
53+
* // returns NaN
3454
*/
3555
function kurtosis( sigma ) {
3656
if ( isnan( sigma ) || sigma <= 0.0 ) {
3757
return NaN;
3858
}
39-
return ( 8.0 * ( PI - 3.0 ) ) / ( ( PI - 2.0 ) * ( PI - 2.0 ) );
59+
return KURTOSIS;
4060
}
4161

4262

lib/node_modules/@stdlib/stats/base/dists/halfnormal/kurtosis/manifest.json

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@
3939
"libpath": [],
4040
"dependencies": [
4141
"@stdlib/math/base/napi/unary",
42-
"@stdlib/math/base/assert/is-nan",
43-
"@stdlib/constants/float64/pi"
42+
"@stdlib/math/base/assert/is-nan"
4443
]
4544
},
4645
{
@@ -55,8 +54,7 @@
5554
"libraries": [],
5655
"libpath": [],
5756
"dependencies": [
58-
"@stdlib/math/base/assert/is-nan",
59-
"@stdlib/constants/float64/pi"
57+
"@stdlib/math/base/assert/is-nan"
6058
]
6159
},
6260
{
@@ -71,8 +69,7 @@
7169
"libraries": [],
7270
"libpath": [],
7371
"dependencies": [
74-
"@stdlib/math/base/assert/is-nan",
75-
"@stdlib/constants/float64/pi"
72+
"@stdlib/math/base/assert/is-nan"
7673
]
7774
}
7875
]

lib/node_modules/@stdlib/stats/base/dists/halfnormal/kurtosis/src/main.c

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

1919
#include "stdlib/stats/base/dists/halfnormal/kurtosis.h"
2020
#include "stdlib/math/base/assert/is_nan.h"
21-
#include "stdlib/constants/float64/pi.h"
21+
22+
static const double KURTOSIS = 0.8691773036059736; // 8*(π-3) / (π-2)²
2223

2324
/**
2425
* Returns the excess kurtosis of a half-normal distribution with scale parameter `sigma`.
@@ -37,5 +38,5 @@ double stdlib_base_dists_halfnormal_kurtosis( const double sigma ) {
3738
) {
3839
return 0.0 / 0.0; // NaN
3940
}
40-
return ( 8.0 * ( STDLIB_CONSTANT_FLOAT64_PI - 3.0 ) ) / ( ( STDLIB_CONSTANT_FLOAT64_PI - 2.0 ) * ( STDLIB_CONSTANT_FLOAT64_PI - 2.0 ) );
41+
return KURTOSIS;
4142
}

0 commit comments

Comments
 (0)