Hi,
On 6/21/2016 16:33, Andreas Prescher wrote:
void f(double d) {
int i = vector.size() * d;
}
A quick note to add to the other answers: You don't want to be using
`int` here.
Especially since you mention a 64-bit platform -- but IMHO it's a bad
idea in general.
If you'd like a simple
In most cases where the rounding is needed, it is better to replace
int i = vector.size() * d;
with
int i = floor(vector.size() * d+0.5);
If it is the floor function that you are looking for, it will be better to
use the following
int i = floor(vector.size() * d+1e-9);
where 1e-9 can be anoth
On 21 June 2016 at 17:01, Andreas Prescher wrote:
| Hello,
|
| I thought it was easy to understand.
|
| Ok:
|
| void foo(double d) {
| std::vector vector;
| for(int i = 0; i < 75; i++) {
| vector.push_back(i);
| }
| int i = vector.size() * d;
| }
|
| from
Hello,
I thought it was easy to understand.
Ok:
void foo(double d) {
std::vector 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 i
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
| a
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 system