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

Logical Operator Clarification #23

Open
ailich opened this issue Jul 4, 2021 · 1 comment
Open

Logical Operator Clarification #23

ailich opened this issue Jul 4, 2021 · 1 comment

Comments

@ailich
Copy link

ailich commented Jul 4, 2021

Thanks for this awesome book. It's been my go to reference for all things Rcpp. One thing that I think that could be clarified though is the section on logical operators (chapter 11). Coming from an R background, I expected & and | to take and return logical values, but my code wasn't working. After a bit of digging, I learned it was because && and || are the logical operators in C++ while & and | are bitwise (1 is interpreted as TRUE and everything else is interpreted as FALSE).

Most people from an R background would probably be looking for the logical operators so a clarification and a table like this could be useful.

Operator Symbol Form Operation
Logical NOT ! !x true if x is false, or false if x is true
Logical AND && x && y true if both x and y are true, false otherwise
Logical OR || x || y true if either x or y are true, false otherwise

Logical Operators in C++ (Source: learnCpp.com)

@teuder
Copy link
Owner

teuder commented Jul 8, 2021

Thanks, @ailich. Yea, that may be a confusing point. I would consider adding the explanation to the Chapter on the LogicalVector.

I really appreciate this kind of advice to make the book sensible for people who are not familiar with C++.

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