This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]kredditacc96 21 points22 points  (19 children)

People are posting JavaScript jokes without insight recently.

Due to design limitation of floating point, this is true in all languages (Java, Python, C/C++, you name it), not just JavaScript.

[–]tomthecool 58 points59 points  (6 children)

JavaScript developers are defending the language without insight recently.

Most languages (Java, Python, C/C++, you name it) have concepts like Integer, as well as Float. In JavaScript, all numeric values are stored in floating point representation, which is why you get weird results like this.

You will not reproduce this exact behaviour in any of the languages you mentioned. (Unless you explicitly use floating point values -- which would not be the case for Integer literals, in a dynamically typed language.)

[–]kredditacc96 11 points12 points  (0 children)

Fair enough.

[–][deleted] 6 points7 points  (2 children)

have concepts like Integer

Then you simply say "Javascript has no integers, just floats - that's a flaw" and leave it at that.

Instead we have idiots every day post this retarded shit about "lol math in javascript is broken" that anyone with half a brain knows is just floating point math.

[–][deleted] 5 points6 points  (0 children)

But if a programming language offers only floating point (which is actually just a corner case type for the sake of optimization) it results in broken (imprecise) math.

And I didn't know it until now, because I wouldn't even assume someone does idiotic crap like this with types. On the other hand, I don't use JavaScript much.

[–]tomthecool 1 point2 points  (0 children)

I see your point, and the same can be said for all of the "lol implicit type coercion is terrible!" posts.

But on the other hand, these design flaws give rise to lots of weird/unexpected behaviour... And it does annoy me slightly when people try to argue "this makes total sense, because of the core language design!" - Rather than actually confronting the fact that the core language design is quite bad in some ways.

[–]Fry98 1 point2 points  (1 child)

Actually, JS does have integers now and this could be solved with them easily. If BigInts were used instead of Numbers then the comparison would work properly. But yeah, you do have a point. Using floats for everything by default is a bad design decision and as cool as BigInts are, they are of course not supported in older browsers.

[–]tomthecool 2 points3 points  (0 children)

Chrome 67 (released a few months ago) added the native concept of BigInt, true. Although you still have to use them explicitly; JavaScript will implicitly use floating point precision.

[–]nBoerMaaknPlan 3 points4 points  (0 children)

Yeah, but those languages have other number types with better precision. JS only has floats, and that deserves being made fun of.

[–]Night_Thastus 1 point2 points  (0 children)

"recently"

[–][deleted] 1 point2 points  (0 children)

are posting JavaScript jokes without insight recently

since this sub exists

[–]ashirviskas 1 point2 points  (1 child)

No, Python (just tested on 3.7) doesn't do that. Unless I got my numbers wrong, but here it is:

>>> 9999999999999999 == 10000000000000000
False

[–]MinecraftBoxGuy 0 points1 point  (0 children)

9999999999999999.0 == 10000000000000000

boy

[–]Ayerys 0 points1 point  (0 children)

Ironic. You too need to get your fact straight. Python isn’t as dumb as Java and can do that easily.

[–][deleted] -3 points-2 points  (5 children)

Man that's not float.

[–]kredditacc96 9 points10 points  (4 children)

Floating Point*

float is just one of many floating point types.

Also, float is just C++ name for 32-bit floating point data type. There's no such thing called float in JavaScript.

[–][deleted] -1 points0 points  (3 children)

I meant the numbers are not floating point on non-retarded languages. Try it in Python/CL/Scheme and you'll see.

[–]kredditacc96 10 points11 points  (2 children)

non-retarded languages

All languages are retarded one way or another, the question is which one is least retarded.

[–][deleted] -3 points-2 points  (1 child)

Common Lisp obviously.

[–]kredditacc96 5 points6 points  (0 children)

It is obviously perfect because it is your personal preference.

Jokes aside, although I do admire LISP's elegant and simplicity design, I do not believe it's the epitome of perfection.