### 3.3.3. Operations on basic data types

The ARM compiler performs the usual arithmetic conversions set out in relevant sections of the ISO C and C++ standards. The following sections document additional points that relate to arithmetic operations. See also Statements.

#### Operations on integral types

The following statements apply to operations on the integral types:

• All signed integer arithmetic uses a two's complement representation.

• Bitwise operations on signed integral types follow the rules that arise naturally from two's complement representation. No sign extension takes place.

• Right shifts on signed quantities are arithmetic.

• Any quantity that specifies the amount of a shift is treated as an unsigned 8-bit value.

• Any value to be shifted is treated as a 32-bit value.

• Left shifts of more than 31 give a result of zero.

• Right shifts of more than 31 give a result of zero from a shift of an unsigned value or positive signed value. They yield –1 from a shift of a negative signed value.

• The remainder on integer division has the same sign as the divisor.

• If a value of integral type is truncated to a shorter signed integral type, the result is obtained by discarding an appropriate number of most significant bits. If the original number was too large, positive or negative, for the new type, there is no guarantee that the sign of the result is going to be the same as the original.

• A conversion between integral types does not raise an exception.

• Integer overflow does not raise an exception.

• Integer division by zero raises a SIGFPE exception. See Table 5.19.

#### Operations on floating-point types

The following statements apply to operations on floating-point types:

• Normal IEEE 754 rules apply.

• Rounding is to the nearest representable value by default.

• Floating-point exceptions are disabled by default.

Also, see the description of the `--fpmode` option in Defining optimization criteria.

### Note

The IEEE 754 standard for floating-point processing states that the default action to an exception is to proceed without a trap. You can modify floating-point error handling by tailoring the functions and definitions in `fenv.h`. See Tailoring error signaling, error handling, and program exit for more details on floating-point processing.

#### Pointer subtraction

The following statements apply to all pointers in C. They also apply to pointers, other than pointers to members, in C++:

• When one pointer is subtracted from another, the difference is the result of the expression:

```
((int)a - (int)b) / (int)sizeof(type pointed to)
```
• If the pointers point to objects with a size of one, two, or four bytes, the natural alignment of the object ensures that the division is exact, provided the objects are not packed.

• For packed or longer types, such as double and struct, both pointers must point to elements of the same array.