A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://en.cppreference.com/w/cpp/language/../memory/../language/usual_arithmetic_conversions.html below:

Usual arithmetic conversions - cppreference.com

Many binary operators that expect operands of arithmetic or enumeration type cause conversions and yield result types in a similar way. The purpose is to yield a common type, which is also the type of the result. This pattern is called the usual arithmetic conversions.

[edit] Definition

Usual arithmetic conversions are defined as follows:

[edit] Stage 1

Applies lvalue-to-rvalue conversion to both operands, the resulting prvalues are used in place of the original operands for the remaining process.

[edit] Stage 2 (since C++11) [edit] Stage 3 (since C++26) [edit] Stage 4
(since C++23) [edit] Stage 5

Both operands are converted to a common type C. Given the types T1 and T2 as the promoted type (under the rules of integral promotions) of the operands, the following rules are applied to determine C:

If one operand is of enumeration type and the other operand is of a different enumeration type or a floating-point type, this behavior is deprecated.

(since C++20)
(until C++26) [edit] Integer conversion rank

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

(since C++11)
(since C++20)
(since C++11)
(since C++11)

The integer conversion rank is also used in the definition of integral promotion.

[edit] Floating-point conversion rank and subrank [edit] Floating-point conversion rank

Every floating-point type has a floating-point conversion rank defined as follows:

(since C++23) Floating-point conversion subrank

Floating-point types that have equal floating-point conversion ranks are ordered by floating-point conversion subrank. The subrank forms a total order among types with equal ranks.

The types std::float16_t, std::float32_t, std::float64_t, and std::float128_t (fixed width floating-point types) have a greater conversion subrank than any standard floating-point type with equal conversion rank. Otherwise, the conversion subrank order is implementation-defined.

(since C++23) [edit] Usage

The floating-point conversion rank and subrank are also used to

[edit] Defect reports

The following behavior-changing defect reports were applied retroactively to previously published C++ standards.

DR Applied to Behavior as published Correct behavior CWG 1642 C++98 usual arithmetic conversions might involve lvalues applies lvalue-to-rvalue conversions first CWG 2528 C++20 the three-way comparison between unsigned char
and unsigned int is ill-formed because
of the intermediate integral promotion[1] determines the common type based
on the promoted types, without
actually promoting the operands[2] CWG 2892 C++98 when both operands are of the same
floating-point type, the meaning of “no
further conversion is needed” was unclear changed to “no further
conversion will be performed”
  1. ↑ Before the resolution, unsigned char is promoted to int at the beginning of stage 5, then it is converted to unsigned int. However, the latter conversion is narrowing, which makes the three-way comparison ill-formed.
  2. ↑ After the resolution, the common type is still unsigned int. The difference is that unsigned char is directly converted to unsigned int without the intermediate integral promotion. The conversion is not narrowing and hence the three-way comparison is well-formed.

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4