Learn R Programming

Brobdingnag (version 1.2-4)

Brobdingnag-package: Brobdingnagian numbers: storing large numbers by their natural logarithms

Description

Real numbers are represented by two objects: a real, holding the logarithm of their absolute values; and a logical, indicating the sign. Multiplication and exponentiation are easy: the challenge is addition. This is achieved using the (trivial) identity $log(e^x+e^y)=x+log(1+e^(y-x))$ where, WLOG, $y

Complex numbers are stored as a pair of brobs: objects of class glub.

The package is a simple example of S4 methods. However, it could be viewed as a cautionary tale: the underlying R concepts are easy yet the S4 implementation is long and difficult. I would not recommend using S4 methods for a package as simple as this; S3 methods would have been perfectly adequate. I would suggest that S4 methods should only be used when S3 methods are demonstrably inadequate.

Arguments

Details

Package:
Brobdingnag
Type:
Package
Version:
1.0-1
Date:
2006-09-21
License:
GPL

The user should coerce numeric vectors to brobs using as.brob(). The 4 arithmetic operations, concatenation, trig functions, comparisons, and so forth, should operate on brobs transparently. Concatentation of Brobdingnagian numbers should be done with cbrob() instead of c().

The basic low-level function is brob(), which takes two vectors: a double for the value and a logical for the sign (defaulting to positive). Given x, function brob(x) returns $exp(x)$.

Functions as.glub() and glub() perform analogous operations for the complex plane.

Examples

Run this code
googol <- as.brob(1e100)
googolplex <- 10^googol


f <- function(n){exp(n)*n^n*sqrt(2*pi*n)}

f(googol)   # close to factorial(googol)





Run the code above in your browser using DataLab