Re: Rename Number.prototype.clz to Math.clz

2014-01-30 Thread Brendan Eich
Qantas 94 Heavy wrote: Would Math.clz32 still throw a TypeError if the argument is not a number, nor an object with the [[NumberData]] internal slot? Currently all math functions perform ToNumber on their arguments, unlike what Number.prototype.clz is currently specified to do. ToUint32 does

Re: Rename Number.prototype.clz to Math.clz

2014-01-30 Thread Qantas 94 Heavy
My bad, should have replied to all. Thanks for clarifying though. On Fri, Jan 31, 2014 at 11:14 AM, Brendan Eich bren...@mozilla.com wrote: Yes, that's right -- for type-inference-based JITs and AOT compilers that use a type-checked subset (asm.js, e.g.) this is not an issue. And as you

Re: Rename Number.prototype.clz to Math.clz

2014-01-28 Thread Brendan Eich
Luke Wagner wrote: It seems to me that we*must* have Math.clz perform ToUint32() on its input. Otherwise (if ToInt32() is used), even if the expression is written Math.clz(x 0), asm.js/type-inference won't be able to optimize away the0 branch since the ToInt32() in the semantics

Re: Rename Number.prototype.clz to Math.clz

2014-01-20 Thread Luke Wagner
It seems to me that we *must* have Math.clz perform ToUint32() on its input. Otherwise (if ToInt32() is used), even if the expression is written Math.clz(x 0), asm.js/type-inference won't be able to optimize away the 0 branch since the ToInt32() in the semantics of Math.clz will convert

Re: Rename Number.prototype.clz to Math.clz

2014-01-18 Thread Brendan Eich
Nick Krempel wrote: Whether log(0) is -Infinity or NaN should depend in some sense on what side you approach 0 from (I arbitrarily claim to be approaching it from the left in my formula, to give a NaN result there too). I feel Math.log(-0) should be NaN in js for that reason, but it is

Re: Rename Number.prototype.clz to Math.clz

2014-01-18 Thread Nick Krempel
On 18 January 2014 18:16, Brendan Eich bren...@mozilla.com wrote: Nick Krempel wrote: Whether log(0) is -Infinity or NaN should depend in some sense on what side you approach 0 from (I arbitrarily claim to be approaching it from the left in my formula, to give a NaN result there too). I

Re: Rename Number.prototype.clz to Math.clz

2014-01-17 Thread Jens Nockert
On 2014/01/17, at 4:20, Brendan Eich bren...@mozilla.com 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

Re: Rename Number.prototype.clz to Math.clz

2014-01-17 Thread Jason Orendorff
On Fri, Jan 17, 2014 at 6:12 AM, Jens Nockert j...@nockert.se wrote: 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. Then you could write:

Re: Rename Number.prototype.clz to Math.clz

2014-01-17 Thread Jens Nockert
On 2014/01/17, at 13:24, Jason Orendorff jason.orendo...@gmail.com wrote: Then you could write: Math.bitlen(x 0) That would return 32 if x is a negative 32-bit signed int, because 0 converts ToUint32. -j Yeah, but when would I need to calculate it on a floating-point number? Allowing

Re: Rename Number.prototype.clz to Math.clz

2014-01-17 Thread Jason Orendorff
On Fri, Jan 17, 2014 at 7:07 AM, Jens Nockert j...@nockert.se wrote: On 2014/01/17, at 13:24, Jason Orendorff jason.orendo...@gmail.com wrote: Then you could write: Math.bitlen(x 0) That would return 32 if x is a negative 32-bit signed int, because 0 converts ToUint32. Yeah, but when

Re: Rename Number.prototype.clz to Math.clz

2014-01-17 Thread Nick Krempel
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

Re: Rename Number.prototype.clz to Math.clz

2014-01-17 Thread Jens Nockert
On H26/01/17, at 20:12, Nick Krempel ndkrem...@google.com wrote: If you go with a representation-independent 'bitlen', I would suggest returning NaN for any negative number. infinity would make sense for a signed two's complement representation.

Re: Rename Number.prototype.clz to Math.clz

2014-01-17 Thread Adam Ahmed
On 18 January 2014 06:25, Jason Orendorff jason.orendo...@gmail.com wrote: Except I think we want bitlen(0) === 0 for consistency with clz. 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 Not

Re: Rename Number.prototype.clz to Math.clz

2014-01-17 Thread Brendan Eich
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 :)

Re: Rename Number.prototype.clz to Math.clz

2014-01-17 Thread Nick Krempel
Whether log(0) is -Infinity or NaN should depend in some sense on what side you approach 0 from (I arbitrarily claim to be approaching it from the left in my formula, to give a NaN result there too). I feel Math.log(-0) should be NaN in js for that reason, but it is defined to be -Infinity in the

Re: Rename Number.prototype.clz to Math.clz

2014-01-17 Thread Nick Krempel
On 17 January 2014 19:25, Jens Nockert j...@nockert.se wrote: On H26/01/17, at 20:12, Nick Krempel ndkrem...@google.com wrote: If you go with a representation-independent 'bitlen', I would suggest returning NaN for any negative number. infinity would make sense for a signed two's

Re: Rename Number.prototype.clz to Math.clz

2014-01-16 Thread Jussi Kalliokoski
To me this sounds as a good idea, I was actually under the impression that it would be under Math until I saw the first ES6 draft featuring clz. Having it under Math not only seems more consistent to me, but also lets you do nice things like `numbers.map(Math.clz)`. Cheers, Jussi On Wed, Jan 15

Re: Rename Number.prototype.clz to Math.clz

2014-01-16 Thread Jason Orendorff
; ... lots of functions that call sin() ... return main; } This kind of code has nice tamper-resistant semantics and (not coincidentally) it will scream on existing JS engines. If clz is a Math function, Emscripten can just var clz = Math.clz; If it's a method, it would have

Re: Rename Number.prototype.clz to Math.clz

2014-01-16 Thread Jason Orendorff
At the risk of putting too many nails in the board... The rationale seems to propose that (0).clz() === 32, but the hypothetical uint64(0).clz() would return 64. That seems like a bad idea though. It's weird for two zero values to get such different behavior from the same method. It's weird for

Re: Rename Number.prototype.clz to Math.clz

2014-01-16 Thread Joshua Bell
On Thu, Jan 16, 2014 at 10:07 AM, Mark S. Miller erig...@google.com wrote: On Thu, Jan 16, 2014 at 8:40 AM, Jason Orendorff jason.orendo...@gmail.com wrote: At the risk of putting too many nails in the board... The rationale seems to propose that (0).clz() === 32, but the hypothetical

Re: Rename Number.prototype.clz to Math.clz

2014-01-16 Thread Jens Nockert
On 2014/01/16, at 17:40, Jason Orendorff jason.orendo...@gmail.com wrote: At the risk of putting too many nails in the board... The rationale seems to propose that (0).clz() === 32, but the hypothetical uint64(0).clz() would return 64. That seems like a bad idea though. It's weird for two

Re: Rename Number.prototype.clz to Math.clz

2014-01-16 Thread Mark Miller
On Thu, Jan 16, 2014 at 12:09 PM, Joshua Bell jsb...@google.com wrote: On Thu, Jan 16, 2014 at 10:07 AM, Mark S. Miller erig...@google.comwrote: On Thu, Jan 16, 2014 at 8:40 AM, Jason Orendorff jason.orendo...@gmail.com wrote: At the risk of putting too many nails in the board... The

Re: Rename Number.prototype.clz to Math.clz

2014-01-16 Thread Mark Miller
On Thu, Jan 16, 2014 at 1:12 PM, Jens Nockert j...@nockert.se wrote: On 2014/01/16, at 17:40, Jason Orendorff jason.orendo...@gmail.com wrote: At the risk of putting too many nails in the board... The rationale seems to propose that (0).clz() === 32, but the hypothetical

Re: Rename Number.prototype.clz to Math.clz

2014-01-16 Thread Kevin Reid
On Thu, Jan 16, 2014 at 1:12 PM, Jens Nockert j...@nockert.se wrote: On 2014/01/16, at 17:40, Jason Orendorff jason.orendo...@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

Re: Rename Number.prototype.clz to Math.clz

2014-01-16 Thread Kevin Reid
On Thu, Jan 16, 2014 at 1:58 PM, Brendan Eich bren...@mozilla.com wrote: Kevin Reid wrote: 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

Re: Rename Number.prototype.clz to Math.clz

2014-01-16 Thread Kevin Reid
On Thu, Jan 16, 2014 at 1:56 PM, Mark S. Miller erig...@google.com wrote: 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. Common Lisp calls most *bitwise* functions of integers

Re: Rename Number.prototype.clz to Math.clz

2014-01-16 Thread Brendan Eich
Kevin Reid wrote: On Thu, Jan 16, 2014 at 1:58 PM, Brendan Eich bren...@mozilla.com mailto:bren...@mozilla.com wrote: Kevin Reid wrote: FWIW: Common Lisp has rigorously transparent (that is, you cannot observe the machine word size) bigints and quite a few binary

Re: Rename Number.prototype.clz to Math.clz

2014-01-16 Thread Jason Orendorff
On Thu, Jan 16, 2014 at 3:12 PM, Jens Nockert j...@nockert.se wrote: On 2014/01/16, at 17:40, Jason Orendorff jason.orendo...@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

Re: Rename Number.prototype.clz to Math.clz

2014-01-16 Thread Brendan Eich
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

Re: Rename Number.prototype.clz to Math.clz

2014-01-16 Thread Andrea Giammarchi
would -0 return -1 too ? I could not resist asking for this, sorry! On Thu, Jan 16, 2014 at 7:20 PM, Brendan Eich bren...@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

Rename Number.prototype.clz to Math.clz

2014-01-15 Thread Jason Orendorff
ES6 adds a clz function, but it's a method of Number.prototype.clz rather than Math.clz. The rationale for this decision is here (search for clz in the page): http://esdiscuss.org/notes/2013-07-25 Can we reverse this, for users' sake? The pattern in ES1-5 is quite strong: math functions go

Re: Rename Number.prototype.clz to Math.clz

2014-01-15 Thread Allen Wirfs-Brock
On Jan 15, 2014, at 11:18 AM, Jason Orendorff wrote: ES6 adds a clz function, but it's a method of Number.prototype.clz rather than Math.clz. The rationale for this decision is here (search for clz in the page): http://esdiscuss.org/notes/2013-07-25 Can we reverse this, for users' sake

Re: Rename Number.prototype.clz to Math.clz

2014-01-15 Thread Alex Kocharin
of Number.prototype.clz rather than Math.clz. The rationale for this decision is here (search for clz in the page):   http://esdiscuss.org/notes/2013-07-25 Can we reverse this, for users' sake? The pattern in ES1-5 is quite strong: math functions go on the Math object. The rationale (What if we add

Re: Rename Number.prototype.clz to Math.clz

2014-01-15 Thread Brendan Eich
...@gmail.com January 15, 2014 11:18 AM ES6 adds a clz function, but it's a method of Number.prototype.clz rather than Math.clz. The rationale for this decision is here (search for clz in the page): http://esdiscuss.org/notes/2013-07-25 Can we reverse this, for users' sake? The pattern in ES1-5 is quite

Re: Math.clz()

2012-03-05 Thread Jussi Kalliokoski
, different approaches work better on different engines, so optimizing the function is a bit of a no-go, especially if we want to have it fast in the future as well. So, I thought I'd propose something that would go well with the earlier proposals to extend Math [2]: Math.clz

Re: Math.clz()

2012-03-04 Thread Tomas Carnecky
, different approaches work better on different engines, so optimizing the function is a bit of a no-go, especially if we want to have it fast in the future as well. So, I thought I'd propose something that would go well with the earlier proposals to extend Math [2]: Math.clz(number

Re: Math.clz()

2012-03-04 Thread Jussi Kalliokoski
better on different engines, so optimizing the function is a bit of a no-go, especially if we want to have it fast in the future as well. So, I thought I'd propose something that would go well with the earlier proposals to extend Math [2]: Math.clz(number) This would allow

Re: Math.clz()

2012-03-04 Thread Peter van der Zee
optimizing the function is a bit of a no-go, especially if we want to have it fast in the future as well. So, I thought I'd propose something that would go well with the earlier proposals to extend Math [2]: Math.clz(number) This would allow for great speed boost in our

Re: Math.clz()

2012-03-04 Thread Jussi Kalliokoski
]: Math.clz(number) This would allow for great speed boost in our decoders if it the JS engine had this built-in and optimized. While at it, it might be wise to add other related functions as well, such as clo (count leading ones), although not as useful. Cheers

Re: Math.clz()

2012-03-04 Thread Wes Garland
to extend Math [2]: Math.clz(number) This would allow for great speed boost in our decoders if it the JS engine had this built-in and optimized. While at it, it might be wise to add other related functions as well, such as clo (count leading ones), although

Re: Math.clz()

2012-03-04 Thread Allen Wirfs-Brock
with the earlier proposals to extend Math [2]: Math.clz(number) This would allow for great speed boost in our decoders if it the JS engine had this built-in and optimized. While at it, it might be wise to add other related functions as well, such as clo (count leading ones), although

Re: Math.clz()

2012-03-04 Thread Jussi Kalliokoski
]: Math.clz(number) This would allow for great speed boost in our decoders if it the JS engine had this built-in and optimized. While at it, it might be wise to add other related functions as well, such as clo (count leading ones), although not as useful. Cheers, Jussi

Re: Math.clz()

2012-03-04 Thread Jussi Kalliokoski
On Sun, Mar 4, 2012 at 6:44 PM, Allen Wirfs-Brock al...@wirfs-brock.comwrote: I agree that there are useful functions when doing bit level decoding. Luke has been championing the Math function additions for ES.next so he should probably be the one to look at these specifically. I assume

Re: Math.clz()

2012-03-04 Thread Mark S. Miller
that would go well with the earlier proposals to extend Math [2]: Math.clz(number) This would allow for great speed boost in our decoders if it the JS engine had this built-in and optimized. While at it, it might be wise to add other related functions as well, such as clo

Re: Math.clz()

2012-03-04 Thread Mark S. Miller
to extend Math [2]: Math.clz(number) This would allow for great speed boost in our decoders if it the JS engine had this built-in and optimized. While at it, it might be wise to add other related functions as well, such as clo (count leading ones), although not as useful

Re: Math.clz()

2012-03-04 Thread Oliver Hunt
the function is a bit of a no-go, especially if we want to have it fast in the future as well. So, I thought I'd propose something that would go well with the earlier proposals to extend Math [2]: Math.clz(number) This would allow for great speed boost in our decoders if it the JS

Re: Math.clz()

2012-03-04 Thread Jussi Kalliokoski
, so optimizing the function is a bit of a no-go, especially if we want to have it fast in the future as well. So, I thought I'd propose something that would go well with the earlier proposals to extend Math [2]: Math.clz(number) This would allow for great speed boost in our

Re: Math.clz()

2012-03-04 Thread Oliver Hunt
work better on different engines, so optimizing the function is a bit of a no-go, especially if we want to have it fast in the future as well. So, I thought I'd propose something that would go well with the earlier proposals to extend Math [2]: Math.clz(number) This would

Re: Math.clz()

2012-03-03 Thread Brendan Eich
with the earlier proposals to extend Math [2]: Math.clz(number) This would allow for great speed boost in our decoders if it the JS engine had this built-in and optimized. While at it, it might be wise to add other related functions as well, such as clo (count leading ones), although not as useful

Math.clz()

2012-02-28 Thread Jussi Kalliokoski
optimizing the function is a bit of a no-go, especially if we want to have it fast in the future as well. So, I thought I'd propose something that would go well with the earlier proposals to extend Math [2]: Math.clz(number) This would allow for great speed boost in our decoders if it the JS engine had