# Mixed Mode Arithmetic Expressions

If operands in an expression contains both INTEGER and REAL constants or variables, this is a mixed mode arithmetic expression.

In mixed mode arithmetic expressions, INTEGER operands are always converted to REAL before carrying out any computations. As a result, the result of a mixed mode expression is of REAL type. The following is a table showing this fact.

 Operator INTEGER REAL INTEGER INTEGER REAL REAL REAL REAL

The rules for evaluating mixed mode arithmetic expressions are simple:

• Use the rules for evaluating single mode arithmetic expressions for scanning.
• After locating an operator for evaluation, do the following:
• if the operands of this operator are of the same type, compute the result of this operator.
• otherwise, one of the operand is an integer while the other is a real number. In this case, convert the integer to a real (i.e., adding .0 at the end of the integer operand) and compute the result. Note that since both operands are real numbers, the result is a real number.
• There is an exception, though. In a**n, where a is a real and n is a positive integer, the result is computed by multiplying n copies of a. For example, 3.5**3 is computed as 3.5*3.5*3.5

### Simple Examples:

• 1 + 2.5 is 3.5
• 1/2.0 is 0.5
• 2.0/8 is 0.25
• -3**2.0 is -9.0
• 4.0**(1/2) is first converted to 4.0**0 since 1/2 is a single mode expression whose result is 0. Then, 4.0**0 is 1.0

### An Important Note:

In expression a**b where a is REAL, the result is undefined if the value of a is negative. For example, -4.0**2 is defined with -16.0 as its result, while (-4.0)**2 is undefined.

### More Complicated Examples:

In the following, brackets will be used to indicated the order of evaluation and braces will be used to indicated an integer-to-real conversion.
• Note that 6.0 ** 2 is not converted to 6.0 ** 2.0. Instead, it is computed as 6.0 * 6.0.
```5 * (11.0 - 5) ** 2 / 4 + 9
--> 5 * (11.0 - {5}) ** 2 / 4 + 9
--> 5 * (11.0 - 5.0) ** 2 / 4 + 9
--> 5 * ([11.0 - 5.0]) ** 2 / 4 + 9
--> 5 * 6.0 ** 2 / 4 + 9
--> 5 * [6.0 ** 2] / 4 + 9
--> 5 * 36.0 / 4 + 9
--> {5} * 36.0 / 4 + 9
--> 5.0 * 36.0 / 4 + 9
--> [5.0 * 36.0] / 4 + 9
--> 180.0 / 4 + 9
--> 180.0 / {4} + 9
--> 180.0 / 4.0 + 9
--> [180.0 / 4.0] + 9
--> 45.0 + 9
--> 45.0 + {9}
--> 45.0 + 9.0
--> 54.0
```
• In the following, 25.0 ** 1 is not converted, and 1 / 3 is zero.
```25.0 ** 1 / 2 * 3.5 ** (1 / 3)
--> [25.0 ** 1] / 2 * 3.5 ** (1 / 3)
--> 25.0 / 2 * 3.5 ** (1 / 3)
--> 25.0 / {2} * 3.5 ** (1 / 3)
--> 25.0 / 2.0 * 3.5 ** (1 / 3)
--> 12.5 * 3.5 ** (1 / 3)
--> 12.5 * 3.5 ** ([1 / 3])
--> 12.5 * 3.5 ** 0
--> 12.5 * [3.5 ** 0]
--> 12.5 * 1.0
--> 12.5
```
Click here to continue with single mode arithmetic expressions.