Complex Valued Objects

DESCRIPTION:
The complex and as.complex functions create vectors of complex numbers.

USAGE:
complex(length=0, data=NULL, real=0, imaginary=0,
        modulus=1, argument=0)
is.complex(x)
as.complex(x)

OPTIONAL ARGUMENTS:
length:
length of the returned object.
data:
a vector, used only when all the arguments below are missing. complex(data=x) is the same as as.complex(x), and complex(length=n, data=x) is the same as rep(as.complex(x), length=n).
real:
vector of real parts for use in the construction of the return value.
imaginary:
vector of imaginary parts for use in the construction of the return value.
modulus:
vector of moduli for use in the construction of the return value.
argument:
vector of arguments for use in the construction of the return value.

x:
any S-PLUS object.

VALUE:
complex returns a simple object (i.e., a vector) of mode "complex". If real and/or imaginary are specified, the real and imaginary parts of the result are set from them, using the defaults if necessary. If modulus and/or argument are specified, the modulus and argument of the result are set from them, using the defaults if necessary. If either of real or imaginary is specified, neither modulus nor argument may be specified, and vice versa.

is.complex returns TRUE if x is of mode "complex", and FALSE otherwise. Its behavior is unaffected by any attributes of x; for example, x could be a complex array.

as.complex returns x if x is a simple object of mode "complex", and otherwise a complex object of the same length as x and with data resulting from coercing the elements of x to mode "complex". Attributes are deleted.


DETAILS:
The "+" within the rectangular representation of a complex number has the usual precedence.

Both the as.complex and is.complex functions are generic; currently there are no methods written for them.


SEE ALSO:
Complex describes the functions that do basic manipulations of complex numbers.

EXAMPLES:
unit.disk <- complex(arg=runif(50, -pi, pi))
        #50 random complex numbers, uniform on the unit circle
sqrt(as.complex(-5:5))
# shift the phase of a vector
zz.shift <- complex(modulus=Mod(zz), argument=Arg(zz)+pi)