[R] rational or float?

Federico Calboli f.calboli at imperial.ac.uk
Wed Aug 8 18:18:51 CEST 2007


Hi All,

I am using the function fractions() and cognates from MASS. I would  
like to be able to tell if some calculations I am doing on some  
rationals are transformed into floats and then retransformed into  
rationals.

For instance I suspect that

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

does transform into floats and back, while I know

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

does not. Since I am using sum() and doing a number of  
multiplications I would like to know so I can intervene.

For instance, what's happening here?

 > pun
      [,1] [,2]
[1,]    1    1
[2,]    4    4
 > library(MASS)
 > pun[1,]/as.fractions(pun[2,])
[1] 1/4 1/4
 > sum(pun[1,]/as.fractions(pun[2,]))
[1] 1/2

Best,

Federico

--
Federico C. F. Calboli
Department of Epidemiology and Public Health
Imperial College, St. Mary's Campus
Norfolk Place, London W2 1PG

Tel +44 (0)20 75941602   Fax +44 (0)20 75943193

f.calboli [.a.t] imperial.ac.uk
f.calboli [.a.t] gmail.com



More information about the R-help mailing list