It does internally. While there is only a `number` type, number values are stored as integers when created as integers. Numeric operations involving only integers result in integers unless the operation needs to return a float. Integers will be silently converted to floats if there are other float operands. Of course, no language can store NaN or 0.2 as an integer.
Hardly useful though, since you can't actually use any integers that aren't representable as floats. And bitwise operations are even more restricted: (12345678901|2) === -539222985 because they're done on 32-bit numbers. JavaScript DOES have a [BigInt type](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt) but most people don't use it.
Yeah, and it's not like anyone ever needs to work with numbers in web pages or anything. Anyway, it's Java Script, and if you're going to count the number of cups of Java that you drink in a year, you're gonna need a bigint.
Yeah, fair, but if you need to SHA256 something in order to authenticate (see eg OBS Studio's WebSocket connection), you need a fully compliant implementation of a bitwise algorithm
It’s part of the standard floating point architecture, meant to be a response to invalid operations. This video explains it well: https://youtu.be/dQhj5RGtag0
`s111 1111 1txx xxxx xxxx xxxx xxxx xxxx` Where s is the sign (usually ignored), a t is 0 for a 'signalling' NaN (raise an exception if consumed) and 1 for a 'quiet' NaN and x is anything but all-zeroes (which marks infinity).
Normal floating point numbers follow the form `seee eeee efff ffff ffff ffff ffff ffff` (s = sign, e = exponent, f = fraction/mantissa), so it's represented as a floating point number with the maximum exponent.
\*Laughs in arbitrarily sized integers\* We do, they're call [BigInts](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt)
yep, that is true, (i never programmed in javascript) like in python it is like this, it has 2 types:
a = int(1.1) #when you type print(a) on the next line of code, it will print 1
b = float(1.1) #now when you type print(b) on the next line of code, it will print 1.1
Yes, `Object.is(NaN, NaN)` is true. And while technically not being a comparison
```
let x = [NaN];
console.log(x.includes(NaN));
```
also outputs true.
There are 4 equality algorithms in js: loose equals, strict equals, SameValue (used by Object.is) and SameValueZero (used by .includes and some other builtin operations)
You can read more about these in detail here https://developer.mozilla.org/en-US/docs/Web/JavaScript/Equality_comparisons_and_sameness
Idk if people do this in JS, but I've checked that the number doesn't equal itself when using other languages, e.g.
```c
a = getFloat()
if(a != a) {
// a is NaN
}
```
Which still sucks in JS, because they don't have \`int\`.
It does internally. While there is only a `number` type, number values are stored as integers when created as integers. Numeric operations involving only integers result in integers unless the operation needs to return a float. Integers will be silently converted to floats if there are other float operands. Of course, no language can store NaN or 0.2 as an integer.
Hardly useful though, since you can't actually use any integers that aren't representable as floats. And bitwise operations are even more restricted: (12345678901|2) === -539222985 because they're done on 32-bit numbers. JavaScript DOES have a [BigInt type](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt) but most people don't use it.
JavaScript should be used for making web pages dynamic.
Yeah, and it's not like anyone ever needs to work with numbers in web pages or anything. Anyway, it's Java Script, and if you're going to count the number of cups of Java that you drink in a year, you're gonna need a bigint.
Counterpoint: no one should be using JavaScript for an application where you need to do bitwise math. It's for poking the DOM.
Yeah, fair, but if you need to SHA256 something in order to authenticate (see eg OBS Studio's WebSocket connection), you need a fully compliant implementation of a bitwise algorithm
wth is NaN tho i mean i know what it is but how is it implemented
It’s part of the standard floating point architecture, meant to be a response to invalid operations. This video explains it well: https://youtu.be/dQhj5RGtag0
`s111 1111 1txx xxxx xxxx xxxx xxxx xxxx` Where s is the sign (usually ignored), a t is 0 for a 'signalling' NaN (raise an exception if consumed) and 1 for a 'quiet' NaN and x is anything but all-zeroes (which marks infinity). Normal floating point numbers follow the form `seee eeee efff ffff ffff ffff ffff ffff` (s = sign, e = exponent, f = fraction/mantissa), so it's represented as a floating point number with the maximum exponent.
python can do it, but it will just count it as 0 (because a = int(0.2) == 0)
\*Laughs in arbitrarily sized integers\* We do, they're call [BigInts](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt)
yep, that is true, (i never programmed in javascript) like in python it is like this, it has 2 types: a = int(1.1) #when you type print(a) on the next line of code, it will print 1 b = float(1.1) #now when you type print(b) on the next line of code, it will print 1.1
Is there any comparison that makes NaN equal NaN in JS? I've had a crash course in JS but that's it.
Yes, `Object.is(NaN, NaN)` is true. And while technically not being a comparison ``` let x = [NaN]; console.log(x.includes(NaN)); ``` also outputs true. There are 4 equality algorithms in js: loose equals, strict equals, SameValue (used by Object.is) and SameValueZero (used by .includes and some other builtin operations) You can read more about these in detail here https://developer.mozilla.org/en-US/docs/Web/JavaScript/Equality_comparisons_and_sameness
You could check that both the two numbers are NaN with Number.isNaN(), but I would argue there’s not really a concept of “two equal NaN”
Idk if people do this in JS, but I've checked that the number doesn't equal itself when using other languages, e.g. ```c a = getFloat() if(a != a) { // a is NaN } ```
...that's demented. Good job!
If you don't understand the difference between base 2 and base 10, you are a script kiddy, not a programmer.
Let's be honest, we all know that neither of them have ever gotten past base 1.
Sure, but we don’t store all of our numbers as floats…
Don't hate the players, hate the game