I am trying to convert floating point values to their string representation, using the QString class from the Qt framework. To do this, I am using the following function:
QString QString::arg(double a)
https://doc.qt.io/qt-5/qstring.html#arg-9
However, my code may supply an 'infinite' floating point value, from the following static function:
const double numericValue = std::numeric_limits<double>::infinity()
I am wondering if there is a nice way to handle this case. There is no reference to an infinite value case on the Qt documentation. Cpp reference suggests that this value is implementation defined and may not even be convertible to a floating point type! https://en.cppreference.com/w/cpp/types/numeric_limits/infinity
I could of course handle this with an if block:
QString asString;
if (numericValue == std::numeric_limits<double>::infinity())
{
asString = "Inf";
}
else
{
asString = QString().arg(numericValue);
}
But is there a better way? Is this even sensible?