I'm adding data to dataset
when a condition is true
, then I'm using getYMax()
to calculate the maximum value in the dataset. However, if the dataset
is empty (no items have been collected) it will return -infinity
. Is there any way to make getYMax()
return 0
instead of -infinity
?
Thank you
Sure. Use a separate function returning a double and taking the dataset as an argument, call it f_getDSMax()
:
if (myDataSet.size() == 0) {
return 0.;
}
return myDataSet.getYMax();
Or you do it in 1 line:
myDataSet.size() == 0 ? 0. : myDataSet.getYMax()