[Rcpp-devel] int double multiplication

Andreas Prescher apres at kabelmail.de
Tue Jun 21 17:01:45 CEST 2016


Hello,

I thought it was easy to understand.

Ok:

void foo(double d) {
	std::vector<int> vector;
	for(int i = 0; i < 75; i++) {
		vector.push_back(i);
	}
	int i = vector.size() * d;
}

from R:
foo(1/3)

foo is inside package built with
package skeleton.

Hope its more clear now.

Andreas



Am 21.06.2016 um 16:49 schrieb Dirk Eddelbuettel:
> 
> On 21 June 2016 at 16:33, Andreas Prescher wrote:
> | Hello,
> | 
> | calling my function from R with
> | f(1/3) gives different results
> | on ubuntu 12.04 32 bit
> | and 14.04 64 bit, e.g:
> | 
> | void f(double d) {
> | 	int i = vector.size() * d;
> | }
> | Given vector of size 75
> | I get 25 on 14.04 64 bit
> | and 24 on 12.04 32 bit.
> | 
> | Size of int is 4 byte,
> | double 8 byte on both systems.
> | 
> | Does anybody have an idea
> | how to get same result
> | on both machines?
> 
> Please provide a _complete_ and _reproducible_ example.
> 
> Dirk
> 
> 
> | 
> | Thanks in advance,
> | 
> | Andreas
> | 
> | (Further information:
> | 14.04 64 bit machine:
> | g++ (Ubuntu 4.8.4-2ubuntu1~14.04.3) 4.8.4
> | R version 3.0.2 (2013-09-25)
> | 
> | 12.04 32 bit:
> | g++ 4.6.3
> | R 3.2.2)
> | 
> | _______________________________________________
> | Rcpp-devel mailing list
> | Rcpp-devel at lists.r-forge.r-project.org
> | https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
> 




More information about the Rcpp-devel mailing list