Skip to content
Open
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 @@ -64,6 +64,9 @@ var y = mgf( 2.0, 0.0, 3.0 );
y = mgf( 0.5, 0.0, 1.0 );
// returns ~1.016

y = mgf( 0.0, 2.0, 5.0 );
// returns 1.0

y = mgf( -1.0, 4.0, 2.0 );
// returns ~0.024
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ function factory( mu, s ) {
return NaN;
}
st = s * t;
if ( st === 0.0 ) {
return 1.0;
}
out = PI_SQUARED * sinh( st );
out /= st * ( PI_SQUARED + ( st*st ) );
out *= exp( mu * t );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ var PI_SQUARED = require( '@stdlib/constants/float64/pi-squared' );
* // returns ~1.016
*
* @example
* var y = mgf( 0.0, 2.0, 5.0 );
* // returns 1.0
*
* @example
* var y = mgf( 1.2, 0.0, 1.0 );
* // returns ~1.098
*
Expand Down Expand Up @@ -72,6 +76,9 @@ function mgf( t, mu, s ) {
return NaN;
}
st = s * t;
if ( st === 0.0 ) {
return 1.0;
}
out = PI_SQUARED * sinh( st );
out /= st * ( PI_SQUARED + ( st*st ) );
out *= exp( mu * t );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ double stdlib_base_dists_cosine_mgf( const double t, const double mu, const doub
) {
return 0.0/0.0; // NaN
}
if ( t == 0.0 ) {
return 1.0;
}
const double st = s*t;
double out = STDLIB_CONSTANT_FLOAT64_PI_SQUARED * stdlib_base_sinh( st );
out /= st * ( STDLIB_CONSTANT_FLOAT64_PI_SQUARED + ( st*st ) );
Expand Down
Loading