[R] Bug on r-bc?

Ben Bolker bbolker at gmail.com
Tue Jul 27 00:40:02 CEST 2010


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"



More information about the R-help mailing list