[R] Integer bit size and the modulus operator
Peter Dalgaard
p.dalgaard at biostat.ku.dk
Mon Jan 30 22:02:03 CET 2006
jim holtman <jholtman at gmail.com> writes:
> The other thing that you have to be aware of is that 8^n is not 8 multiplied
> by itself n times. You are probably using logs to compute this. Here is a
> sample of 8^(1:20). The value of 8^2 is 64.000000000000004 (not exactly an
> integer); roundoff errors are apparent in the other values.
>
> > 8^(1:20)
> [1] 8.0000000000000000e+00 6.4000000000000004e+01 5.1200000000000001e+02
> 4.0960000000000001e+03
> [5] 3.2768000000000002e+04 2.6214400000000002e+05 2.0971519999999999e+06
> 1.6777215999999999e+07
> [9] 1.3421772800000000e+08 1.0737418240000001e+09 8.5899345920000005e+09
> 6.8719476736000003e+10
> [13] 5.4975581388799997e+11 4.3980465111039999e+12 3.5184372088832001e+13
> 2.8147497671065600e+14
> [17] 2.2517998136852482e+15 1.8014398509481984e+16 1.4411518807585588e+17
> 1.1529215046068471e+18
This was resolved a few versions back as I recall it (seems to have
eluded the NEWS file?):
> options(digits=20)
> 8^(1:20)
[1] 8.0000000000000000000e+00 6.4000000000000000000e+01
[3] 5.1200000000000000000e+02 4.0960000000000000000e+03
[5] 3.2768000000000000000e+04 2.6214400000000000000e+05
[7] 2.0971520000000000000e+06 1.6777216000000000000e+07
[9] 1.3421772800000000000e+08 1.0737418240000000000e+09
[11] 8.5899345920000000000e+09 6.8719476736000000000e+10
[13] 5.4975581388800000000e+11 4.3980465111040000000e+12
[15] 3.5184372088832000000e+13 2.8147497671065600000e+14
[17] 2.2517998136852480000e+15 1.8014398509481984000e+16
[19] 1.4411518807585587200e+17 1.1529215046068469760e+18
> 8^(1:20) %%1
[1] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Warning messages:
1: probable complete loss of accuracy in modulus
2: probable complete loss of accuracy in modulus
3: probable complete loss of accuracy in modulus
--
O__ ---- Peter Dalgaard Øster Farimagsgade 5, Entr.B
c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K
(*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
More information about the R-help
mailing list