tmp/tmpfw401l3o/{from.md → to.md}
RENAMED
|
@@ -0,0 +1,93 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
## Preamble <a id="expr.pre">[[expr.pre]]</a>
|
| 2 |
+
|
| 3 |
+
[*Note 1*: [[expr]] defines the syntax, order of evaluation, and
|
| 4 |
+
meaning of expressions.[^1] An expression is a sequence of operators and
|
| 5 |
+
operands that specifies a computation. An expression can result in a
|
| 6 |
+
value and can cause side effects. — *end note*]
|
| 7 |
+
|
| 8 |
+
[*Note 2*: Operators can be overloaded, that is, given meaning when
|
| 9 |
+
applied to expressions of class type [[class]] or enumeration type
|
| 10 |
+
[[dcl.enum]]. Uses of overloaded operators are transformed into function
|
| 11 |
+
calls as described in [[over.oper]]. Overloaded operators obey the
|
| 12 |
+
rules for syntax and evaluation order specified in [[expr.compound]],
|
| 13 |
+
but the requirements of operand type and value category are replaced by
|
| 14 |
+
the rules for function call. Relations between operators, such as `++a`
|
| 15 |
+
meaning `a+=1`, are not guaranteed for overloaded operators
|
| 16 |
+
[[over.oper]]. — *end note*]
|
| 17 |
+
|
| 18 |
+
Subclause [[expr.compound]] defines the effects of operators when
|
| 19 |
+
applied to types for which they have not been overloaded. Operator
|
| 20 |
+
overloading shall not modify the rules for the *built-in operators*,
|
| 21 |
+
that is, for operators applied to types for which they are defined by
|
| 22 |
+
this Standard. However, these built-in operators participate in overload
|
| 23 |
+
resolution, and as part of that process user-defined conversions will be
|
| 24 |
+
considered where necessary to convert the operands to types appropriate
|
| 25 |
+
for the built-in operator. If a built-in operator is selected, such
|
| 26 |
+
conversions will be applied to the operands before the operation is
|
| 27 |
+
considered further according to the rules in subclause
|
| 28 |
+
[[expr.compound]]; see [[over.match.oper]], [[over.built]].
|
| 29 |
+
|
| 30 |
+
If during the evaluation of an expression, the result is not
|
| 31 |
+
mathematically defined or not in the range of representable values for
|
| 32 |
+
its type, the behavior is undefined.
|
| 33 |
+
|
| 34 |
+
[*Note 3*: Treatment of division by zero, forming a remainder using a
|
| 35 |
+
zero divisor, and all floating-point exceptions varies among machines,
|
| 36 |
+
and is sometimes adjustable by a library function. — *end note*]
|
| 37 |
+
|
| 38 |
+
[*Note 4*:
|
| 39 |
+
|
| 40 |
+
The implementation may regroup operators according to the usual
|
| 41 |
+
mathematical rules only where the operators really are associative or
|
| 42 |
+
commutative.[^2] For example, in the following fragment
|
| 43 |
+
|
| 44 |
+
``` cpp
|
| 45 |
+
int a, b;
|
| 46 |
+
...
|
| 47 |
+
a = a + 32760 + b + 5;
|
| 48 |
+
```
|
| 49 |
+
|
| 50 |
+
the expression statement behaves exactly the same as
|
| 51 |
+
|
| 52 |
+
``` cpp
|
| 53 |
+
a = (((a + 32760) + b) + 5);
|
| 54 |
+
```
|
| 55 |
+
|
| 56 |
+
due to the associativity and precedence of these operators. Thus, the
|
| 57 |
+
result of the sum `(a + 32760)` is next added to `b`, and that result is
|
| 58 |
+
then added to 5 which results in the value assigned to `a`. On a machine
|
| 59 |
+
in which overflows produce an exception and in which the range of values
|
| 60 |
+
representable by an `int` is \[`-32768`, `+32767`\], the implementation
|
| 61 |
+
cannot rewrite this expression as
|
| 62 |
+
|
| 63 |
+
``` cpp
|
| 64 |
+
a = ((a + b) + 32765);
|
| 65 |
+
```
|
| 66 |
+
|
| 67 |
+
since if the values for `a` and `b` were, respectively, -32754 and -15,
|
| 68 |
+
the sum `a + b` would produce an exception while the original expression
|
| 69 |
+
would not; nor can the expression be rewritten as either
|
| 70 |
+
|
| 71 |
+
``` cpp
|
| 72 |
+
a = ((a + 32765) + b);
|
| 73 |
+
```
|
| 74 |
+
|
| 75 |
+
or
|
| 76 |
+
|
| 77 |
+
``` cpp
|
| 78 |
+
a = (a + (b + 32765));
|
| 79 |
+
```
|
| 80 |
+
|
| 81 |
+
since the values for `a` and `b` might have been, respectively, 4 and -8
|
| 82 |
+
or -17 and 12. However on a machine in which overflows do not produce an
|
| 83 |
+
exception and in which the results of overflows are reversible, the
|
| 84 |
+
above expression statement can be rewritten by the implementation in any
|
| 85 |
+
of the above ways because the same result will occur.
|
| 86 |
+
|
| 87 |
+
— *end note*]
|
| 88 |
+
|
| 89 |
+
The values of the floating-point operands and the results of
|
| 90 |
+
floating-point expressions may be represented in greater precision and
|
| 91 |
+
range than that required by the type; the types are not
|
| 92 |
+
changed thereby.[^3]
|
| 93 |
+
|