Usual arithmetic conversions

When different arithmetic types are used as operands in certain types of expressions, standard conversions known as usual arithmetic conversions are applied.

For example, when the values of two different integral types are added together, both values are first converted to the same type: when a short int value and an int value are added together, the short int value is converted to the int type. Expressions and operators provides a list of the operators and expressions that participate in the usual arithmetic conversions.

Conversion ranks for arithmetic types

The ranks in the tables are listed from highest to lowest:

Table 1. Conversion ranks for floating-point types
Operand type
long double or long double _Complex
double or double _Complex
float or float _Complex
IBM extension
Table 2. Conversion ranks for decimal floating-point types
Operand type
_Decimal128
_Decimal64
_Decimal32
IBM extension
Table 3. Conversion ranks for integer types
Operand type
long long int, unsigned long long int
long int, unsigned long int
int, unsigned int
short int, unsigned short int
char, signed char, unsigned char
Boolean
Notes:
  • The long long int and unsigned long long int types are not included in the C89, C++98, and C++03 standards.
  • C only The wchar_t type is not a distinct type, but rather a typedef for an integer type. The rank of the wchar_t type is equal to the rank of its underlying type.C only
  • C only The rank of enumerated type is equal to the rank of its underlying type.C only

Rules for floating-point operands

In a context where an operation involves two operands, if either of the operands is of floating-point type, the compiler performs the usual arithmetic conversions to bring these two operands to a common type. The floating-point promotions are applied to both operands. The following rules apply to the promoted operands:
  1. If both operands have the same type, no conversion is needed.
  2. Otherwise, if both operands have complex types, the type at a lower integer conversion rank is converted to the type at a higher rank. For more information, see Floating-point conversions.
  3. Otherwise, if one operand has a complex type, the type of both operands after conversion is the higher rank of the following types:
    • The complex type corresponding to the type of the generic floating-point operand
    • The type of the complex operand
    For more information, see Floating-point conversions.
  4. Otherwise, both operands have generic floating types. The following rules apply:
    1. If one operand has the long double type, the other operand is converted to long double.
    2. Otherwise, if one operand has the double type, the other operand is converted to double.
    3. Otherwise, if one operand has the float type, the other operand is converted to float.

Rules for integral operands

In a context where an operation involves two operands, if both of the operands are of integral types, the compiler performs the usual arithmetic conversions to bring these two operands to a common type. The integral promotions are applied to both operands and the following rules apply to the promoted operands:
  1. If both operands have the same type, no conversion is needed.
  2. Otherwise, if both operands have signed integer types or both have unsigned integer types, the type at a lower integer conversion rank is converted to the type at a higher rank.
  3. Otherwise, if one operand has an unsigned integer type and the other operand has a signed integer type, the following rules apply:
    1. If the rank for the unsigned integer type is higher than or equal to the rank for the signed integer type, the signed integer type is converted to the unsigned integer type.
    2. Otherwise, if the signed integer type can represent all of the values of the unsigned integer type, the unsigned integer type is converted to the signed integer type.
    3. Otherwise, both types are converted to the unsigned integer type that corresponds to the signed integer type.