Macaulay2 » Documentation
Packages » RInterface :: rounding of RObjects
next | previous | forward | backward | up | index | toc

rounding of RObjects -- rounding of R objects

These functions round RObject's representing numbers in specific ways.

ceiling and floor do the expected thing, calling the corresponding R function to round up or down, respectively.

i1 : x = RObject exp 1

o1 = [1] 2.718282

o1 : RObject of type double
i2 : ceiling x

o2 = [1] 3

o2 : RObject of type double
i3 : floor x

o3 = [1] 2

o3 : RObject of type double

truncate calls R's trunc function to round toward 0.

i4 : truncate x

o4 = [1] 2

o4 : RObject of type double
i5 : truncate(-x)

o5 = [1] -2

o5 : RObject of type double

round calls the corresponding R function, which rounds to even, just as in Macaulay2.

i6 : round RObject 2.5

o6 = [1] 2

o6 : RObject of type double
i7 : round RObject 3.5

o7 = [1] 4

o7 : RObject of type double

It may also be called with a second argument, or equivalently, a digits option, specifying the number of decimal places to be used when rounding.

i8 : round(x, 2)

o8 = [1] 2.72

o8 : RObject of type double
i9 : round(x, digits => 3)

o9 = [1] 2.718

o9 : RObject of type double