Rename Number.prototype.clz to Math.clz
Brendan Eich
brendan at mozilla.com
Fri Jan 17 17:26:45 PST 2014
Adam Ahmed wrote:
> Just noting that this actually works:
> Math.ceil(Math.log(0 + 1) / Math.LN2) === 0
>
> However:
> Math.ceil(Math.log(-1 + 1) / Math.LN2) === -Infinity
That's pretty sweet, but then try -2 or -3 or below and you get NaN.
> Not sure how that affects a Negative NaN-cy option :)
Heh.
I think we should make sure (per Jason and Jens) that, given type
inference or asm.js-style type-checking, we can select a single common
machine instruction. After that, we should consider more abstract
"prettiness" properties such as the one you show for -1. And given the
-Infinity then NaN inconsistency, perhaps NaN wins. But Jens' point
about Infinity (bit length in two's complement infinite precision of any
negative number) is strangely compelling.
Need to hear from type-inference and asm.js gurus. Cc'ing a few. The
issue is, given
Math.bitlen(x)
where x has inferred type int32, what do we need in the way of a guard
for negative values? We need something, we cannot use BSR directly
without getting 32 for -1.
/be
More information about the es-discuss
mailing list