5 ms·
> JavaScript numbers are a mess. Next a bit of arithmetics. They aren't a mess. Every programming platform has limits on number sizes. In JavaScript numbers ar
by rosybox 7y ago
> JavaScript numbers are a mess. Next a bit of arithmetics.
They aren't a mess. Every programming platform has limits on number sizes. In JavaScript numbers are floating point values, but you can get a guarantee of integer precision within the scope of Number.MAX_SAFE_INTEGER and Number.isSafeInteger. Is that a mess? I'm not one to defend JavaScript, it has lots of problems, but in this case the behavior works as defined in the specification and is predictable.
- axaxs 7y agoDo you not find the fact the JavaScript has no concept of integers and treats everything as floating point, as a valid point to it being a mess with numbers? Sure, you can make it work. But I think it's a fair criticism when compared to just about any other language.
- jgtrosh 7y agoConversely, do you find that this criticism applies to Lua?
- deleted 7y ago[deleted]
- OskarS 7y agoAs a person who spends his days writing Lua, it absolutely applies.
- axaxs 7y agoAbsolutely. I don't particularly like either language much as a self admitted language snob, but I have to realize their successes and try to remain rather objective in my statements. Subjectively, I think that python does numbers best for a scripting language.
- samatman 7y agoI would say ever so slightly less. Lua has the identical problem to JS, in that you get 53 bits of precision (now 64 with Lua >= 5.3). However, Lua has operator overloading, so it's practical to import an infinite-precision integer library, define the operators, and then use ordinary arithmetic from there, with correct results. I would prefer a proper built-in numeric tower, but I'm in the minority there; Lua is a minimalist language and generally doesn't add things to the core which can be written as extensions.
- chrisseaton 7y agoSeems like the opposite of a 'mess'? Maybe it's too minimal and limited. But having just one of a thing seems hard to characterise as being 'messy'.
- dgb23 7y agoYou can force JS to treat a Number type as an integer. It is uncommon and a bit more verbose. https://en.wikipedia.org/wiki/Asm.js https://en.wikipedia.org/wiki/Asm.js I agree though. Dealing with arithmetic (or with Dates) in JS can be painful.
- forrestthewoods 7y agoJavaScript can’t represent 64-bit integers without using a string. Calling it just a mess is being polite.
- ikorolev 7y agoAt least they are working on it: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
- deleted 7y ago[deleted]
- nitwit005 7y agoThey wouldn't be adding BigInt to the language if everything was fine. The current status quo is that everyone pulls in math libraries if they need precise math. Dealing with overflow issues is difficult in most languages. The float representation adds another layer of difficulty.
- quietbritishjim 7y agoThis is quite pedantic because I really agree with your overall point, but: > Every programming platform has limits on number sizes. Arbitrary precision integers are a thing, and lots of languages at least have library support for them (I'm sure JavaScript does in an npm library). In Python they're even the way that all integers work (as of Python 3). Of course they're limited in principle by available memory.