Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why float is not considered as an integral type?

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?

like image 593
azizbekian Avatar asked Mar 02 '13 08:03

azizbekian


People also ask

Is float an integral type?

An integral type is one which has only integers - whole numbers. The purpose of floating point types is to represent non-integers as well.

Which is not an integral data type?

There are four main types of data: string, integer, float, and boolean. Of these, only boolean is not an integral data type.

What is the difference between a float and an integer?

An integer is a whole number and a floating-point value, or float, is a number that has a decimal place.

Which is integral data type?

Integral data types are data types that represent whole numbers. They are used to store data that cannot be fractional, such as counts or measurements. Integral data types are typically stored as 32-bit or 64-bit values.


1 Answers

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.

like image 104
Jon Skeet Avatar answered Sep 23 '22 16:09

Jon Skeet