What does
radius |= 0;
do?
Found in these blur functions here: http://www.quasimondo.com/BoxBlurForCanvas/FastBlur.js
What does
radius |= 0;
do?
Found in these blur functions here: http://www.quasimondo.com/BoxBlurForCanvas/FastBlur.js
Converts radius
to integral value, since |
is a bit-operator (which force a 32-bit integer value).
radius |= 0
would be equivalent to
radius = (castToInt32(radius > 0 ? Math.floor(radius) : Math.ceil(radius))) | 0
if such a function as castToInt32()
existed. | 0
is an idiomatic JavaScript way to do the same thing. The operation itself is a no-op, since OR-ing each bit with 0
will return the same bit (1 | 0 == 1
, 0 | 0 == 0
), the benefit is the casting of the value.