[R] Problem with products in R ?

Gabor Grothendieck ggrothendieck at gmail.com
Sun May 4 19:10:00 CEST 2014


Checking this with the bc R package (https://code.google.com/p/r-bc/),
the Ryacas package (CRAN), the gmp package (CRAN) and the Windows 8.1
calculator all four give the same result:

> library(bc)
> bc("168988580159 * 36662978")
[1] "6195624596620653502"

> library(Ryacas)
> yacas("168988580159 * 36662978", retclass = "character")
6195624596620653502

> library(gmp)
> as.bigz("168988580159") * as.bigz("36662978")
Big Integer ('bigz') :
[1] 6195624596620653502


On Sun, May 4, 2014 at 12:50 PM, Ted Harding <Ted.Harding at wlandres.net> wrote:
> 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
>
> ______________________________________________
> R-help at r-project.org 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.



-- 
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com



More information about the R-help mailing list