6.3.1.8 Usual arithmetic conversions

Previous Table of Contents

698 Many operators that expect operands of arithmetic type cause conversions and yield result types in a similar way.

699 The purpose is to determine a common real type for the operands and result.

700 For the specified operands, each operand is converted, without change of type domain, to a type whose corresponding real type is the common real type.

701 Unless explicitly stated otherwise, the common real type is also the corresponding real type of the result, whose type domain is the type domain of the operands if they are the same, and complex otherwise.

702 This pattern is called the usual arithmetic conversions:

703 First, if the corresponding real type of either operand is long double, the other operand is converted, without change of type domain, to a type whose corresponding real type is long double.

704 Otherwise, if the corresponding real type of either operand is double, the other operand is converted, without change of type domain, to a type whose corresponding real type is double.

705 Otherwise, if the corresponding real type of either operand is float, the other operand is converted, without change of type domain, to a type whose corresponding real type is float.51)

706 Otherwise, the integer promotions are performed on both operands.

707 Then the following rules are applied to the promoted operands:

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

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

710 Otherwise, if the operand that has unsigned integer type has rank greater or equal to the rank of the type of the other operand, then the operand with signed integer type is converted to the type of the operand with unsigned integer type.

711 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, then the operand with unsigned integer type is converted to the type of the operand with signed integer type.

712 Otherwise, both operands are converted to the unsigned integer type corresponding to the type of the operand with signed integer type.

713 The values of floating operands and of the results of floating expressions may be represented in greater precision and range than that required by the type;

714 the types are not changed thereby.52)

715 51) For example, addition of a double _Complex and a float entails just the conversion of the float operand to double (and yields a double _Complex result).

716 52) The cast and assignment operators are still required to perform their specified conversions as described in 6.3.1.4 and 6.3.1.5.

Next

Created at: 2005-06-29 02:18:56 The text from WG14/N1124 is copyright © ISO