Like 10/2- imagine a 10 square foot box, saying 10 divided by 2 is like saying “how many 2 square foot boxes fit in this 10 square foot box?” So the answer is 5.
But if you take the same box and ask “how many boxes that are infinitely small, or zero feet squared, can fit in the same box the answer would be infinity not “undefined”. So 10/0=infinity.
I understand why 2/0 can’t be 0 not only because that doesn’t make and since but also because it could cause terrible contradictions like 1=2 and such.
Ah math is so cool. I love infinity so if anyone wants to talk about it drop a comment.
Edit: thanks everyone so much for the answers. Keep leaving comments though because I’m really enjoying seeing it explained in different ways. Also it doesn’t seem like anyone else has ever been confused by this judging by the comment but if anyone is I really liked this video https://www.khanacademy.org/math/algebra/x2f8bb11595b61c86:foundation-algebra/x2f8bb11595b61c86:division-zero/v/why-dividing-by-zero-is-undefined
Wouldn't this also mean that 1!=0!, why is this true?
Videos
Edit: Thanks guys! This was a question from a friend, to which I didn’t have a confident answer to. I guess we were just confusing it with other languages.
also why 0.1+0.1=0.2 yet 0.1+0.1+0.1= 0.300000000000000000004
At work so I can't ELI5 now, but here's some great info on floating points
http://docs.python.org/3.3/tutorial/floatingpoint.html
It’s important to realize that this is, in a real sense, an illusion: you’re simply rounding the display of the true machine value.
One illusion may beget another. For example, since 0.1 is not exactly 1/10, summing three values of 0.1 may not yield exactly 0.3, either:
.1 + .1 + .1 == .3 False Also, since the 0.1 cannot get any closer to the exact value of 1/10 and 0.3 cannot get any closer to the exact value of 3/10, then pre-rounding with round() function cannot help:
round(.1, 1) + round(.1, 1) + round(.1, 1) == round(.3, 1) False Though the numbers cannot be made closer to their intended exact values, the round() function can be useful for post-rounding so that results with inexact values become comparable to one another:
round(.1 + .1 + .1, 10) == round(.3, 10) True Binary floating-point arithmetic holds many surprises like this. The problem with “0.1” is explained in precise detail below, in the “Representation Error” section.
Imagine someone asked you to write down the following equation without using fractions: 1/3 + 1/3 + 1/3 = 1
You would have to write 0.33333 + 0.33333 + 0.33333 = 1 even though it isn't true in the strictest sense. You wanted to write 1/3 but you couldn't, so you wrote 0.33333. If you later ask someone else whether this equation is correct, he will rightly answer no, since 0.33333 + 0.33333 + 0.33333 = 0.99999.
This is exactly what is happening here. When python sees 0.1 it can't represent it exactly, so it stores 0.100000000000000005. When it sees 0.3 it stores 0.299999999999999988.
So when you later come back and ask if 0.100000000000000005 + 0.100000000000000005 + 0.100000000000000005 = 0.299999999999999988 it will correctly answer False.
The only difference is that python is lying to you when it prints out the numbers. So, even though the number it stores is 0.100000000000000005 it will print 0.1 for your viewing pleasure!
PS. This is not specific to python, since most programming languages work the same way. If you want exact decimal math you can use the decimal module.
You get the syntax error because 1.toString() is trying to call toString() on a floating point value but without using the dot access operator.
Whatever is interpreting that '.' has to decide whether it is there as a floating point indication or the access operator. Vagueties are not good, so one of those possibilities takes precedence. And in JavaScript's case, the floating point indicator is taking precedence (as described by peteykun in their answer, the lexer determines which code characters are considered part a number).
1..toString() and 1.0.toString() work because the floating point is already there so there is no uncertainty. We know then, that the second '.' has to be the access operator.
It does not have much to do with the type of 1 or 1.0 but with the way lexer parses your code. A period following a string of digits is treated as a decimal point and not as the class member access (.) operator.
Enclosing 1 in parentheses solves the problem:
(1).toString();
Why does 1/0 not equal infinity? The reason why I'm asking is I thought 0 could fit into 1 an infinite amount of times, therefore making 1/0 infinite!!!!
Why is 1/0 Undefined instead of ∞?
Forgive me if this is a dumb question, as I don't know math alot.