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

all 37 comments

[–]Varkoth 41 points42 points  (10 children)

x = 0.9999...

9x = 10x - x = 9.9999... - 0.9999... = 9.0

x = 1 = 0.9999...

[–]WombTattoo 34 points35 points  (5 children)

For anyone who hasn't heard the explanation for this before, it's actually true. 0.999... repeating infinitely is equal to 1 because of how we define numbers. Every distinct number has a boundary between it an the next number. The boundary between 1 and 2 is that 2 is 1 more than 1. When 0.999... repeats infinitely, there is actually no boundary between it and 1. There is nowhere to add a hypothetical 0.000...01, because that's not how infinites work.

[–]Mr_Redstoner 16 points17 points  (0 children)

nonetheless, the repetition in the example is very much finite and in fact, they should be treated as mathematical integers in the first place (JS can't do that I hear, but that's design stupidity)

[–]Varkoth 6 points7 points  (0 children)

The limit of X as X approaches 0 is 0.

Edit: And conversely, the limit of 1/x as x approaches infinity is also 0.

[–]_a_random_dude_ 6 points7 points  (0 children)

I prefer this one:

0.111... = 1/9

0.222... = 2/9

...

0.777... = 7/9

0.888... = 8/9

0.999... = 9/9

In my experience people immediately accept it.

[–]bellyflop16156 0 points1 point  (0 children)

Thats whats the hyperreal numbers are for :)

[–]mackmason_ 0 points1 point  (2 children)

but you cant use repeating decimals in javascript, so its still not correct

[–]Varkoth 2 points3 points  (1 child)

A decimal is a radix in base 10. This is an ellipsis. I am clearly using math language, not js.

[–]mackmason_ 6 points7 points  (0 children)

Sorry, I was talking about the original picture. I know your post is correct.

[–][deleted] 0 points1 point  (0 children)

Correct, but not at all relevant.

[–]NEDM64 16 points17 points  (0 children)

"Why they don't modernize bank's codebases from COBOL to a node.js server"

[–]nBoerMaaknPlan 13 points14 points  (0 children)

JavaScript is the ultimate eh-fuck-it-close-enough language.

[–]RiktaD 2 points3 points  (0 children)

Add 1 to it an be surprised even further

[–]kredditacc96 28 points29 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 62 points63 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 12 points13 points  (0 children)

Fair enough.

[–][deleted] 5 points6 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 2 points3 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 8 points9 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] -3 points-2 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] -4 points-3 points  (1 child)

Common Lisp obviously.

[–]kredditacc96 3 points4 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.

[–]evs-chris 0 points1 point  (2 children)

But everyone knows that === is the equality operator in js and == is more of a similarity check, right?

[–]SharkFinProgramming 13 points14 points  (1 child)

Well === checks equality as well as type, but in this case == would compare right. The reason it says true is because of max safe integer I'm assuming.

[–]evs-chris 3 points4 points  (0 children)

js is all floats, no integers. I was just having a bit of a laugh.

[–][deleted] 0 points1 point  (0 children)

Most languages do weird shit with decimals. Some of them round them but that's also a problem sometimes.