You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Issue #1
The following c++ function returns the sum of the components of a numeric vector. For some reasons the if statement that tests for the NA input does not handle this case properly (see below). Why is that?
double sum_numeric( NumericVector x ) {
double res= 0.0;
for (double d: x){
if (d == NA) {
printf("missing value in at least one component");
}
res += d;
}
return res;
}
x <- 1:3
sum_numeric(x)
[1] 6
x <- c(1,2,NA)
sum_numeric(x)
[1] -2147483642
Issue #2
The following c++ function returns the maximum entry of a numeric vector. For some reasons the if statement that tests for the empty vector input does not handle this case properly (see below). Why is that?
double max_numeric( NumericVector x ) {
if (x.size() == 0) {
stop("expecting at least one component");
}
double res = x[0];
for (int i=1; i<x.size(); i++) {
double d = x[i];
if (d > res) res = d;
}
return res;
}
Activity