Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

max of empty IntegerVector gives large negative number #883

Closed
jackwasey opened this issue Jul 20, 2018 · 1 comment
Closed

max of empty IntegerVector gives large negative number #883

jackwasey opened this issue Jul 20, 2018 · 1 comment

Comments

@jackwasey
Copy link
Contributor

Not sure if this is designed to be somewhat consistent with R (which gives -Inf and a warning for max(integer(0)).

Rcpp::cppFunction('int getiv() { IntegerVector IV = IntegerVector::create(); return max(IV); }')
getiv()
# [1] -368909088

Don't know where the number came from, other than perhaps a random memory location on my machine. If it is picking random memory locations, I guess it could cause some kind of memory access violation? I don't see an obviously correct choice of output in this case.

@eddelbuettel
Copy link
Member

Agreed -- max() and min() do not seem to check correctly for empty vectors right now, and the returned value appears to be a random value each time.

edd@rob:~/git/rcpp(master)$ Rscript -e 'Rcpp::cppFunction("int getiv() { IntegerVector IV = IntegerVector::create(); return max(IV); }"); getiv()'
[1] 955757120
edd@rob:~/git/rcpp(master)$ Rscript -e 'Rcpp::cppFunction("int getiv() { IntegerVector IV = IntegerVector::create(); return max(IV); }"); getiv()'
[1] -376245696
edd@rob:~/git/rcpp(master)$ 

eddelbuettel added a commit that referenced this issue Jul 21, 2018
consider empty vectors in min() and max() (fixes #883)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants