Skip to content

Logical Operator Clarification #23

@ailich

Description

@ailich

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions