6 ms·
It could also be that a lot of languages don't actually have integer types and just use a 64bit floating point number instead - ala JavaScript etc.
by daemin 2y ago
It could also be that a lot of languages don't actually have integer types and just use a 64bit floating point number instead - ala JavaScript etc.
- bee_rider 2y agoReally? That seems nuts. How do they index an array?
- eigenket 2y agoThey index them with doubles, they do the same with loop variables. As long as your integer is less (in absolute value) than about 2^53 (because they have 53 bit mantisas) you can represent it exactly with a double. 2^53 is 2^(10*5+3) so even if you're indexing individual bytes that many indexes works until you need to index into an array with 8 petabytes of data in it, at which point you're probably not using javascript anymore. Like many things in javascript it's a bit cursed but it does work.
- cryptonector 2y agoPlus 53-bit indices exceed the amount of memory that many 64-bit architectures can address (x86_64 is 48 bits, ARM is either 48 or 52 bits).
- zokier 2y agox86-64 is 57 bits these days https://en.wikipedia.org/wiki/Intel_5-level_paging https://en.wikipedia.org/wiki/Intel_5-level_paging
- cryptonector 2y agoThanks for the correction! TIL.
- namibj 2y agoTbf, it's not commonly run because it increases TLB miss latency for rarely any benefit (why are you mmap-ing so much? How can you afford to keep that much data around...).
- jcranmer 2y agoIn practice, JavaScript has 32-bit signed integers and 64-bit floating-point numbers as distinct types (look into any JS engine, and you'll see a distinction between the two being made), even if they both surface as a single "number" type. You can also see the distinction in the way that bitwise operators coerce numbers to integers, even though the arithmetic operators coerce to floats in theory.
- recursive 2y agoThe spec describes the behavior of converting to and from 32-bit signed for the purposes of the bitwise operators. https://tc39.es/ecma262/#sec-toint32 https://tc39.es/ecma262/#sec-toint32
- cryptonector 2y agofloor() enters the chat
- eigenket 2y agoIt would be quite funny if that was how it worked, but it just checks to see if the exponent is 0 and then uses the mantisa as the index if so.
- baq 2y agoworth mentioning - js has had a built-in bigint type for quite a while now: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe... the problem is it's marginally useful, since everyone expects number