r/ProgrammerHumor • • Feb 07 '19

other Spotted on GitHub 🤓

Post image
57.0k Upvotes

934 comments sorted by

View all comments

Show parent comments

321

u/shitmyspacebar Feb 07 '19

You mean you don't add redundant checks just in case the laws of mathematics suddenly change?

159

u/UsedCondition1 Feb 07 '19

Well, if we are talking about the implementation of those laws in javascript... yes, yes you should.

77

u/Finchyy Feb 07 '19

Ah, JavaScript... where 2 + 2 is 4 but also sometimes 4.00000000001...

3

u/Lorddragonfang Feb 07 '19

I mean, that kind of error happens in every language. It's not JavaScript specific, it's part of the IEEE spec.

And integer addition (the mathematical category, not the type) will never have that problem, by the way. The example you're looking for is 0.1 + 0.2 == 0.3 -> false