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
Table 2. Conversion ranks for decimal floating-point types
Operand type
IBM extension _Decimal128
IBM extension _Decimal64
IBM extension _Decimal32
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 standards.
  • 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.
  • The rank of enumerated type is equal to the rank of its underlying type.

Rules for decimal floating-point operands

IBM extension
In a context where an operation involves two operands, if one of the operands is of decimal floating type, the other operand cannot be a generic floating type, imaginary type, or complex 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 and the following rules apply to the promoted operands:
  1. If both operands have the same type, no conversion is needed.
  2. If one operand has the _Decimal128 type, the other operand is converted to _Decimal128.
  3. Otherwise, if one operand has the _Decimal64 type, the other operand is converted to _Decimal64.
  4. Otherwise, if one operand has the _Decimal32 type, the other operand is converted to _Decimal32.
IBM extension

Rules for other 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. If the rules for decimal floating-point operands do not apply, 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.