Skip to content

Commit

Permalink
Per #2644, error out if the requested percentile is out of range.
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnHalleyGotway committed Aug 16, 2023
1 parent 886d59e commit fa96e6f
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/basic/vx_math/ptile.cc
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,17 @@ int index;
double delta;
double p = bad_data_double;

// Range check
if ( t < 0.0 || t > 1.0 ) {

mlog << Error << "\npercentile() -> "
<< "requested percentile value (" << t
<< ") must be between 0 and 1!\n\n";

exit ( 1 );

}

if ( n > 0 ) {

index = nint(floor((n - 1)*t));
Expand All @@ -76,6 +87,7 @@ if ( n > 0 ) {
delta = (n - 1)*t - index;
p = (1 - delta)*ordered_array[index] + delta*ordered_array[index + 1];
}

}

return ( p );
Expand Down Expand Up @@ -110,6 +122,17 @@ int index;
float delta;
float p = bad_data_float;

// Range check
if ( t < 0.0 || t > 1.0 ) {

mlog << Error << "\npercentile_f() -> "
<< "requested percentile value (" << t
<< ") must be between 0 and 1!\n\n";

exit ( 1 );

}

if ( n > 0 ) {

index = nint(floor((n - 1)*t));
Expand Down

0 comments on commit fa96e6f

Please sign in to comment.