Reputation: 62189
I'm watching over the type_traits
, and accidentally came across the fact, that float
is not considered to be an integral type. It was kinda surprise for me.
I looked through the web to find appropriate information, but couldn't find anything concerning that fact. All I could find is something like this:
If T is an integral type (bool, char, char16_t, char32_t, wchar_t, short, int, long, long long, including any signed, unsigned, and cv-qualified variants), provides the member constant value equal true. For any other type, value is false.
So the question here: Why did the C++ Standards Committee decide that float is not an integral type?
Upvotes: 7
Views: 3052
Reputation: 97
Those are integral types because while storing integer types or characters in c++ ,it stores in integer format (even characters i.e., in ASCII format).But floats are not stored like that we don't have any method to convert floats to binary format
Upvotes: -1
Reputation: 56883
Jon's answer is right, but here's a short overview of some type traits that might help you:
is_integral
checks if a type is integral typeis_floating_point
checks if a type is floating point typeis_arithmetic
checks if a type is either integral or floating point typeAnd here is a nice graph from Howard Hinnant that shows the relationship between the type categories.
Upvotes: 5
Reputation: 93860
I suspect your confusion is which meaning of integral applies:
Definition of INTEGRAL
1 a : essential to completeness : constituent "an integral part of the curriculum"
b (1) : being, containing, or relating to one or more mathematical integers (2) : relating to or concerned with mathematical integration or the results of mathematical integration
It's not (1a) essential to completeness (which float
would be), but (1b) relating to the integers.
Upvotes: 5
Reputation: 1502106
An integral type is one which has only integers - whole numbers. The purpose of floating point types is to represent non-integers as well.
From the Wikipedia page on integer (computer science):
In computer science, an integer is a datum of integral data type, a data type which represents some finite subset of the mathematical integers.
Upvotes: 11