[R] fractional calculations

Prof Brian Ripley ripley at stats.ox.ac.uk
Mon Jun 25 16:36:55 CEST 2007


On Mon, 25 Jun 2007, Henrique Dallazuanna wrote:

> require(MASS)
> ?as.fractions
> as.fractions(1/2+1/8)

I think Federico wanted

1/as.fractions(2) + 1/as.fractions(8)

that is avoiding computing 1/8 in float (although it is exact).

You might be better off with package gmp:

> 1/as.bigq(2) + 1/as.bigq(8)
[1] "5/8"

allows you to handle arbitrarily large fractions.


-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595



More information about the R-help mailing list