Can I write const expression double that is two ulps less than -0.5

Viewed 259

I have a set of floating point calculation based on numbers I receive via a json packet. At the end of my calculation I require one of the numbers to be >= -0.5. I'm finding that sometimes I have a value that fails the test because it is one ULP below the threshold. Is there anyway to write a constexpression that means something like

constexpr auto threshold = -0.5 - 2*ULP;

or do I have to resort to something like

auto threshold = -0.5;
threshold = std::nexttoward(threshold, -2.0);
threshold = std::nexttoward(threshold, -2.0);
2 Answers
Related