Bug on r-bc?

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

Bug on r-bc?

paul smith-6
Dear All,

The following code should return 1, but it returns 0:

source("http://r-bc.googlecode.com/svn/trunk/R/bc.R")
bc("9 % 2")

Do you confirm this bug?

Paul

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Bug on r-bc?

bbolker
Paul Smith <phhs80 <at> gmail.com> writes:

>
> Dear All,
>
> The following code should return 1, but it returns 0:
>
> source("http://r-bc.googlecode.com/svn/trunk/R/bc.R")
> bc("9 % 2")
>
> Do you confirm this bug?
>

  It's not a bug in r-bc, it's a misfeature (?) in bc.
It has to do with the 'scale' parameter in bc (which gets
set to 100 explicitly by r-bc, but would be set to 20 in any
case by the use of the '-l' option to bc)

http://superuser.com/questions/31445/gnu-bc-modulo-with-scale-other-than-0
http://en.wikipedia.org/wiki/Bc_programming_language
http://www.linuxquestions.org/questions/programming-9/bc-using-l-messes-up-modulus-331003/

a workaround;

> source("http://r-bc.googlecode.com/svn/trunk/R/bc.R")
> bc("scale=0; 9%2")
[1] "1"

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Bug on r-bc?

Gabor Grothendieck
In reply to this post by paul smith-6
On Mon, Jul 26, 2010 at 1:44 PM, Paul Smith <[hidden email]> wrote:
> Dear All,
>
> The following code should return 1, but it returns 0:
>
> source("http://r-bc.googlecode.com/svn/trunk/R/bc.R")
> bc("9 % 2")
>

See FAQ 2 on the r-bc package home page:
http://r-bc.googlecode.com

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Bug on r-bc?

paul smith-6
On Mon, Jul 26, 2010 at 11:42 PM, Gabor Grothendieck
<[hidden email]> wrote:
>> The following code should return 1, but it returns 0:
>>
>> source("http://r-bc.googlecode.com/svn/trunk/R/bc.R")
>> bc("9 % 2")
>>
>
> See FAQ 2 on the r-bc package home page:
> http://r-bc.googlecode.com

Thanks to all respondents for your replies. It seems that there is
still a problem:

> bc("2 % 50",sample=0)
[1] "0"

However,

> bc("scale = 0; 2 % 50")
[1] "2"
>

Paul

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Bug on r-bc?

bbolker
In reply to this post by Gabor Grothendieck
Gabor Grothendieck <ggrothendieck <at> gmail.com> writes:

> See FAQ 2 on the r-bc package home page:
> http://r-bc.googlecode.com

  This is getting a little bit self-referential -- that FAQ refers to
the previous message in this thread ...

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Bug on r-bc?

Gabor Grothendieck
On Mon, Jul 26, 2010 at 10:00 PM, Ben Bolker <[hidden email]> wrote:
> Gabor Grothendieck <ggrothendieck <at> gmail.com> writes:
>
>> See FAQ 2 on the r-bc package home page:
>> http://r-bc.googlecode.com
>
>  This is getting a little bit self-referential -- that FAQ refers to
> the previous message in this thread ...
>

The above was written before I saw your post but (in fact I had an
entire offline conversation with the poster) but when I did see it the
links and other info seemed so useful that I improved the FAQ and
linked to it.

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Bug on r-bc?

Gabor Grothendieck
In reply to this post by paul smith-6
On Mon, Jul 26, 2010 at 6:54 PM, Paul Smith <[hidden email]> wrote:

> On Mon, Jul 26, 2010 at 11:42 PM, Gabor Grothendieck
> <[hidden email]> wrote:
>>> The following code should return 1, but it returns 0:
>>>
>>> source("http://r-bc.googlecode.com/svn/trunk/R/bc.R")
>>> bc("9 % 2")
>>>
>>
>> See FAQ 2 on the r-bc package home page:
>> http://r-bc.googlecode.com
>
> Thanks to all respondents for your replies. It seems that there is
> still a problem:
>
>> bc("2 % 50",sample=0)
> [1] "0"

Its scale=0,  not sample=0

> bc("2 % 50", scale=0)
[1] "2"

> bc("scale=0; 2 % 50")
[1] "2"

> options(bc.scale=0)
> bc("2 % 50")
[1] "2"

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Bug on r-bc?

paul smith-6
On Tue, Jul 27, 2010 at 5:12 AM, Gabor Grothendieck
<[hidden email]> wrote:

>>>> The following code should return 1, but it returns 0:
>>>>
>>>> source("http://r-bc.googlecode.com/svn/trunk/R/bc.R")
>>>> bc("9 % 2")
>>>>
>>>
>>> See FAQ 2 on the r-bc package home page:
>>> http://r-bc.googlecode.com
>>
>> Thanks to all respondents for your replies. It seems that there is
>> still a problem:
>>
>>> bc("2 % 50",sample=0)
>> [1] "0"
>
> Its scale=0,  not sample=0
>
>> bc("2 % 50", scale=0)
> [1] "2"
>
>> bc("scale=0; 2 % 50")
> [1] "2"
>
>> options(bc.scale=0)
>> bc("2 % 50")
> [1] "2"
>

That is right! Sorry and thanks, Gabor.

Paul

______________________________________________
[hidden email] 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.