[R] Problem with products in R ?

(Ted Harding) Ted.Harding at wlandres.net
Sun May 4 18:50:59 CEST 2014


On 04-May-2014 14:13:27 Jorge I Velez wrote:
> Try
> 
> options(digits = 22)
> 168988580159 * 36662978
># [1] 6195624596620653568
> 
> HTH,
> Jorge.-

Err, not quite ... !
I hitch my horses to my plough (with help from R):

options(digits=22)
168988580159*8 = 1351908641272 (copy down)
168988580159*7 = 1182920061113  ( " " )
168988580159*9 = 1520897221431  ( " " )
168988580159*2 =  337977160318  ( " " )
168988580159*6 = 1013931480954  ( " " )^3
168988580159*3 =  506965740477  ( " " )

         1351908641272
        11829200611130
       152089722143100
       337977160318000
     10139314809540000
    101393148095400000
   1013931480954000000
   5069657404770000000
======================
   6195624596620653502
[after adding up mentally]

compared with Jorge's:
   6195624596620653568

("02" vs "68" in the final two digits).

Alternatively, if using a unixoid system with 'bc' present,
one can try interfacing R with 'bc'. 'bc' is an calculating
engine which works to arbitrary precision.

There certainly used to be a utility in which R can evoke 'bc',
into which one can enter a 'bc' command and get the result
returned as a string, but I can't seem to find it on CRAN now.
In any case, the raw UNIX command line for this calculation
with 'bc' (with result) is:

$ bc -l
[...]
168988580159 * 36662978
6195624596620653502
quit

which agrees with my horse-drawn working.

Best wishes to all,
Ted.

> On Sun, May 4, 2014 at 10:44 PM, ARTENTOR Diego Tentor <
> diegotentor71 at gmail.com> wrote:
> 
>> Trying algorithm for products with large numbers i encountered a difference
>> between result of 168988580159 * 36662978 in my algorithm and r product.
>> The Microsoft calculator confirm my number.
>>
>> Thanks.
>> --
>> *        Gráfica ARTENTOR          *
>>
>> de Diego L. Tentor
>> Echagüe 558
>> Tel.:0343 4310119
>> Paraná - Entre Ríos

-------------------------------------------------
E-Mail: (Ted Harding) <Ted.Harding at wlandres.net>
Date: 04-May-2014  Time: 17:50:54
This message was sent by XFMail



More information about the R-help mailing list