Home > OS >  Is using std::numeric_limits<T>::quiet_NaN() a bad practice?
Is using std::numeric_limits<T>::quiet_NaN() a bad practice?

Time:11-18

Have the following function that searches a query for a match and returns NaN if no match was found:


int64_t Foo::search(const std::string& foo, int64_t t0, ...
if {
...
}
else
  return std::numeric_limits<int64_t>::quiet_NaN();
}

CodePudding user response:

std::numeric_limits<T>::quiet_NaN(); is only meaningful if T is a floating point type for which std::numeric_limits<T>::has_quiet_NaN(); is true. So, no, your code is not good practise.

Reference: https://en.cppreference.com/w/cpp/types/numeric_limits/quiet_NaN

  • Related