Example with scalar input and output
signR <- function(x) {
if (x > 0) {
1
} else if (x == 0) {
0
} else {
-1
}
}
a <- -0.5
b <- 0.5
c <- 0
signR(c)
#> [1] 0
Translation:
cppFunction('int signC(int x) {
if (x > 0) {
return 1;
} else if (x == 0) {
return 0;
} else {
return -1;
}
}')
- Note that the
if
syntax is identical! Not everything is different!