Skip to content

Commit 5f9232b

Browse files
committed
Fix NaN handling
1 parent 9e5dc9d commit 5f9232b

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

lib/node_modules/@stdlib/stats/incr/mstdev/lib/main.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ function incrmstdev( W, mean ) {
112112
return null;
113113
}
114114
if ( N === 1 ) {
115-
return 0.0;
115+
return ( isnan( M2 ) ) ? NaN : 0.0;
116116
}
117117
if ( N < W ) {
118118
return sqrt( M2 / (N-1) );

lib/node_modules/@stdlib/stats/incr/mstdev/test/test.js

+4
Original file line numberDiff line numberDiff line change
@@ -355,8 +355,10 @@ tape( 'if provided `NaN`, the accumulated value is `NaN` for at least `W` invoca
355355
v = acc( data[ i ] );
356356
if ( isnan( expected[ i ] ) ) {
357357
t.equal( isnan( v ), true, 'returns expected value for window '+i );
358+
t.equal( isnan( acc() ), true, 'returns expected value for window '+i );
358359
} else {
359360
t.equal( v, expected[ i ], 'returns expected value for window '+i );
361+
t.equal( acc(), expected[ i ], 'returns expected value for window '+i );
360362
}
361363
}
362364
t.end();
@@ -417,8 +419,10 @@ tape( 'if provided `NaN`, the accumulated value is `NaN` for at least `W` invoca
417419
v = acc( data[ i ] );
418420
if ( isnan( expected[ i ] ) ) {
419421
t.equal( isnan( v ), true, 'returns expected value for window '+i );
422+
t.equal( isnan( acc() ), true, 'returns expected value for window '+i );
420423
} else {
421424
t.equal( v, expected[ i ], 'returns expected value for window '+i );
425+
t.equal( acc(), expected[ i ], 'returns expected value for window '+i );
422426
}
423427
}
424428
t.end();

0 commit comments

Comments
 (0)