Skip to content

Commit 9ff045a

Browse files
committed
fix: improve parameter validation and style in binomial/logpmf
- Fix integer comparisons in edge cases (x == 0 instead of x == 0.0) - Improve parameter validation logic for cleaner code flow - Fix JSDoc example to use integer (3 instead of 3.0) - Maintain correct int32_t types for discrete parameters x and n --- type: pre_push_report description: Results of running various checks prior to pushing changes. report: - task: run_javascript_examples status: na - task: run_c_examples status: na - task: run_cpp_examples status: na - task: run_javascript_readme_examples status: na - task: run_c_benchmarks status: na - task: run_cpp_benchmarks status: na - task: run_fortran_benchmarks status: na - task: run_javascript_benchmarks status: na - task: run_julia_benchmarks status: na - task: run_python_benchmarks status: na - task: run_r_benchmarks status: na - task: run_javascript_tests status: na --- --- type: pre_push_report description: Results of running various checks prior to pushing changes. report: - task: run_javascript_examples status: na - task: run_c_examples status: na - task: run_cpp_examples status: na - task: run_javascript_readme_examples status: na - task: run_c_benchmarks status: na - task: run_cpp_benchmarks status: na - task: run_fortran_benchmarks status: na - task: run_javascript_benchmarks status: na - task: run_julia_benchmarks status: na - task: run_python_benchmarks status: na - task: run_r_benchmarks status: na - task: run_javascript_tests status: na --- --- type: pre_push_report description: Results of running various checks prior to pushing changes. report: - task: run_javascript_examples status: na - task: run_c_examples status: na - task: run_cpp_examples status: na - task: run_javascript_readme_examples status: na - task: run_c_benchmarks status: na - task: run_cpp_benchmarks status: na - task: run_fortran_benchmarks status: na - task: run_javascript_benchmarks status: na - task: run_julia_benchmarks status: na - task: run_python_benchmarks status: na - task: run_r_benchmarks status: na - task: run_javascript_tests status: na ---
1 parent 19edc09 commit 9ff045a

File tree

2 files changed

+13
-15
lines changed
  • lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf

2 files changed

+13
-15
lines changed

lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/include/stdlib/stats/base/dists/binomial/logpmf.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
#include <stdint.h>
2323

24+
2425
/*
2526
* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler.
2627
*/

lib/node_modules/@stdlib/stats/base/dists/binomial/logpmf/src/main.c

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
* @return evaluated logPMF
3636
*
3737
* @example
38-
* double y = stdlib_base_dists_binomial_logpmf( 3.0, 20, 0.2 );
38+
* double y = stdlib_base_dists_binomial_logpmf( 3, 20, 0.2 );
3939
* // returns ~-1.583
4040
*/
4141
double stdlib_base_dists_binomial_logpmf( const int32_t x, const int32_t n, const double p ) {
@@ -47,19 +47,16 @@ double stdlib_base_dists_binomial_logpmf( const int32_t x, const int32_t n, cons
4747
) {
4848
return 0.0 / 0.0;
4949
}
50-
if ( x >= 0 ){
51-
if ( x > n ) {
52-
return STDLIB_CONSTANT_FLOAT64_NINF;
53-
}
54-
if ( p == 0.0 ) {
55-
return ( x == 0.0 ) ? 0.0 : STDLIB_CONSTANT_FLOAT64_NINF;
56-
}
57-
if ( p == 1.0 ) {
58-
return ( x == n ) ? 0.0 : STDLIB_CONSTANT_FLOAT64_NINF;
59-
}
60-
double out = stdlib_base_binomcoefln( n, x );
61-
out += ( x * stdlib_base_ln( p ) ) + ( ( n - x ) * stdlib_base_log1p( -p ) );
62-
return out;
50+
if ( x < 0 || x > n ) {
51+
return STDLIB_CONSTANT_FLOAT64_NINF;
6352
}
64-
return STDLIB_CONSTANT_FLOAT64_NINF;
53+
if ( p == 0.0 ) {
54+
return ( x == 0 ) ? 0.0 : STDLIB_CONSTANT_FLOAT64_NINF;
55+
}
56+
if ( p == 1.0 ) {
57+
return ( x == n ) ? 0.0 : STDLIB_CONSTANT_FLOAT64_NINF;
58+
}
59+
double out = stdlib_base_binomcoefln( n, x );
60+
out += ( x * stdlib_base_ln( p ) ) + ( ( n - x ) * stdlib_base_log1p( -p ) );
61+
return out;
6562
}

0 commit comments

Comments
 (0)