8.1. Boolean
A boolean is either true or false. A boolean can be
represented by an i1 in MLIR.
8.1.1. Declaration
A boolean value is declared with the keyword boolean. If the variable
is not initialized explicitly, it is set to false (its zero value).
8.1.2. Literals
The following are the only two valid boolean literals:
truefalse
8.1.3. Operations
The following operations are defined on boolean values. In all
of the usage examples bool-expr means some boolean yielding
expression.
Operation |
Symbol |
Usage |
|---|---|---|
parentheses |
|
|
negation |
|
|
logical or |
|
|
logical xor |
|
|
logical and |
|
|
equals |
|
|
not equals |
|
|
Unlike many languages, the and and or operators do not use short-circuit
evaluation.
Therefore, both the left hand side and right hand side of an expression
must always be evaluated. This has a practical consequence: a guard like
x != 0 and 1/x > 0 does not protect the division – 1/x is evaluated
even when x is 0, raising a MathError (see Integer and
Errors). To guard a fallible expression, nest an if instead.
Operator precedence and associativity are specified once, for all types, in the table of operator precedence.
8.1.4. Type Casting and Implicit Casts
To see the types that boolean may be cast and/or implicitly cast to, see
the sections on Type Casting and Implicit Casts
respectively.