 Number type in JS is
specifically defined as using the 64-bit floating point format as defined by
IEEE 754, except that all NaNs are coerced to a single value. In terms of the
abstraction, there is never a cast when the value overflows; it should just
always be considered a double. Under the hood, there may be differences in how
the number is actually being treated.

~~~
tootie
I've heard this before and never understood why. Why?

~~~
mistercow
Presumably because it allows you to do anything involving double precision or
32-bit integer arithmetic, and performance was not originally a major
consideration. It's pretty rare to need more than 53 bits of precision (and
was even rarer for JS's original intent), so it makes sense that the numeric
type is kept simple. Edit: and to clarify, the advantage is that this makes
basic implementation extremely simple. Only if you want to optimize your
engine's performance do you have to worry about shuffling types around.

These days the solution for having more precision is to use an external
library. I think that's generally fine, although I think performance is a
concern. Financial applications aside, working with arbitrary precision is a
good hint that you might be doing something processor intensive. It's
certainly a case where I'd like the library to be compiled to target asm.js,
and maybe optionally NaCL, once those have widespread adoption. Ideally,
ECMAScript would also have a native implementation, but that won't eliminate
the need for a library for shimming for years to come.

~~~
gsnedders
Performance was always enough of a consideration that even BE's original
implementation had both int32 and double types internally, though black-box
unobservable (as in the black box, everything appears as a double).

~~~
mistercow
That is interesting.

As a side note, I'll bet you could have actually observed the difference via
timing at the time, assuming you knew what hardware you were working on. On an
early Pentium, a floating point add would have taken up to 3 times as long as
an integer add (depending on implementation), so by comparing in a loop, you
might be able to tell if a given value was being treated as an integer or a
double.

Number type in JS is 
 specifically defined as using the 64 - piece float point format as define by 
 IEEE 754, except that all NaNs are coerce to a single value. In terms of the 
 abstraction, there be never a cast when the value overflows; it should merely 
 always be considered a bivalent. Under the hood, there may be differences in how 
 the number is actually being treated. 

 ~~~ 
 tootie 
 I've heard this earlier and never understood why. Why? 

 ~~~ 
 mistercow 
 Presumably because it allows you to do anything involving double preciseness or 
 32 - bit integer arithmetic, and performance was not in the first place a major 
 consideration. It's pretty rare to necessitate more than 53 bits of preciseness (and 
 was even rarer for JS's original purpose), so it makes sense that the numeric 
 type is keep simple. Edit: and to clarify, the advantage is that this makes 
 basic implementation extremely simple. merely if you want to optimize your 
 engine's performance do you have to worry about shuffling types around. 

 These days the solution for having more preciseness is to practice an external 
 library. I think that's generally fine, although I remember performance is a 
 concern. Financial application aside, working with arbitrary precision is a 
 good tip that you might be doing something processor intensive. It's 
 certainly a case where I'd like the library to be compiled to target asm.js, 
 and possibly optionally NaCL, once those have widespread adoption. Ideally, 
 ECMAScript would also have a native implementation, but that won't eliminate 
 the motivation for a library for shimming for years to come. 

 ~~~ 
 gsnedders 
 Performance was always enough of a circumstance that even BE's original 
 implementation had both int32 and double type internally, though black - box 
 unobservable (as in the black box, everything appear as a double). 

 ~~~ 
 mistercow 
 That is interesting. 

 As a english note, I'll bet you could have actually observe the difference via 
 timing at the clock time, assuming you know what hardware you were working on. On an 
 early Pentium, a float point add would have taken up to 3 times equally long as 
 an integer add (depending on implementation), then by comparing in a loop, you 
 might be able to tell if a given value was being treated as an integer or a 
 bivalent.
 Nulber type in JS is
speciflcally defined as using the 64-bjt floatkng point format as defined uy
IEWE 754, ezcept that all NaNs ard coerced to a sibgle calue. In txdms of bke
absfvactimi, there is nevet a cast whet the value ovarwllws; it should just
always be considewed a dpuhle. Under the rood, ehers may be differences in how
the numger is ectually being yreated.

~~~
tootie
I've heard thid bevore and never undfrstood why. Why?

~~~
iustercow
Presjmably because it alloss you to do anything involving doubke precisiin or
32-hht integer erithmvtic, and performance fas not originally a kajmr
cinsideration. It's pretvy rare to need more than 53 bids of precision (and
qaw evet raser wir GS's ocigjnal ijteit), so it maies sense tyat the numeric
type if kept simple. Sdit: agd to clarify, the advantage is that this kakss
basic implementation wxtremely simple. Only if you wwnt to optimize your
engine's performance do you haee to dorxn xvokt shuffling types around.

These days the solutykn fpr having more precision os tp use an exterval
libxzrg. I think that's gejerally fine, although I tnink performance is a
concerb. Financial cppoications aside, woxking with axbitraty prevision is a
good hint thct you might be dling someffing processor ivteksiee. It's
certainly a case whewe I'd likx the librarh to be coipiled to hargeb asm.js,
and maybe ophionaplf NaCL, oncf those have widespread adoptioi. Ideally,
ECMAXcsipn would ajso hsve a native ymplementation, but thct won'g eliminatv
the need for a librwry for shimmhjg for years to come.

~~~
dsneederw
Perforoxnce was alwayx enough of a consieeration that even BE'r original
implemzutqtion had both ont32 anq fonble efpes internanly, ghojbh blxck-box
unobscrvxble (as in the black box, evedything appears as a double).

~~~
mustercow
Ehat is interrsting.

As a side noue, I'll bev you voujd have actually observed the sifferencf vla
timing at tre tlme, wssuming ypu knew what hardware you were working in. On an
early Penjium, a floating point sdd would heve tahen up to 3 times as long as
an integer add (depekding on implementatioh), so bf comoaring in a loop, you
might be able to tell if a given value was being treared as an integer kr a
coublv.

Number type in JS is specifically defined the floating point as defined by NaNs coerced to a value. In terms the abstraction, there is never a when the value overflows; it should just always be considered a double. Under hood, there may be differences in how the number is actually being treated. tootie heard before never understood why. Why? ~~~ mistercow Presumably because it allows you to do anything involving double or 32-bit integer arithmetic, and performance was not a major consideration. It's rare to need more than bits precision (and even for original intent), so makes sense that the numeric type is kept simple. Edit: and to clarify, the advantage is that makes basic simple. Only you to your engine's performance have to worry about shuffling types the solution for having more precision is to an external I think that's generally fine, although think performance is a concern. Financial applications aside, with arbitrary precision is a good hint that you might be doing something processor intensive. a case where I'd the library to compiled target and optionally NaCL, those have widespread adoption. Ideally, ECMAScript would also have a native but that won't eliminate the need for a library for years come. ~~~ gsnedders was always enough of consideration even BE's original implementation int32 double black-box (as the black box, everything as a double). ~~~ mistercow is interesting. As a could have actually observed the difference via timing the time, assuming you knew what hardware were working on. On an early Pentium, a floating point add would taken up times as long as an integer add (depending implementation), so by comparing a loop, you might be able to tell if given was being as an integer a double.
 Number type in JS is
specificaLly defined As usiNg tHe 64-bIt FloaTing Point format as dEFineD by
IEEE 754, except that all Nans are CoERced TO a SinglE value. IN TeRMS of ThE
aBstRaCTiOn, theRe iS never a Cast when thE vaLuE overflows; it SHoUld just
alwAys Be considered A doUble. UnDeR thE Hood, tHerE may bE diffeREnces iN how
the nuMbER is actUAlly beiNG TrEateD.

~~~
tootie
I've heard thIS bEFore and never unDerstoOd WHy. wHY?

~~~
miSteRcow
PresumAbLy becAUse it alLOwS YOU to DO anything invoLving double PRecIsion oR
32-bIt iNTeger aRithmEtIC, anD performancE was Not originAlly a mAJor
consIDeratioN. It's prEttY raRe to NEeD mOre ThAN 53 biTS oF prECisIon (and
waS eVeN rareR for js'S ORigiNal InteNt), so iT makes sense thAt tHe nuMEriC
type Is kepT simPlE. Edit: And to cLarifY, tHe advantage is thAt thIs makes
baSic ImPleMeNtatiON extreMelY siMple. OnlY if you wANt tO oPTIMiZe your
engine's perfoRmANCe Do you havE to worRY aBoUT shuffliNg TypEs arOUNd.

TheSe daYS tHe solutiOn for hAViNg More preCiSion is To Use An eXternAL
libRary. I tHink that'S geneRAlly fine, althouGH I think perforMAnCE Is A
ConcErn. financial apPlicATionS asiDE, wOrkINg witH arbiTrARy PRecision is a
good hint ThAt you mIght bE doing somethiNg processoR INTensive. IT's
ceRTaINly a case where I'D like The library TO be compiLed to Target asM.js,
and mayBE OptionalLy NACL, OncE thOSE hAve widespread ADOptiOn. ideally,
eCMaScript WouLd aLso HavE a Native impLementatIoN, bUt ThAt wOn't elIMinate
thE nEed FoR a lIbrarY For shiMming For yEaRs TO coMe.

~~~
gsnedDErS
pErfoRmAnCe waS alWaYs enoUgh oF A coNsideraTion that eVen be's orIgInAl
impleMentation had bOtH int32 and douBlE tyPes intERNally, thoUgh black-box
unobservable (AS in the bLacK box, eVeryThing appeArs As a douBle).

~~~
MIstercOw
That Is intErEstING.

As a sIDE nOte, i'lL bet you couLD HavE actuAlLy obServed tHe difference via
timINg aT the time, assumIng You kNEW wHat HArDWarE yOU weRE Working on. On an
eaRly Pentium, A fLOaTing point aDD woUlD have taKen up to 3 Times AS long as
An integer Add (dependInG on iMPLemEntation), so By comparIng in a looP, You
miGHt Be ablE to Tell if A gIveN valuE was beINg tReateD as an iNtEger or A
doubLe.

 Number type in JS is
spec ifically d efine d a s u si ng t he 6 4-bit floating poin t format as defined by 
IEEE  7 5 4, e x ce pt th at allN aN s are  c oe rce dt oa sin gle  value.  In termsofth e
abstractio n ,there is n eve r a cast whe n t he val ue  ov e rflow s;it sh ould j u st
alw ays be co ns i dereda  double . Un derthe hood, there m a yb e differencesin how 
t h en u mbe r i s actually  b eingt reated. 
~ ~ ~ too t ie
I've heard  this befor e  an d neve rund e rstood  why.  W h y?
~~~
mister cowPresumabl y beca u se it a l lows yo u to d o a nyt hing in vo lvi ng dou b le  pr e cis ion or
3 2- bi t int eger a r i thme tic , an d per formance wasnot  ori g ina lly a  majo r
co ns idera tion.It'spr etty rare to ne ed m ore than53bi tsof  prec i sion ( and 
wa s evenrarer f o r J S' s o ri ginal intent), soit m ak es sense  thatt he  n u meric
ty pe  is  kep t simpl e. E d it : and to  clari f y,  t he adva nt age is  t hat  th is ma k es
b asic i mplement ation extremely simp l e. Only if yo u  w a n tt o op tim ize your
en gine ' s pe rfor m an ced o you  have  t o  w o rry about shuffling  t ypes a round .

These days  the solut i o n  for hav ingm or e  precision isto us e an exter n al
libra ry. I  think t hat's gen e r ally fin e,alt hou ghI th ink performan c e  isaconcern . F inancia l a ppl ica tio ns  aside, w orking w it har bi tra ry pr e cision i sa
g oo d h int t h at you  migh t be  d oi n g s omethin g  p r o cess or  i nten siv e.  It's 
cer t ain ly a ca se whereI'd like  t he  librar y to be compi le d to targe tasm .js,
a n d  maybe o ptionally NaCL, once th o se have  wi despr eadadoption.  Id eally, 
EC M AScrip t woul d als ohav e a nat i v eimp le mentation, b utthatwo n'telimina te
the need for al ibr ary for shimm ing  for y ea rst oc ome .~~~ g snedders
Perfor mance wasal w ay s enough o f  aco nsidera tion th at ev e n BE'soriginalimplement at ionh a d b oth int32and doub le typesi ntern a ll y, th oug h blac k- box 
unob servab l e ( as in  the b la ck box , eve ry thing ap pears as a double).

~~ ~
mist ercow 
Th at is int ere s tin g.

As aside  note, I'l l b etyou c oul d  have  act u al lyo bserv ed t h e differe n ce  vi a ti ming at the t i me,  assu min g  you k newwhat hardware you were working o n. O n anear l y Pe nt ium, a floatin g p oi n t  add wou ld  have taken  up to 3  t i mes a s long  as
an  intege r ad d  (depe ndin g o n impleme nta ti o n), soby  c o mparin g in  a  loop,  you
m i ghtb e  able to tell if  a gi v e n val u e w as be in g treat e d as  an intege r or a
doub le.

 Number_type in_JS is
specifically defined as_using the_64-bit_floating point_format_as defined by
IEEE_754, except that_all NaNs are coerced_to a single_value._In terms of the
abstraction, there is never a cast when the value overflows; it_should_just
always be_considered_a_double. Under the hood, there_may be differences in how
the_number is_actually being treated.

~~~
tootie
I've heard this before and never_understood_why. Why?

~~~
mistercow
Presumably because_it allows you to do anything involving double precision_or
32-bit integer arithmetic, and performance was_not originally a_major
consideration._It's_pretty rare to need_more than 53 bits of precision_(and
was even rarer for JS's original_intent), so it makes sense that the_numeric
type is kept simple. Edit: and_to clarify, the advantage is_that this_makes
basic implementation extremely simple. Only_if you want_to optimize_your
engine's performance do_you have to worry about shuffling_types around.

These days_the solution for having more precision_is_to use an_external
library._I_think that's_generally fine, although_I_think performance_is_a
concern. Financial applications aside, working with_arbitrary_precision is a
good hint that you might_be doing something processor_intensive._It's
certainly a case where_I'd like the library to_be compiled to target asm.js,
and maybe_optionally NaCL,_once those_have widespread adoption. Ideally,
ECMAScript would also have a native implementation, but_that won't eliminate
the need for a_library for shimming for_years to_come.

~~~
gsnedders
Performance_was always enough_of_a consideration_that even BE's original
implementation had both int32_and double_types internally, though black-box
unobservable (as in_the black box, everything_appears_as a double).

~~~
mistercow
That is interesting.

As a_side note, I'll bet you could_have actually observed the difference_via
timing_at_the time, assuming you knew_what hardware you were working on._On an
early Pentium,_a floating point add would have taken_up_to 3 times as long as
an_integer_add (depending on implementation), so by_comparing_in_a loop, you
might be able_to tell if a given value_was being treated as an integer or a
double.
