A parameter with value of -0 in R becomes 0 in C++ world when using Rcpp. Here is a minimal example that demonstrates this.
library("Rcpp")
cppFunction('
void signCheck(NumericVector v ) {
int vint = Rcpp::as<int>(v);
if (vint < 0) {
Rcout << " v is negative";
}
else if (vint == 0) {
Rcout << "v is zero";
}
else {
Rcout << "v is positive";
}
}
')
a = -0
print(paste("sign in R", sign(1/a)))
signCheck(a)
Here is the output:
[1] "sign in R -1"
v is zero
In short, The difference in -0 and 0 vanishes. Is this a bug? Is there any work around?