Skip to content

Commit 3c1e93d

Browse files
authored
refactor: replace isProbability with inline range check in stats/base/dists/bernoulli/mgf
PR-URL: #12292 Reviewed-by: Athan Reines <kgryte@gmail.com>
1 parent 6bf10af commit 3c1e93d

2 files changed

Lines changed: 11 additions & 4 deletions

File tree

lib/node_modules/@stdlib/stats/base/dists/bernoulli/mgf/lib/factory.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
// MODULES //
2222

2323
var constantFunction = require( '@stdlib/utils/constant-function' );
24-
var isProbability = require( '@stdlib/math/base/assert/is-probability' );
2524
var isnan = require( '@stdlib/math/base/assert/is-nan' );
2625
var exp = require( '@stdlib/math/base/special/exp' );
2726

@@ -40,7 +39,11 @@ var exp = require( '@stdlib/math/base/special/exp' );
4039
* // returns ~0.855
4140
*/
4241
function factory( p ) {
43-
if ( !isProbability( p ) ) {
42+
if (
43+
isnan( p ) ||
44+
p < 0.0 ||
45+
p > 1.0
46+
) {
4447
return constantFunction( NaN );
4548
}
4649
return mgf;

lib/node_modules/@stdlib/stats/base/dists/bernoulli/mgf/lib/main.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020

2121
// MODULES //
2222

23-
var isProbability = require( '@stdlib/math/base/assert/is-probability' );
2423
var isnan = require( '@stdlib/math/base/assert/is-nan' );
2524
var exp = require( '@stdlib/math/base/special/exp' );
2625

@@ -59,7 +58,12 @@ var exp = require( '@stdlib/math/base/special/exp' );
5958
* // returns NaN
6059
*/
6160
function mgf( t, p ) {
62-
if ( isnan( t ) || !isProbability( p ) ) {
61+
if (
62+
isnan( t ) ||
63+
isnan( p ) ||
64+
p < 0.0 ||
65+
p > 1.0
66+
) {
6367
return NaN;
6468
}
6569
return ( 1.0-p ) + ( p * exp( t ) );

0 commit comments

Comments
 (0)