float point number?

how can I check if the number is float point number without converting the number to string and then find '.'? For example, this number (5.0) should not be integer. I found the following way in Python but it didn't work in C++
abs(n - (int)n) < 0.000001
A number is a floating point number if it is declared with type float, double, or long double. I do not understand your question.
Sorry for being not clear enough. I want to implement a function (template function) that accepts a number and returns true if the number is integer otherwise returns false.
This function already exists in C++:
http://en.cppreference.com/w/cpp/types/is_integral
Did you use abs? of fabs? abs returns an integer
There is no need to use either function. The correct way is to either use std::is_integral, or if your compiler/library does not support C++11, to use the boost equivalent.
I'm using Qt and there is such header file like #include <type_traits>
Something like this would work:
1
2
3
4
#include <type_traits>

template <typename T>
bool is_integral(T lbl) { return std::is_integral<T>::value; }


If you don't have C++11, you could also do this:
1
2
3
4
#include <limits>

template <typename T>
bool is_integral(T lbl) { return std::numeric_values<T>::is_integer; }


The functions are of course just to reduce the verbosity. You could also just use the std::numeric_values<T>::is_integer(); directly in your code.
Last edited on
Thank you guys.

@Stewbond,
It worked thanks but I found
std::numeric_limits<T>::is_integer;

instead of
std::numeric_values<T>::is_integer;
whoops, that was a typo that I had corrected in my IDE, but forgot to correct it here.
Topic archived. No new replies allowed.