[R] Problem with products in R ?
Martin Maechler
maechler at stat.math.ethz.ch
Tue May 6 08:58:07 CEST 2014
[.....................]
Sorry to prolong this thread, but I'm a bit astonished.
'bc' has been a really great tool when it was created (1975, at
Bell labs, according to Wikipedia) and made available, open
source, eventually, and I have been fond of it at the time.
On the other hand, we have had the GNU GMP and MPFR C libraries with
state of the art algorithms, in active development, ....
and R packages 'gmp' (for a long time) and 'Rmpfr' for several
years now.
As we are R users as opposed to C programmers (who may be fond
of 'bc' because of its C-like syntax), and of course, as I'm
involved in the maintenance of both R packages 'gmp' and 'Rmpfr',
I wonder why you are not using these which contain considerably
more functionality, notably than the bc interface package.
Martin
> On Mon, May 5, 2014 at 11:09 PM, Richard M. Heiberger <rmh at temple.edu> wrote:
>> Gabor,
>>
>> Can you confirm that the bc function is supposed to be current.
>> The bc package works with my Mac, but not with Windows.
>> I keep getting the message
>>
>> Error in system(cmd, input = input, intern = TRUE) : -l
>>
>> The FAQ on your https://code.google.com/p/r-bc/ page didn't get me past that
>> problem. I tried both the download bc.zip from the page and also the cygwin bc.
>>
>> A secondary issue is that placing your bc.exe into c:/Program
>> Files/R/R-3.1.0/library/bc/bcdir/bc.exe
>> gives the message
>>> one <- bc(1)
>> Error in system(cmd, input = input, intern = TRUE) :
>> 'C:/Program' not found
>>
>> Working around that is possible with
>>> bc.cmd <- "C:/Progra~1/R/R-3.1.0/library/bc/bcdir/bc.exe -l"
>>> one <- bc(1, cmd=bc.cmd)
>> but the next line gives the same problem
>>> one
>> Error in system(cmd, input = input, intern = TRUE) :
>> 'C:/Program' not found
>>
>> Thanks
>> Rich
>>
>>
>> On Sun, May 4, 2014 at 1:10 PM, Gabor Grothendieck
>> <ggrothendieck at gmail.com> wrote:
>>> 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
>>>
>>> ______________________________________________
>>> 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
> ______________________________________________
> 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.
More information about the R-help
mailing list