Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does rank mean in relation to type conversion?

From C++11 standard (draft n3337) §5/9:

— If both operands have the same type, no further conversion is needed.

— Otherwise, if both operands have signed integer types or both have unsigned integer types, the operand with the type of lesser integer conversion rank shall be converted to the type of the operand with greater rank.

— Otherwise, if the operand that has unsigned integer type has rank greater than or equal to the rank of the type of the other operand, the operand with signed integer type shall be converted to the type of the operand with unsigned integer type.

— Otherwise, if the type of the operand with signed integer type can represent all of the values of the type of the operand with unsigned integer type, the operand with unsigned integer type shall be converted to the type of the operand with signed integer type.

— Otherwise, both operands shall be converted to the unsigned integer type corresponding to the type of the operand with signed integer type.

What does rank mean in this context?
Surely it's not referring to std::rank,
as that has to do with the number of dimensions in an array...

In terms of integral types and floating point types, I think it refers to their potential sizes.

The C++ Standard guarantees that:

1 == sizeof(char) <= sizeof(short) <= sizeof(int) <= sizeof(long) <=  sizeof(long long)  

am I right to assume then that the ranks are then:

RankType
1 char
2 short
3 int
4 long
5 long long
...

I haven't been able to find a list anywhere describing the level of rank for each type.

like image 407
Trevor Hickey Avatar asked May 27 '15 16:05

Trevor Hickey


People also ask

What is conversion rank?

Conversion rate ranking explains how your ad's expected conversion rate compared to ads with the same optimization goal competing for the same audience.

How type conversion is done in C?

Implicit Type Conversion In C Notice that we have assigned the double value to an integer variable. int number = value; Here, the C compiler automatically converts the double value 4150.12 to integer value 4150. Since the conversion is happening automatically, this type of conversion is called implicit type conversion.

Which operator can be used to do type conversions?

operator int(); ... }; The operator overloading defines a type conversion operator that can be used to produce an int type from a Counter object. This operator will be used whenever an implicit or explict conversion of a Counter object to an int is required. Notice that constructors also play a role in type conversion.

What is integer conversion?

Integer promotion is the implicit conversion of a value of any integer type with rank less or equal to rank of int or of a bit field of type _Bool, int, signed int, unsigned int, to the value of type int or unsigned int.

What is the integer conversion rank?

Every integer type has an integer conversion rank defined as follows: — No two signed integer types other than char and signed char (if char is signed) shall have the same rank, even if they have the same representation. — The rank of a signed integer type shall be greater than the rank of any signed integer type with a smaller size.

Can two signed integer types have the same rank?

— No two signed integer types other than char and signed char (if char is signed) shall have the same rank, even if they have the same representation. — The rank of a signed integer type shall be greater than the rank of any signed integer type with a smaller size.

How to calculate rank correlation coefficient?

The calculation for the rank correlation coefficient the same as that for the Pearson correlation coefficient, but is calculated using the ranks of the observations and not their numerical values. This method is useful when the data are not available in numerical form but information is sufficient to rank the data.

What is the use of the rank method?

This method is useful when the data are not available in numerical form but information is sufficient to rank the data.


1 Answers

The 4.13 section says that

Every integer type has an integer conversion rank defined as follows:

— No two signed integer types other than char and signed char (if char is signed) shall have the same rank, even if they have the same representation.

— The rank of a signed integer type shall be greater than the rank of any signed integer type with a smaller size.

— The rank of long long int shall be greater than the rank of long int, which shall be greater than the rank of int, which shall be greater than the rank of short int, which shall be greater than the rank of signed char.

— The rank of any unsigned integer type shall equal the rank of the corresponding signed integer type

— The rank of any standard integer type shall be greater than the rank of any extended integer type with the same size.

— The rank of char shall equal the rank of signed char and unsigned char.

— The rank of bool shall be less than the rank of all other standard integer types.

— The ranks of char16_t, char32_t, and wchar_t shall equal the ranks of their underlying types (3.9.1).

— The rank of any extended signed integer type relative to another extended signed integer type with the same size is implementation-defined, but still subject to the other rules for determining the integer conversion rank.

— For all integer types T1, T2, and T3, if T1 has greater rank than T2 and T2 has greater rank than T3, then T1 shall have greater rank than T3.

like image 134
Rahul Tripathi Avatar answered Nov 10 '22 00:11

Rahul Tripathi