Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
// MODULES //

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

Expand All @@ -40,7 +39,11 @@ var exp = require( '@stdlib/math/base/special/exp' );
* // returns ~0.855
*/
function factory( p ) {
if ( !isProbability( p ) ) {
if (
isnan( p ) ||
p < 0.0 ||
p > 1.0
) {
return constantFunction( NaN );
}
return mgf;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

// MODULES //

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

Expand Down Expand Up @@ -59,7 +58,12 @@ var exp = require( '@stdlib/math/base/special/exp' );
* // returns NaN
*/
function mgf( t, p ) {
if ( isnan( t ) || !isProbability( p ) ) {
if (
isnan( t ) ||
isnan( p ) ||
p < 0.0 ||
p > 1.0
) {
return NaN;
}
return ( 1.0-p ) + ( p * exp( t ) );
Expand Down