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 <[email protected]> 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
> [email protected]
> https://mail.mozilla.org/listinfo/es-discuss
>
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to