Re: [R] Integer bit size and the modulus operator

From: Prof Brian Ripley <ripley_at_stats.ox.ac.uk>
Date: Tue 31 Jan 2006 - 18:34:35 EST

On Mon, 30 Jan 2006, Peter Dalgaard wrote:

> Ionut Florescu <ifloresc@stevens.edu> writes:
>
>> Actually it does that in my 2.2.1 version as well:
>>
>> > options(digits=20)
>> > 8^(1:20)
>> [1] 8.0000000000000000e+00 6.4000000000000004e+01 5.1200000000000001e+02
>> [4] 4.0960000000000001e+03 3.2768000000000002e+04 2.6214400000000002e+05
>> [7] 2.0971519999999999e+06 1.6777215999999999e+07 1.3421772800000000e+08
>> [10] 1.0737418240000001e+09 8.5899345920000005e+09 6.8719476736000003e+10
>> [13] 5.4975581388799997e+11 4.3980465111039999e+12 3.5184372088832001e+13
>> [16] 2.8147497671065600e+14 2.2517998136852482e+15 1.8014398509481984e+16
>> [19] 1.4411518807585588e+17 1.1529215046068471e+18
>>
>
> Hmm, then it is a platform dependency and my memory playing tricks on
> me... The thing that got fixed was log2(8), perhaps?

It is platform dependent, as it basically uses the system's pow() function. That almost certainly does not use logs.

However, the results above are the result of printing digits that do not exist, and reflect the platforms printf() function. They look like the results on Windows, where e.g.

> 8^7 - 2097152

[1] 0
> 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

despite the discrepancies shown in the printout.

BTW, pow() on Windows was replaced a while back and is the same code as glibc on ix86 Linux.

So two morals:

  1. Do not ignore warnings
  2. Distinguish between results and their printed representation.
-- 
Brian D. Ripley,                  ripley@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@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
Received on Tue Jan 31 18:47:42 2006

This archive was generated by hypermail 2.1.8 : Tue 31 Jan 2006 - 21:05:38 EST