Rename Number.prototype.clz to Math.clz

Jens Nockert jens at
Fri Jan 17 04:12:49 PST 2014

On 2014/01/17, at 4:20, Brendan Eich <brendan at> wrote:

> Not sure it matters. We could return -1 for any negative number, 0 for 0, and > 0 for positive integral values.

It does matter, this specific issue makes the x86 instruction BSR a lot less useful than it could be. There they set a zero-flag instead of returning a defined value. This is enough of an issue that AMD introduced the LZCNT instruction that instead returns the input size, to mirror what other platforms do[1].

When I needed this function the last time (implementing audio codecs in JS) I would have needed that it worked essentially like the bitwise operators, and defined on the resulting 32-bit signed int. We already leak the 32-bitness of those operators, so leaking a 32-bitness on a few related functions wouldn’t be a big issue imho.


More information about the es-discuss mailing list