3 ms·
I'm going to take the opposite position of most commenters here and decry the fact that almost all programming languages get arithmetic wrong. Adding two posit
by sedachv 16y ago
I'm going to take the opposite position of most commenters here and decry the fact that almost all programming languages get arithmetic wrong.
Adding two positive numbers should never result in a negative number. Adding a one to an integer should result in the next largest integer.
There are new languages created all the time that don't have built-in support for arbitrary precision integers or rational numbers. They might have some neat ideas, but if your language can't even get arithmetic right, it's garbage.
- prodigal_erik 16y agoArithmetic is a relatively self-contained part of a language. The problem isn't that JavaScript's arithmetic is lame, it's that they didn't leave any way for the programmer to fix it—even if you make rational bignums out of arrays of doubles (or whatever), you can't make them drop-in replacements by overloading operators. It's a strange oversight for a language which lets instances override methods.
- pedrocr 16y ago>It's a strange oversight for a language which lets instances override methods. That's only because everything is an instance in Javascript. There are no classes, it's prototype OO.
- wladimir 16y agoA lot of languages also get arithmetic right, for example Python. Most languages that get it 'wrong' are low-level languages (such as C), which have a good reason, as CPUs have limited width registers. However, I agree that there is no excuse for Javascript to not have arbitrary length integers. Then again, that language is broken and ugly in a lot of ways.