Skip to content

Commit 0e4d771

Browse files
Planeshifterclaude
andcommitted
fix: correct C implementation behavior for t-distribution variance
- Fix C implementation to return Infinity for 1 < v <= 2 (was incorrectly returning NaN) - Update native tests to match expected behavior from JavaScript implementation - Both implementations now properly handle edge cases: NaN for v <= 1, Infinity for 1 < v <= 2 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 2541f56 commit 0e4d771

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

lib/node_modules/@stdlib/stats/base/dists/t/variance/src/main.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,11 @@
2929
* // returns 1.667
3030
*/
3131
double stdlib_base_dists_t_variance( const double v ) {
32-
if ( stdlib_base_is_nan( v ) || v <= 2.0 ) {
32+
if ( stdlib_base_is_nan( v ) || v <= 1.0 ) {
3333
return 0.0 / 0.0; // NaN
3434
}
35+
if ( v <= 2.0 ) {
36+
return 1.0 / 0.0; // Infinity
37+
}
3538
return v / ( v - 2.0 );
3639
}

lib/node_modules/@stdlib/stats/base/dists/t/variance/test/test.native.js

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,9 @@ tape( 'if provided `NaN` for the parameter, the function returns `NaN`', opts, f
5555
t.end();
5656
});
5757

58-
tape( 'if provided `v <= 2`, the function returns `NaN`', opts, function test( t ) {
58+
tape( 'if provided `v <= 1`, the function returns `NaN`', opts, function test( t ) {
5959
var y;
6060

61-
y = variance( 2.0 );
62-
t.equal( isnan( y ), true, 'returns NaN' );
63-
6461
y = variance( 1.0 );
6562
t.equal( isnan( y ), true, 'returns NaN' );
6663

@@ -73,6 +70,22 @@ tape( 'if provided `v <= 2`, the function returns `NaN`', opts, function test( t
7370
t.end();
7471
});
7572

73+
tape( 'if provided `1 < v <= 2`, the function returns `Infinity`', opts, function test( t ) {
74+
var PINF = require( '@stdlib/constants/float64/pinf' );
75+
var y;
76+
77+
y = variance( 2.0 );
78+
t.equal( y, PINF, 'returns Infinity' );
79+
80+
y = variance( 1.5 );
81+
t.equal( y, PINF, 'returns Infinity' );
82+
83+
y = variance( 1.1 );
84+
t.equal( y, PINF, 'returns Infinity' );
85+
86+
t.end();
87+
});
88+
7689
tape( 'the function evaluates the variance for a Student\'s t-distribution', opts, function test( t ) {
7790
var expected;
7891
var delta;

0 commit comments

Comments
 (0)