Skip to content

Commit b0790e4

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: 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 7403869 commit b0790e4

File tree

5 files changed

+14
-43
lines changed

5 files changed

+14
-43
lines changed

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

Lines changed: 6 additions & 6 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 pow = require( '@stdlib/math/base/special/pow' );
25-
var PI_SQUARED = require( '@stdlib/constants/float64/pi-squared' );
24+
25+
26+
// VARIABLES //
27+
28+
var COSINE_EXCESS_KURTOSIS = -0.5937628755982794; // 6(90-π^4)/(5(π^4-6)^2)
2629

2730

2831
// MAIN //
@@ -55,17 +58,14 @@ var PI_SQUARED = require( '@stdlib/constants/float64/pi-squared' );
5558
* // returns NaN
5659
*/
5760
function kurtosis( mu, s ) {
58-
var out;
5961
if (
6062
isnan( mu ) ||
6163
isnan( s ) ||
6264
s <= 0.0
6365
) {
6466
return NaN;
6567
}
66-
out = 6.0 * ( 90.0 - ( PI_SQUARED*PI_SQUARED ) );
67-
out /= 5.0 * pow( PI_SQUARED-6.0, 2.0 );
68-
return out;
68+
return COSINE_EXCESS_KURTOSIS;
6969
}
7070

7171

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

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,7 @@
3939
"libpath": [],
4040
"dependencies": [
4141
"@stdlib/math/base/napi/binary",
42-
"@stdlib/math/base/assert/is-nan",
43-
"@stdlib/constants/float64/eps",
44-
"@stdlib/math/base/special/pow",
45-
"@stdlib/constants/float64/pi-squared"
42+
"@stdlib/math/base/assert/is-nan"
4643
]
4744
},
4845
{
@@ -58,9 +55,7 @@
5855
"libpath": [],
5956
"dependencies": [
6057
"@stdlib/math/base/assert/is-nan",
61-
"@stdlib/constants/float64/eps",
62-
"@stdlib/math/base/special/pow",
63-
"@stdlib/constants/float64/pi-squared"
58+
"@stdlib/constants/float64/eps"
6459
]
6560
},
6661
{
@@ -76,9 +71,7 @@
7671
"libpath": [],
7772
"dependencies": [
7873
"@stdlib/math/base/assert/is-nan",
79-
"@stdlib/constants/float64/eps",
80-
"@stdlib/math/base/special/pow",
81-
"@stdlib/constants/float64/pi-squared"
74+
"@stdlib/constants/float64/eps"
8275
]
8376
}
8477
]

lib/node_modules/@stdlib/stats/base/dists/cosine/kurtosis/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/cosine/kurtosis.h"
2020
#include "stdlib/math/base/assert/is_nan.h"
21-
#include "stdlib/math/base/special/pow.h"
22-
#include "stdlib/constants/float64/pi_squared.h"
21+
22+
static const double COSINE_EXCESS_KURTOSIS = -0.5937628755982794; // 6(90-π^4)/(5(π^4-6)^2)
2323

2424
/**
2525
* Returns the excess kurtosis of a raised cosine distribution.
@@ -40,7 +40,5 @@ double stdlib_base_dists_cosine_kurtosis( const double mu, const double s ) {
4040
) {
4141
return 0.0/0.0; // NaN
4242
}
43-
double out = 6.0 * ( 90.0 - ( STDLIB_CONSTANT_FLOAT64_PI_SQUARED*STDLIB_CONSTANT_FLOAT64_PI_SQUARED ) );
44-
out /= 5.0 * stdlib_base_pow( STDLIB_CONSTANT_FLOAT64_PI_SQUARED-6.0, 2.0 );
45-
return out;
43+
return COSINE_EXCESS_KURTOSIS;
4644
}

lib/node_modules/@stdlib/stats/base/dists/cosine/kurtosis/test/test.js

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,8 @@
2222

2323
var tape = require( 'tape' );
2424
var isnan = require( '@stdlib/math/base/assert/is-nan' );
25-
var abs = require( '@stdlib/math/base/special/abs' );
2625
var PINF = require( '@stdlib/constants/float64/pinf' );
2726
var NINF = require( '@stdlib/constants/float64/ninf' );
28-
var EPS = require( '@stdlib/constants/float64/eps' );
2927
var kurtosis = require( './../lib' );
3028

3129

@@ -79,8 +77,6 @@ tape( 'if provided a nonpositive `s`, the function returns `NaN`', function test
7977

8078
tape( 'the function returns the excess kurtosis of a raised cosine distribution', function test( t ) {
8179
var expected;
82-
var delta;
83-
var tol;
8480
var mu;
8581
var s;
8682
var y;
@@ -92,13 +88,7 @@ tape( 'the function returns the excess kurtosis of a raised cosine distribution'
9288
for ( i = 0; i < mu.length; i++ ) {
9389
y = kurtosis( mu[i], s[i] );
9490
if ( expected[i] !== null ) {
95-
if ( y === expected[i] ) {
96-
t.equal( y, expected[i], 'mu:'+mu[i]+', s: '+s[i]+', y: '+y+', expected: '+expected[i] );
97-
} else {
98-
delta = abs( y - expected[ i ] );
99-
tol = 10.0 * EPS * abs( expected[ i ] );
100-
t.ok( delta <= tol, 'within tolerance. mu: '+mu[i]+'. s: '+s[i]+'. y: '+y+'. E: '+expected[ i ]+'. Δ: '+delta+'. tol: '+tol+'.' );
101-
}
91+
t.equal( y, expected[i], 'mu:'+mu[i]+', s: '+s[i]+', y: '+y+', expected: '+expected[i] );
10292
}
10393
}
10494
t.end();

lib/node_modules/@stdlib/stats/base/dists/cosine/kurtosis/test/test.native.js

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,8 @@
2323
var resolve = require( 'path' ).resolve;
2424
var tape = require( 'tape' );
2525
var isnan = require( '@stdlib/math/base/assert/is-nan' );
26-
var abs = require( '@stdlib/math/base/special/abs' );
2726
var PINF = require( '@stdlib/constants/float64/pinf' );
2827
var NINF = require( '@stdlib/constants/float64/ninf' );
29-
var EPS = require( '@stdlib/constants/float64/eps' );
3028
var tryRequire = require( '@stdlib/utils/try-require' );
3129

3230

@@ -88,8 +86,6 @@ tape( 'if provided a nonpositive `s`, the function returns `NaN`', opts, functio
8886

8987
tape( 'the function returns the excess kurtosis of a raised cosine distribution', opts, function test( t ) {
9088
var expected;
91-
var delta;
92-
var tol;
9389
var mu;
9490
var s;
9591
var y;
@@ -101,13 +97,7 @@ tape( 'the function returns the excess kurtosis of a raised cosine distribution'
10197
for ( i = 0; i < mu.length; i++ ) {
10298
y = kurtosis( mu[i], s[i] );
10399
if ( expected[i] !== null ) {
104-
if ( y === expected[i] ) {
105-
t.equal( y, expected[i], 'mu:'+mu[i]+', s: '+s[i]+', y: '+y+', expected: '+expected[i] );
106-
} else {
107-
delta = abs( y - expected[ i ] );
108-
tol = 10.0 * EPS * abs( expected[ i ] );
109-
t.ok( delta <= tol, 'within tolerance. mu: '+mu[i]+'. s: '+s[i]+'. y: '+y+'. E: '+expected[ i ]+'. Δ: '+delta+'. tol: '+tol+'.' );
110-
}
100+
t.equal( y, expected[i], 'mu:'+mu[i]+', s: '+s[i]+', y: '+y+', expected: '+expected[i] );
111101
}
112102
}
113103
t.end();

0 commit comments

Comments
 (0)