I am struggling about floating points in Rcpp
and how to get the numeric output from continued fractions in a numeric vector.
Here is my demo code:
library(Rcpp)
cppFunction('NumericVector signC() {
NumericVector out1(3);
out1[0]=round(0.888888888);
out1[1]=round(1/3);
out1[2]=1/3;
return out1;
}')
The output from my demo code:
> signC()
[1] 1 0 0
I am wondering why 1/3
was convert to be 0 and how to get 0.3333333
from 1/3
? The 1/3
was working fine under R environment.
Thanks, I appreciate any replies in advance!