On Thu, Jan 16, 2014 at 3:12 PM, Jens Nockert <[email protected]> wrote: > On 2014/01/16, at 17:40, Jason Orendorff <[email protected]> wrote: >> Or maybe: flip the function around so that it returns the number of >> bits in the binary expansion of the value: Math.bitlen(15) === 4. This >> is just (32 - CLZ), so it effectively computes the same thing as clz. >> The advantage is that it extends naturally to integers of any size. > > What is Math.bitlen(-1) then? Isn’t this just the same problem as before, > except it happens for negative numbers instead of positive?
No opinion. For the use cases I know of, speed matters: it is desired that this operation compile down to a CLZ or equivalent machine instruction, when the argument is in the range of uint32. I slightly prefer Math.clz32 to Math.bitlen for this reason. It's exactly what it says on the label. People searching for a JS equivalent of CLZ or __builtin_clz() are likely to find it. The specification can start with ToUint32 which already tells us how corner cases should behave. -j _______________________________________________ es-discuss mailing list [email protected] https://mail.mozilla.org/listinfo/es-discuss

