x <- as.bigq(21,6)
x
# 7 / 2
# Wow ! result is simplified.
y <- as.bigq(5,3)
# addition works !
x + y
# You can even try multiplication, division...
x * y / 13
# and, since May 2012,
x ^ 20
stopifnot(is.bigq(x), is.bigq(x + y),
x ^ 20 == as.bigz(7)^20 / 2^20)
# convert to string, double
as.character(x)
as.double(x)
stopifnot( is.na(NA_bigq_) )
# Depict the "S4-class" bigq, i.e., the formal (S4) methods:
if(require("Rmpfr")) # mostly interesting there
showMethods(class="bigq")
# an sapply() version that works for big rationals "bigq":
sapplyQ <- function(X, FUN, ...) c_bigq(lapply(X, FUN, ...))
# dummy example showing it works (here):
qq <- as.bigq(1, 1:999)
q1 <- sapplyQ(qq, function(q) q^2)
stopifnot( identical(q1, qq^2) )
Run the code above in your browser using DataLab