Rename Number.prototype.clz to Math.clz
Nick Krempel
ndkrempel at google.com
Fri Jan 17 11:12:36 PST 2014
If you go with a representation-independent 'bitlen', I would suggest
returning NaN for any negative number.
This is consistent with a simple mathematical definition:
bitlen(n) := ceil(log_2(n + 1))
(Or, in js: Math.ceil(Math.log(n + 1) / Math.LN2), which potentially has
rounding errors, but works for integers up to 2^48.)
Second best preference for me would be to return bitlen(Math.abs(n)).
None of this applies if you opt for a representation-dependent (clz-style)
bitlen,
Nick
On 17 January 2014 03:20, Brendan Eich <brendan at mozilla.com> wrote:
> Jason Orendorff wrote:
>
>> > 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.
>>
>
> Not sure it matters. We could return -1 for any negative number, 0 for 0,
> and > 0 for positive integral values.
>
> /be
>
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20140117/f8f88ee3/attachment.html>
More information about the es-discuss
mailing list