Tools: MPW
Advanced Search
Apple Developer Connection
Member Login Log In | Not a Member? Support

MPW Command Reference


Appendix C (continued)

Arithmetic Operators

+  Addition

In an arithmetic expression, the + character signifies addition. For example, the command

Evaluate 10667 + 991 + 16043

adds 10,667, 991, and 16,043 and displays the result, 27,701, in the active window. You can also use the + character with variables. For example, the command

Evaluate {a} + {b}

adds the current values of the variables {a} and {b}.

The + character can also be used in regular expressions. See the + One or more occurrences entry for a description of that meaning.

÷  Division  [Option-/]

The ÷ character signifies division and has the same meaning as the DIV operator. For example, the command

Evaluate 12 4

divides 12 by 4 and displays the result of 3 in the active window.

You can also use variables with the character. If you enter

Evaluate {a} {b}

the current value of {a} is divided by the current value of {b}.

When you use parentheses to group figures in any arithmetic computation, the expression within parentheses is performed first. The final result may be different for different groupings. For example, the result of

Evaluate (100 25) * 4

is 16; but the result of

Evaluate 100 (25 * 4)

is 1.

DIV  Division

The DIV operator signifies division and has the same meaning as the character. For example, the command

Evaluate 12 DIV 4

divides 12 by 4 and displays the result of 3 in the active window.

You can also use variables with the DIV operator. If you enter

Evaluate {a} DIV {b}

the current value of {a} is divided by the current value of {b}.

When you use parentheses to group figures in any arithmetic computation, the expression within parentheses is performed first. The final result may be different for different groupings. For example, the result of

Evaluate (100 DIV 25) * 4

is 16; but the result of

Evaluate 100 DIV (25 * 4)

is 1.

MOD  Modulus

The MOD operator finds the modulus, or remainder, of a division process, and has the same meaning as the % operator. For example, 15 2 yields 7, with a remainder (or modulus) of 1.

The command

Evaluate 100 MOD 3

divides 100 by 3 and displays the remainder in the active window. In this case, the modulus is 1. However, the result of the command

Evaluate 3 MOD 5

is 3. When you divide a smaller number by a larger number, the modulus is the smaller number. For example, with

Evaluate 25 MOD 100

the Evaluate command returns 25; but with

Evaluate 100 MOD 25

the Evaluate command returns 0.

%  Modulus

The % operator finds the modulus, or remainder, of a division process, and has the same meaning as the MOD operator. For example, 15 2 yields 7, with a remainder (or modulus) of 1.

The command

Evaluate 100 % 3

divides 100 by 3 and prints the remainder of the division to the screen. In this case, the modulus is 1. However, the result of the command

Evaluate 3 % 5

is 3. When you divide a smaller number by a larger number, the modulus is the
smaller number.

For example, with

Evaluate 25 % 100

the Evaluate command returns 25; but with

Evaluate 100 % 25

the Evaluate command returns 0.

*  Multiplication

The * character signifies multiplication. For example, the command

Evaluate 3 * 4

multiplies 3 and 4 and displays the result of 12 in the active window. You can also use the * character with variables. The command

Evaluate {a} * {b}

multiplies the current values of the variables {a} and {b}.

-  Subtraction, sign change

In arithmetic expressions, the - character can mean subtraction or sign change. When it means subtraction, the - character is used between two operands to subtract the value on the right from the value on the left. For example, the command

Evaluate 10 - 2

computes the result as 8, and displays it in the active window. When you group expressions within parentheses, the expression within parentheses is evaluated first; this might alter the result. For example,

Evaluate (20 - 8) - 4

yields 8. However, the command

Evaluate 20 - (8 - 4)

yields 16. You can also use the - character with variables. The command

Evaluate {a} - {b}

subtracts the current value of {b} from the current value of {a}.

When the - character means sign change, it changes the sign of a number or variable. For example,

Evaluate -4

displays -4 in the active window. Likewise,

Evaluate -(-4)

displays 4. You can change the sign of a variable or expression in the same way, as in

Evaluate -({a} + {b})

which adds the current values of {a} and {b}, then changes the sign of the result.

The - character can also be used in regular expressions. See the - Specify a range of characters entry for a description of that meaning.

 
 


Last Updated July 2000