How do any floating point values ​​compare to infinity?

Basically I want to find the smallest (positive) value from a group of values ​​and to compare with the first default value. A naive assumption would be, they would always compare “less” (except for NaNs, but not consider them), but I'm not quite sure.

I use type float, and I think it can be safely assumed that my target equipment implements the value of infinity.

Here is a sample code:

auto leastValue = std::numeric_limits<float>::infinity();
for (auto i = something.begin(), e = something.end(); i != e; ++i)
{
  auto value = (*i)->GetValue();
  if (value < leastValue)
  {
    leastValue = value;
  }
}
+5
source share
3 answers

IEEE 754, NaN , . , . , numeric_limits<float>::is_iec559. , numeric_limits<float>::max(); , .

+8

: ,

, . ( : P)

+2

, , , . , , .

auto i = something.begin();
auto e = semething.end();
if (i == e)
  throw std::exception("empty sequence");

auto leastValue = (*i)->GetValue();

for (++i; i != e; ++i)
{
  auto value = (*i)->GetValue();
  if (value < leastValue)
  {
    leastValue = value;
  }
}
0