For each function, I get/have a finite sized array of floats that I need to pick.
So if I have something like
1)
{-0.02, 0.5, 0.98, -0.15, etc... }
I would pick "-0.02" from this list.
2)
{-0.78, 0.003, 0.1, -1.8, etc... }
and now, I would pick "0.003" from this list.
This is just an example. In my real program, I have floats with 5-6 decimal points.
std::min_element
has an overload that takes a comparison function object; that's what I'd use here:
float val = *std::min_element(std::begin(v), std::end(v),
[](float a, float b) { return fabs(a) < fabs(b); } );
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With