6 ms·
"bitand" for bitwise & is weird
by marcfawzi 13y ago
"bitand" for bitwise & is weird
- cameronkknight 13y agoBitwise operators for JavaScript are unused except in special cases, as JavaScript really doesn't handle bitwise as one might expect. Everything is cast to either int32 (or uint32 in the case of >>>) and then recast back into a Number (8-bit IEEE-754 floating point). Due to their relative lack of use, freeing up the symbols to represent something else seemed prudent.
- marcfawzi 13y agohow about _& instead of the lengthy and typo prone "bitand"
- yoklov 13y agoI've seen them get quite a bit of use in graphical code, which is, well, actually fairly common in JS. Code that uses bitwise operations looks fairly ugly as is. Hav e you considered enabling them with a prefix or suffix? E.G. ^$ instead of bitxor, or >>$ instead of bitrshift...
- cameronkknight 13y agoThat could be possible, you could even do it today, if you wanted: macro operator binary ^$ ASTE $left bitxor $right There are also operators for `and`, `or`, `xor` which act logically. `not` which does a boolean invert. So there are `bitand`, `bitor`, `bitxor`, `bitnot` which fit well as working bitwise instead of logically. I suppose the outliers are `bitlshift`, `bitrshift`, `biturshift`, but it does somewhat make sense to keep the `bit` prefix because it casts to int32 and because its operations are inherently bitwise.
- marijn 13y agoEverything is weird the first time you see it.