Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

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();
}

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading