Skip to content
Draft
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 @@ -88,16 +88,21 @@ function factory( r, p ) {
if ( isnan( k ) || k < 0.0 || k > 1.0 ) {
return NaN;
}
if ( p === 1.0 ) {
return 0.0;
}
if ( k === 0.0 ) {
return 0.0;
}
if ( k === 1.0 ) {
return PINF;
}

// If the mean overflows double-precision floating-point format, the sought quantile saturates at positive infinity:
if ( mu === PINF ) {
return PINF;
}

// Cornish-Fisher expansion:
if ( k < 0.5 ) {
x = -erfcinv( 2.0 * k ) * SQRT2;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ function quantile( k, r, p ) {
) {
return NaN;
}
if ( p === 1.0 ) {
return 0.0;
}
if ( k === 0.0 ) {
return 0.0;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ double stdlib_base_dists_negative_binomial_quantile( const double k, const doubl
) {
return 0.0 / 0.0; // NaN
}
if ( p == 1.0 ) {
return 0.0;
}
if ( k == 0.0 ) {
return 0.0;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,21 @@ tape( 'if provided a success probability `p` equal to `0`, the created function
t.end();
});

tape( 'if provided a success probability `p` equal to `1`, the created function always returns `0`', function test( t ) {
var quantile;
var y;

quantile = factory( 20.0, 1.0 );

y = quantile( 0.5 );
t.strictEqual( y, 0.0, 'returns expected value' );

y = quantile( 0.9 );
t.strictEqual( y, 0.0, 'returns expected value' );

t.end();
});

tape( 'if the distribution mean overflows double-precision floating-point format, the created function returns `+infinity`', function test( t ) {
var quantile;
var y;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,18 @@ tape( 'if provided a success probability `p` equal to `0`, the function returns
t.end();
});

tape( 'if provided a success probability `p` equal to `1`, the function returns `0`', function test( t ) {
var y;

y = quantile( 0.5, 20, 1.0 );
t.strictEqual( y, 0.0, 'returns expected value' );

y = quantile( 0.9, 10, 1.0 );
t.strictEqual( y, 0.0, 'returns expected value' );

t.end();
});

tape( 'if the distribution mean overflows double-precision floating-point format, the function returns `+infinity`', function test( t ) {
var y;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,18 @@ tape( 'if provided a success probability `p` equal to `0`, the function returns
t.end();
});

tape( 'if provided a success probability `p` equal to `1`, the function returns `0`', opts, function test( t ) {
var y;

y = quantile( 0.5, 20, 1.0 );
t.strictEqual( y, 0.0, 'returns expected value' );

y = quantile( 0.9, 10, 1.0 );
t.strictEqual( y, 0.0, 'returns expected value' );

t.end();
});

tape( 'if the distribution mean overflows double-precision floating-point format, the function returns `+infinity`', opts, function test( t ) {
var y;

Expand Down
Loading