01. Basics {VeryLargeIntegers} | R Documentation |
Very Large Integers Basics
Description
vli is a S3 class that allows to store and operate with arbitrarily large integers. Each object of class vli has 3 attributes (sign
, length
and value
) that can be accessed as shown in the examples. The (absolute) value of the number is stored in a numeric vector to avoid truncation.
Usage
as.vli(n)
## Default S3 method:
as.vli(n)
## S3 method for class 'vli'
as.vli(n)
## S3 method for class 'character'
as.vli(n)
## S3 method for class 'numeric'
as.vli(n)
asnumeric(x)
## Default S3 method:
asnumeric(x)
## S3 method for class 'vli'
asnumeric(x)
## S3 method for class 'vli'
as.integer(x, ...)
## S3 method for class 'vli'
as.integer(x, ...)
vli(m)
## S3 method for class 'vli'
print(x, ...)
is.vli(x)
Arguments
n |
value for the vli object being created; character or numeric |
x |
object of class vli |
... |
further arguments passed to or from other methods |
m |
number of vli objects being initialized; numeric |
Details
In as.vli(n)
, if n
is numeric, it must be a 32 bits integer to avoid the loss of precision. The idea is to use numeric objects only for small numbers. In other case, character objects are prefered.
The function as.integer(x)
, where x
a vli object, only works when the absolute value of x
is up to 2.147.483.648 (32 bits). In other case it returns an error.
The function asnumeric(x)
could cause loss of precision if the value of x
is big.
The function vli(m)
initialize a list of m
objects of class vli.
Punctuation signs are ignored in the creation of vli objects (see the last example).
Author(s)
Javier Leiva Cuadrado
Examples
## Creating a new vli object
x <- as.vli("-89027148538375418689123052")
## Printing a vli object
print(x)
## Testing the class
is.vli(x)
## Coercing into a character object
as.character(x)
## Accessing to the attributes of the vli object
x$sign
x$value
x$length
## Punctuation signs are ignored
as.vli("2345.25")