Learn R Programming

gmp (version 0.5-4)

bigq: Large sized rationals

Description

Type class supporting arithmetic operations on very large rationals.

Usage

as.bigq(n, d = 1)
## S3 method for class 'bigq':
as.character(x, b=10,...)
## S3 method for class 'bigq':
as.double(x,...)
as.bigz.bigq(a, mod=NA)
## S3 method for class 'bigq':
is.na(x)
## S3 method for class 'bigq':
print(x, quote=FALSE, initLine = TRUE, ...)
denominator(x)
numerator(x)

Arguments

n,d
either integer, numeric or string value (String value: either starting with 0x for hexadecimal, 0b for binary or without prefix for decimal values. Any format error results in 0). n stand
a
an element of class "bigq"
mod
optional modulus to convert into biginteger
x
numeric value
b
base: from 2 to 36
...
additional arguments passed to methods
quote
(for printing:) logical indicating if the numbers should be quoted (as characters are); the default used to be TRUE (implicitly) till 2011.
initLine
(for printing:) logical indicating if an initial line (with the class and length or dimension) should be printed.

Value

  • An Robject of (S3) class "bigq" representing the parameter value.

Details

as.bigz.bigq() returns the smallest integers not less than the corresponding rationals bigq.

References

http://mulcyber.toulouse.inra.fr/projects/gmp/

Examples

Run this code
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(x ^ 20 == as.bigz(7)^20 / 2^20)

# convert to string, double
as.character(x)
as.double(x)

Run the code above in your browser using DataLab