Ticket #371 (new defect)

Opened 2 years ago

Last modified 2 years ago

int and uint are removed from the language

Reported by: lth Assigned to: anonymous
Type: defect Priority: major
Component: Spec Version: 4
Keywords: Cc: brendan,graydon,jeffdyer

Description

Nobody wants int and uint, at least not enough to bother. So we remove them.

In order to ease the pain of this to user code and builtin code alike, we define some new top-level functions:

  intrinsic::isInt(x)     // integer in range -2^31..2^31-1 ?
  intrinsic::isUint(x)    // integer in range 0..2^32-1 ?
  intrinsic::toInt(x)     // ToInt32 from ES3
  intrinsic::toUint(x)    // ToUint32 from ES3

(We could use 32 suffixes in these names but it seems unnecessary.)

Attachments

Change History

Changed 2 years ago by liorean

I'd be a little wary of using the name toInt there. ES3 has two other conversion functions worth mention in this context, ToInteger? and ToUInt16*.

ToInteger? basically returns 0 for values of NaN, passes 0 or +/- Infinity through unchanged, and truncates the decimal part off any other Number (rounding towards 0, in other words).

ToInt?32 returns 0 for 0, NaN and +/- Infinity. For any other Number however, it truncates the decimal part off, performs a modulus 232, then returns that if < 231 or that-232 if >= 231.

And wouldn't it make sense to expose a toUInt16 function like this as well, thereby making toUInt32 a more appropriate name for that one than toUint?

To me, the name toInt doesn't really tell me what to expect, ToInteger?-like or ToInt?32-like behaviour. The name toInt32 isn't ambiguous in that way IMO.

* ES3 is inconsistent about capitalisation of UInt/Uint...

Changed 2 years ago by lth

ToUInt16 is only used by String.fromCharCode and I think ES4 will probably handle that case differently (after all we're talking about moving away from 16-bit characters, and from what I can tell ToUInt16(x) = ToUint?32(x) % 65536. So I don't think there's any need for this function in ES4.

With regard to confusion about names, I'm somewhat agnostic. I think adding the '32' is redundant if proper spec work is done, but I'm sure I could be persuaded otherwise (when the spec is more done than now).

Re toInteger, I have mixed feelings about how it's named since it can return infinities, and I wonder if the problem isn't rather with the naming of this function, not with the others.

Changed 2 years ago by liorean

On ToUin?32: Hmm, I was dead sure it was used in the shift operations as well. Guess I was wrong about that.

On ToInteger?: Not only can it return Infinity, it can return integers with up to 53 bits precision, even larger numbers than 253 where precision is such that you can't tell adjactant integers apart.

Still, there's a use case for being able to do

if(toInt32(n)===toInteger(n))
    /* ... */;

Changed 2 years ago by liorean

s/ToUin32/ToUint16/

Note: See TracTickets for help on using tickets.