Macaulay2 » Documentation
Packages » RInterface :: arithmetic operators on RObjects
next | previous | forward | backward | up | index | toc

arithmetic operators on RObjects -- arithmetic operators on R objects

The standard arithmetic operators are available when working with R objects, and in particular, numeric and complex vectors.

+ and - are both available as unary operators.

i1 : x = RObject(-5)

o1 = [1] -5

o1 : RObject of type integer
i2 : +x

o2 = [1] -5

o2 : RObject of type integer
i3 : -x

o3 = [1] 5

o3 : RObject of type integer

+, -, *, /, and ^ are available as binary operators with the expected behavior.

i4 : x = RObject 5

o4 = [1] 5

o4 : RObject of type integer
i5 : y = RObject 2

o5 = [1] 2

o5 : RObject of type integer
i6 : x + y

o6 = [1] 7

o6 : RObject of type integer
i7 : x - y

o7 = [1] 3

o7 : RObject of type integer
i8 : x * y

o8 = [1] 10

o8 : RObject of type integer
i9 : x / y

o9 = [1] 2.5

o9 : RObject of type double
i10 : x^y

o10 = [1] 25

o10 : RObject of type double

// and % have their usual Macaulay2 behaviors of floor division and modulus, respectively, wrapping around R's %/% and %%.

i11 : x // y

o11 = [1] 2

o11 : RObject of type integer
i12 : x % y

o12 = [1] 1

o12 : RObject of type integer

For the binary operators, one of the operands may be a Macaulay2 object. It will be converted to an RObject before the operation is performed.

i13 : x + 2

o13 = [1] 7

o13 : RObject of type integer
i14 : 5 + y

o14 = [1] 7

o14 : RObject of type integer