6 ms·
Not quite true. They do use an integer data representation if the number is an integer, it just silently changes to a float if its necessary. So `let x = 2;` th
by conradludgate 6y ago
Not quite true. They do use an integer data representation if the number is an integer, it just silently changes to a float if its necessary. So `let x = 2;` the type would be 'number' but the data would just be an integer.
- Someone 6y agoThat’s an implementation detail. JavaScript, the language, doesn’t (AFAIK; I don’t keep track of this rapidly moving target) have integers (but does have integer arrays, nowadays. See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Typed_arrays https://developer.mozilla.org/en-US/docs/Web/JavaScript/Type...) If the type were integer, let x = 2 let y = x / 8 would have y = 0, but its value will be 0.25.
- Smaug123 6y agoThat's perfectly reasonable; there's nothing to say that `/` has type `int -> int -> int` even in a strongly-typed language. I wouldn't bat an eyelid to discover that `/` had type `int -> int -> float` in any language. The problem is when you discover that `+` does not have type `int -> int -> int` (e.g. when you try and increment a very large integer and floating point stops being able to represent it).
- MaxBarraclough 6y ago> I wouldn't bat an eyelid to discover that `/` had type `int -> int -> float` I'd bat both eyelids, that's the kind of surprising design decision that would turn me away from a language. To my knowledge, no major programming language does this, and there's wisdom in the principle of least surprise. edit: I am of course mistaken, Python does exactly this. Corrected by chrisseaton again!
- chrisseaton 6y ago> I'd bat both eyelids, that's the kind of surprising design decision that would turn me away from a language. To my knowledge, no major programming language does this, and there's wisdom in the principle of least surprise. Lol prepare to bat your eyelids. % python Python 3.8.5 (default, Jul 21 2020, 10:48:26) [Clang 11.0.3 (clang-1103.0.32.62)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> 1 / 2 0.5
- MaxBarraclough 6y agoI'll bat my eyelids, but only after I kick myself ;-P If you're up for a game of No True Scotsman, can you name me a statically typed language that does the same?
- recursive 6y agoVisual basic
- MaxBarraclough 6y agoI don't think so. According to this, in Visual Basic, the '/' operator isn't defined for integer types. https://docs.microsoft.com/en-us/dotnet/visual-basic/language-reference/operators/data-types-of-operator-results#floating-point-arithmetic https://docs.microsoft.com/en-us/dotnet/visual-basic/languag...
- recursive 6y agoIntegers are right there in the table on the page you're linking to. If you don't believe me, perhaps you'll believe output from the machine. https://tio.run/##K0vSTc4vSv3/3zc/pTQnVcEjNScnn4szuDRJwTcxM09Dk4uTMyUzVyFPIbFYITOvJDU9tUjBVsHQACqegipuAhR2zs8rzs9J1QsvyixJ9cnMS9UwNFDQVzABGuWal6IANJoLREMs/P8fAA https://tio.run/##K0vSTc4vSv3/3zc/pTQnVcEjNScnn4szuDRJwTcxM0... * edited for guideline compliance
- 6y ago
- cyberbanjo 6y ago(/ 1 2) #=> 1/2 Clojure as well, though it's a rational not a float.
- MaxBarraclough 6y agoInteresting, thanks
- deleted 6y ago[deleted]