Rename Number.prototype.clz to Math.clz

Mark S. Miller erights at google.com
Thu Jan 16 13:56:06 PST 2014


Name aside, integer-length seems very sensible. For JS, I propose that it
be extended to the remaining problem cases as follows:

f(-0.0) = f(0.0) = 0
f(-Infinity) = f(Infinity) = Infinity
f(NaN) = NaN

Why is logcount called "logcount"? As the doc on integer-length makes
clear, it has a strong relation to the log-base-2 of the number. logcount
does not.

What is logcount used for?



On Thu, Jan 16, 2014 at 1:41 PM, Kevin Reid <kpreid at google.com> wrote:

> On Thu, Jan 16, 2014 at 1:12 PM, Jens Nockert <jens at nockert.se> wrote:
>
>>  On 2014/01/16, at 17:40, Jason Orendorff <jason.orendorff at gmail.com>
>> 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?
>>
>
> FWIW: Common Lisp has rigorously transparent (that is, you cannot observe
> the machine word size) bigints and quite a few binary operations defined on
> them, so it's where I personally would look for precedent on such
> questions. It doesn't have clz or bitlen per se, but it has these two
> functions which contain positions on the issue:
>
>
> integer-length
> http://www.lispworks.com/documentation/HyperSpec/Body/f_intege.htm
>  Returns the number of bits needed to represent 'integer' in binary
> two's-complement format.
> [Comment: This is equivalent to bitlen + 1 in order to count the sign bit,
> and is well-defined for negative numbers.]
>
> logcount
> http://www.lispworks.com/documentation/HyperSpec/Body/f_logcou.htm
> Computes and returns the number of bits in the two's-complement binary
> representation of 'integer' that are `on' or `set'. If 'integer' is
> negative, the 0 bits are counted; otherwise, the 1 bits are counted.
>
>
> (If I had guessed without actually reading the docs, though, I would have
> had logcount rejecting negative numbers.)
>
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
>


-- 
    Cheers,
    --MarkM
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20140116/6f5fc9bf/attachment.html>


More information about the es-discuss mailing list