How are JS numbers represented internally??

T

Thomas 'PointedEars' Lahn

Dr said:
[...] VK said:
Also I guess (only guess) that indirectly it answers on another
occasional question: "What is the longest string value allowed in
JavaScript?" Skipping on mechanical limits (memory), by language itself
I would say that it's 9007199254740992 characters or lesser to be able
to use any of string methods (otherwise rounding error for length will
kill them).

Characters are Unicode, so one should probably think of a number and
halve it, allowing 2 bytes per character. ECMA says they are 16 bits.

They are 16 bits _at least_. ECMAScript Edition 3 (not ECMA, ECMAScript is
also an ISO/IEC Standard) says that string values are encoded using UTF-16.

It is true that one UTF-16 code unit is 16 bits (hence the name), but one
Unicode character can be required to be encoded with more than one UTF-16
code unit.


PointedEars
 
V

VK

Thomas said:
They are 16 bits _at least_. ECMAScript Edition 3 (not ECMA, ECMAScript is
also an ISO/IEC Standard) says that string values are encoded using UTF-16.

It is true that one UTF-16 code unit is 16 bits (hence the name), but one
Unicode character can be required to be encoded with more than one UTF-16
code unit.

I don't think that internal representation of characters is important
here, because we are not intersted in the factual String object size
but in the limits of its "methodability". Either 1 or 2 byte or even 4
bytes per character but string methods are dealing with string .length
counted per character units, not per bytes used to represent these
units.

As 8,388,608 TB (over 8 millions terabytes if I'm counting right) or
even half of it are beyond the testing on my current machines :) this
will remain a theoretical suggestion for a long while.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,145
Latest member
web3PRAgeency
Top