Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
Root797676yI wrote a long comment explaining why NaN is a number, why it inherits from Number instead of returning something that doesn't, why the interpreter team made this decision, problems other approaches would introduce, examples of said problems in other languages, etc.
Then devRant crashed and I lost it.
I am not retyping all of that. 😡 -
stacked26696y@acnair no sarcasm: in certain languages/frameworks NaNs can have different types (signaling, quiet), a sign and a payload
-
inaba45896yI'm not really sure what's so confusing? It just means if you do number stuff on non numbers you get told it's not a number.
If you find yourself in that situation then you should rethink what you're doing
@Root TL;DR IEEE756 -
acnair1796y@inaba so, are you saying that in the place where we have to pass the argument do we have to pass the number or the function which returns a number?
-
x4fyr216yI just used -0.0F in my thesis. Till this time I thought for floats the binary -0 is reserved for NaN.
-
inaba45896y@acnair Not entirely sure what you mean? You get NaN places like Number("1a"), 1/"1a", 1-"1a", etc. Basically places where you're doing number stuff on non-numbers.
Though one annoying thing is that parseInt has PHP-like behaviour, where it will only return NaN if the first character isn't a number. IE parseInt("1a") and parseInt("a1") produces different things, sadly. (parseFloat does the same) -
Wack61916y@Deadmau5 it is perfectly logical as it is. `NaN` is a special data type. It has a unique sequence of 0 and 1, it implements an `eq` class, that always returns false, and so on. It does make sense. (Not a huge js fan here either)
@WIPocket this also makes sense, the `eq` class of it allways returns false, but there is a `toString` property, which returns "NaN"
I mean, come on guys. I love to bash JS, but not for this...
For further reference on floating point arithmetric: https://en.m.wikipedia.org/wiki/...
If you want to bash js, bash it for `[1,2,3,10].sort();` which produces `[1,10,2,3]` (which kind of makes sence, as it just performs an lexicographical sort, and doesn't care if you throw in numbers and strings or just numbers in there (it first casts all values to strings...), but still is not what I would expect from it...) -
Systems aspect:
Floating-point formats (in binary) consist of 3 parts: sign (1 bit), exponent (~2 bytes), and mantissa (everything else)
Infinity is when the exponent is all 1s and the mantissa is 0. The sign bit indicates positive (0) or negative (1) infinity.
NaN is when the exponent is is all 1s but the mantissa is nonzero. The value of the mantissa is the 'payload' being talked about. I'm not sure about signaling and non-signaling NaN, but it depends on the payload. -
acnair1796y@Wack too much to gulp for a noobie noob. I will save these information. It would come in handy I guess.
Related Rants
Like WTF!
"the value of NaN is result of an operation that cannot produce a normal result. NaN is not equal to any value, including itself."
The funny or wierd part (maybe just for me):
"You can detect NaN with the isNaN(number) function".
Like whaaat? 😶
rant
help
question
nan
javascrpit