<div dir="ltr">Hi All,<div><br></div><div>This is one of those picky math questions that deals with numerical precision.  Let's say that one has a data set with scalar type "float", and wants to select values within a range (minval, maxval) where minval, maxval are of type "double":</div><div><br></div><div>    if (fval >= minval && fval <= maxval) { ... }</div><div><br></div><div>Now let's say you don't want "fval" to be converted to double, because floats are faster than doubles on your hardware:</div><div><br></div><div>   float fminval = static_cast<float>(minval);</div><div>   float fmaxval = static_cast<float>(maxval);</div><div>   ...</div><div>   if (fval >= fminval && fval <= fmaxval) { ... }</div><div><br></div><div>Unfortunately, there are some cases where fval <= fmaxval even though fval > maxval.  Reducing the precision of the range has invalidated the check.  In order to fix things, you must choose fminval to be the value closest to but not more than minval, and choose fmaxval to be the value closest to but not less than maxval.</div><div><br></div><div>    float fminval = NearestFloatNotGreaterThan(minval);</div><div>    float fmaxval = NearestFloatNotLessThan(maxval);</div><div><br></div><div>With these, (fval >= fminval && fval <= fmaxval) gives the same result as (fval >= minval && val <= fmaxval) and all is right with the world.</div><div><br></div><div>So my question is, have any other devs created a solution for this issue, either for VTK or for related code?  I'm considering a solution based on the C++11 function std::nextafter(), as described on this stackoverflow page: <a href="https://stackoverflow.com/questions/15294046/round-a-double-to-the-closest-and-greater-float">https://stackoverflow.com/questions/15294046/round-a-double-to-the-closest-and-greater-float</a></div><div><br></div><div> - David</div><div><br></div><div><br></div><div><br></div><div><br></div></div>