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 @@ -59,8 +59,8 @@ function skewness( k ) {
return NaN;
}
mu = mean( k );
sigma = sqrt( variance( k ) );
sigma2 = sigma * sigma;
sigma2 = variance( k );
sigma = sqrt( sigma2 );
sigma3 = sigma2 * sigma;
return ( mu / sigma3 ) * ( 1.0 - ( 2.0*sigma2 ) );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ function mean( N, K, n ) {
) {
return NaN;
}
return n * ( K / N );
return ( n * K ) / N;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In principle, this computation has a greater risk of overflow, including just to the realm beyond safe integers. However, practically speaking, that is not a common use case, so I am fine having this match the C implementation.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirmed, and worth pinning down the boundary: the product overflows once n*K exceeds sqrt(MAX_VALUE) ≈ 1.34e154, so mean( 1e160, 1e160, 1e160 ) now returns Infinity where the previous arrangement returned 1e160.

The asymmetry is JS-only. src/main.c takes int32_t, so the C cannot reach that regime at all, whereas the JS guard is isNonNegativeInteger, which accepts 1e300. So this is a case where matching the C narrows the JS domain rather than just reordering within it.

Leaving as-is per your call. Noting the threshold here so it's on the record if anyone later hits it.


Generated by Claude Code

}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ tape( 'the function returns the mean of a hypergeometric distribution', function
n = data.n;
for ( i = 0; i < n.length; i++ ) {
y = mean( N[i], K[i], n[i] );
t.strictEqual( isAlmostSameValue( y, expected[ i ], 1 ), true, 'returns expected value' );
t.strictEqual( isAlmostSameValue( y, expected[ i ], 0 ), true, 'returns expected value' );
}
t.end();
});
Loading