To check for NaN is relatively easy as it is the only case where
value == value is false.
To check for Inifinity, seeing as it is a sort of "valid value" is a bit more complex and requires the use of the <limits> c++ library. Here is the code:
QString Approximator
::ValidQReal(qreal value
){ if (value != value){
return "NaN";
}
else if (value > std::numeric_limits<qreal>::max()){
return "+Inf";
}
else if (value < -std::numeric_limits<qreal>::max()){
return "-Inf";
}
else
return "";
}
QString Approximator::ValidQReal(qreal value){
if (value != value){
return "NaN";
}
else if (value > std::numeric_limits<qreal>::max()){
return "+Inf";
}
else if (value < -std::numeric_limits<qreal>::max()){
return "-Inf";
}
else
return "";
}
To copy to clipboard, switch view to plain text mode
In my particular case I return a QString that eventually cuts my thread and shows an errro message of what was found.
Bookmarks