Re: [R] fractional calculations

From: Prof Brian Ripley <ripley_at_stats.ox.ac.uk>
Date: Mon, 25 Jun 2007 15:36:55 +0100 (BST)

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

______________________________________________
R-help_at_stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Received on Mon 25 Jun 2007 - 15:07:54 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 25 Jun 2007 - 15:32:16 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.