Feature - Implemented Bitwise & | and ^ should take booleans as well as ints

Veracity

Developer
Staff member
I made the following observation elsewhere, in response to the comment that the new bitwise operators require ints, not booleans:
Code:
> ash boolean a = true; boolean b = true; to_boolean(to_int(a) ^ to_int(b));

Returned: false

> ash boolean a = true; boolean b = false; to_boolean(to_int(a) ^ to_int(b));

Returned: true
It would be trivial to allow these operators to also allow booleans: true coerces into 1 and false coerces into 0. It would would probably not be too hard to auto-coerce ints to booleans if the operands were booleans.

In other words, &, |, and ^ given ints should return an int, and given booleans should return a boolean.
 

Veracity

Developer
Staff member
Revision 8971 allows booleans as well as ints for ^ & | and ~. The first three have two operands, which must be both ints or both booleans.
 
Top