Skip to content

Commit 732af8d

Browse files
committed
feat: add 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 2f54879 commit 732af8d

File tree

2 files changed

+115
-0
lines changed
  • lib/node_modules/@stdlib/stats/base/dists/bradford/median/lib

2 files changed

+115
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2025 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
/**
22+
* Bradford distribution median.
23+
*
24+
* @module @stdlib/stats/base/dists/bradford/median
25+
*
26+
* @example
27+
* var median = require( '@stdlib/stats/base/dists/bradford/median' );
28+
*
29+
* var v = median( 0.1 );
30+
* // returns ~0.488
31+
*
32+
* v = median( 0.5 );
33+
* // returns ~0.449
34+
*/
35+
36+
// MODULES //
37+
38+
var median = require( './main.js' );
39+
40+
41+
// EXPORTS //
42+
43+
module.exports = median;
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2025 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
// MODULES //
22+
23+
var isnan = require( '@stdlib/math/base/assert/is-nan' );
24+
var sqrt = require( '@stdlib/math/base/special/sqrt' );
25+
26+
27+
// MAIN //
28+
29+
/**
30+
* Returns the median of a Bradford distribution.
31+
*
32+
* @param {PositiveNumber} c - shape parameter
33+
* @returns {NonNegativeNumber} median
34+
*
35+
* @example
36+
* var v = median( 0.1 );
37+
* // returns ~0.488
38+
*
39+
* @example
40+
* var v = median( 0.5 );
41+
* // returns ~0.449
42+
*
43+
* @example
44+
* var v = median( 10.0 );
45+
* // returns ~0.232
46+
*
47+
* @example
48+
* var v = median( 0.0 );
49+
* // returns NaN
50+
*
51+
* @example
52+
* var v = median( -1.0 );
53+
* // returns NaN
54+
*
55+
* @example
56+
* var v = median( NaN );
57+
* // returns NaN
58+
*/
59+
function median( c ) {
60+
if (
61+
isnan( c ) ||
62+
c <= 0.0
63+
) {
64+
return NaN;
65+
}
66+
return ( sqrt( 1.0 + c ) - 1.0 ) / c;
67+
}
68+
69+
70+
// EXPORTS //
71+
72+
module.exports = median;

0 commit comments

Comments
 (0)