-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Both float examples aren't WTF #8
Comments
@FlorianUekermann Interesting - which bit of IEEE 754 is relevant here? Part of the humour of this site isn't about highlighting technical bugs, but rather highlighting how JS many not behave how you expect it to behave. Unless you understand the deep logic of computing (and what leads to 0.3 being very difficult to represent as a floating point value), then a lot of programmers would expect 0.1 + 0.2 to equal 0.3, like it does in the real world. Likewise, even when you understand the intricacies of a language, it's very unintuitive that something is not equal to itself. So while they are not "bugs"... I think they are still valid WTF's. Thats how most people react to them when they first discover them. |
I don't recall which paragraph details how NaN works, but for the accuracy issue it's kinda the whole thing.
Fair point. I would argue though that this is expected. I would be extremely surprised in any language if I found that 64bit floating point numbers behaved differently.
See my point above. Many other examples on the site are not just surprising to people without prior programming experience, but good examples of real language problems (the === operator was invented, because everyone realizes by now that the non-transitivity you show in the amazing holy trinity comparison is a side effect of an insane definition of ==).
Again, this has very little to do with the language. NaN comparisons always return false with ==, < and > in practically every language.
This may be true for people who are new to programming in general. For people who have worked with floating point in any language it would definitely be more of a WTF situation if JS did not behave like this. Anyway, thanks for the fun website, especially the trinity image is great. I think I have made my case, please close if you disagree. |
I think, maybe, the solution here would be to explain on the page why
Likewise, on the Nan page I could add some of the content you've provided above to explain why Thanks for raising the issue :) 👍🏻 |
They still really aren't WTFs imo... ...but I can see how this may be different for other people. I guess especially JS is written by lots of people who don't have much of a tech background. Here is an idea: Mark them very clearly as non-WTF (maybe even in green instead of red) and add a little more explanation like you suggested. This might really help some people understand floating point better. Maybe like this. Not WTF: NaN is a strange numberThis is expected behavior in any programming language, because according to IEEE 754, all comparisons involving NaN return Not WTF: Floating Point Mathadd this line in the code block This is expected behavior in any programming language using 64bit floating point numbers. Many decimal numbers can not be accurately represented as binary floating point numbers. Additionally, the result of any floating point operation is rounded to a representable number. These inaccuracies must be taken into account when comparing results of floating point operations. |
I just wanted to open an Issue about those two points... @FlorianUekermann is absolutely right, those are not javascript WTFs but well defined floating point behaviour. Removing them would be a good thing. |
Please remove both floating point examples.
NaN == NaN
and0.1 + 0.2 == 0.3
should befalse
. Following IEEE 754 is the sane thing to do.If you disagree with IEEE 754 that's a valid opinion, but not a JS issue.
The text was updated successfully, but these errors were encountered: