diff --git a/src/basic/vx_math/ptile.cc b/src/basic/vx_math/ptile.cc index 75b834f934..1b7207c760 100644 --- a/src/basic/vx_math/ptile.cc +++ b/src/basic/vx_math/ptile.cc @@ -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)); @@ -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 ); @@ -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() -> " + << "requested percentile value (" << t + << ") must be between 0 and 1!\n\n"; + + exit ( 1 ); + +} + if ( n > 0 ) { index = nint(floor((n - 1)*t));