Arithmetic Operators

DESCRIPTION:
The arithmetic operations of addition, subtraction, multiplication, division, exponentiation, integer division, and modulo. All but the latter two accept complex as well as numeric arguments.

USAGE:
e1 op e2

op:
one of +, -, *, /, ^, %/% or %%.

REQUIRED ARGUMENTS:
e1,e2:
numeric or complex. Missing values (NAs) are allowed.

VALUE:
numeric or complex result, with the shorter argument used cyclically, if necessary: +, -, * and / are the usual arithmetic operators and ^ is exponentiation. (The ** operator no longer exists as a synonym to ^.)

%/% is integer divide; the operands should be numeric and the result is floor(e1/e2) if e2!=0 and 0 if e2==0.

%% is the modulo function; it also expects numeric operands and is defined as e1-floor(e1/e2)*e2 if e2!=0 and e1 otherwise (see Knuth, 1968, section 1.2.4). Thus %/% and %% always satisfy e1==(e1%/%e2)*e2+e1%%e2.


CLASSES:
This function will be used as the default method for classes that do not inherit a specifc method for the function or for the Ops group of functions. The result will retain the class and the attributes. If this behavior is not appropriate, the designer of the class should provide a method for the function or for the Ops group.

DETAILS:
For ^ with numeric arguments and negative e1: if e2 is not an integer, the value is NA; if e2 is a negative integer, the value is 1/(e1^(-e2)). A machine-dependent test is performed to decide if a number is exactly or nearly an integer; do not count on its behavior in doubtful cases.

Section 5.6.1 of Becker, Chambers and Wilks describes the rules for dealing with operands possessing attributes. Also see section 5.1.5 for details on domains and branch cuts in the case of complex arguments for exponentiation.

The .Uminus function performs the unary minus operation. For example, -2 is the same as .Uminus(2).

These are generic functions since they are part of the Ops group. Group methods exist for data frames. They also exist for factors and ordered factors, but arithmetic is not allowed for these classes.


REFERENCES:
Knuth, D. E. (1968). The Art of Computer Programming, Volume 1: Fundamental Algorithms Addison-Wesley, Reading, Mass.

SEE ALSO:
Matrix-product , Complex , cumsum , exp .

EXAMPLES:
x-mean(x)       # deviations from the mean; second argument used repeatedly
(1+(5:8)/1200)^12     # compound interest, 5:8 per annum monthly

get("%/%") # print the definition