std :: isnormal () does what you want, but also checks for 0.0. So you can check this case further:
float f; bool isNumber = (std::isnormal(f) || f == 0.0);
Edit: as specified by user isnormal also returns false for the subnormal number that the OP probably does not want.
However, perhaps std :: isfinite does the right thing.
float f; bool isNumber = std::isfinite(f) ;
it returns false for NaN and Inf .
user463035818
source share