Skip to content

Commit da9818a

Browse files
committed
Use constantFunction, consolidate conditionals, and add empty lines
1 parent 6b75679 commit da9818a

3 files changed

Lines changed: 15 additions & 33 deletions

File tree

lib/node_modules/@stdlib/math/base/dist/laplace/mgf/lib/factory.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
// MODULES //
44

5+
var constantFunction = require( '@stdlib/utils/constant-function' );
56
var isnan = require( '@stdlib/math/base/assert/is-nan' );
67
var abs = require( '@stdlib/math/base/special/abs' );
78
var exp = require( '@stdlib/math/base/special/exp' );
89
var pow = require( '@stdlib/math/base/special/pow' );
9-
var nan = require( './nan.js' );
1010

1111

1212
// MAIN //
@@ -28,11 +28,8 @@ var nan = require( './nan.js' );
2828
* // returns ~13.758
2929
*/
3030
function factory( mu, b ) {
31-
if ( isnan( mu ) || isnan( b ) ) {
32-
return nan;
33-
}
34-
if ( b <= 0.0 ) {
35-
return nan;
31+
if ( isnan( mu ) || isnan( b ) || b <= 0.0 ) {
32+
return constantFunction( NaN );
3633
}
3734
return mgf;
3835

lib/node_modules/@stdlib/math/base/dist/laplace/mgf/lib/mgf.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,30 +21,39 @@ var pow = require( '@stdlib/math/base/special/pow' );
2121
* @example
2222
* var y = mgf( 0.5, 0.0, 1.0 );
2323
* // returns ~1.333
24+
*
2425
* @example
2526
* var y = mgf( 0.0, 0.0, 1.0 );
2627
* // returns 1.0
28+
*
2729
* @example
2830
* var y = mgf( -1.0, 4.0, 0.2 );
2931
* // returns ~0.019
32+
*
3033
* @example
3134
* var y = mgf( NaN, 0.0, 1.0 );
3235
* // returns NaN
36+
*
3337
* @example
3438
* var y = mgf( 0.0, NaN, 1.0 );
3539
* // returns NaN
40+
*
3641
* @example
3742
* var y = mgf( 0.0, 0.0, NaN );
3843
* // returns NaN
44+
*
3945
* @example
4046
* var y = mgf( 1.0, 0.0, 2.0 );
4147
* // returns NaN
48+
*
4249
* @example
4350
* var y = mgf( -0.5, 0.0, 4.0 );
4451
* // returns NaN
52+
*
4553
* @example
4654
* var y = mgf( 2.0, 0.0, 0.0 );
4755
* // returns NaN
56+
*
4857
* @example
4958
* var y = mgf( 2.0, 0.0, -1.0 );
5059
* // returns NaN
@@ -54,16 +63,12 @@ function mgf( t, mu, b ) {
5463
if (
5564
isnan( t ) ||
5665
isnan( mu ) ||
57-
isnan( b )
66+
isnan( b ) ||
67+
b <= 0.0 ||
68+
abs( t ) >= 1.0/b
5869
) {
5970
return NaN;
6071
}
61-
if ( b <= 0.0 ) {
62-
return NaN;
63-
}
64-
if ( abs( t ) >= 1.0/b ) {
65-
return NaN;
66-
}
6772
bt = b * t;
6873
return exp( mu * t ) / ( 1.0 - pow( bt, 2.0 ) );
6974
} // end FUNCTION mgf()

lib/node_modules/@stdlib/math/base/dist/laplace/mgf/lib/nan.js

Lines changed: 0 additions & 20 deletions
This file was deleted.

0 commit comments

Comments
 (0)