Discuss Scratch

Scyth3d
Scratcher
500+ posts

Why does 0/0 return nan but 1/0 or anything else returns infinity

w
RandomGuy658
Scratcher
100+ posts

Why does 0/0 return nan but 1/0 or anything else returns infinity

A 0/0 is a hole, which is a point that cannot exist in the logic of math. positive#/0 returns infinity because anything divided by zero can go on forever. It's just math logic but pretty confusing.
Scyth3d
Scratcher
500+ posts

Why does 0/0 return nan but 1/0 or anything else returns infinity

RandomGuy658 wrote:

A 0/0 is a hole, which is a point that cannot exist in the logic of math. positive#/0 returns infinity because anything divided by zero can go on forever. It's just math logic but pretty confusing.
i thought both was undefined and scratch put infinity as a shortcut
RandomGuy658
Scratcher
100+ posts

Why does 0/0 return nan but 1/0 or anything else returns infinity

Scyth3d wrote:

RandomGuy658 wrote:

A 0/0 is a hole, which is a point that cannot exist in the logic of math. positive#/0 returns infinity because anything divided by zero can go on forever. It's just math logic but pretty confusing.
i thought both was undefined and scratch put infinity as a shortcut
No, the only reason divided by zero is “undefined” is because technically you cannot just divide a number by zero, but the real answer is infinity
KangaCoder
Scratcher
1000+ posts

Why does 0/0 return nan but 1/0 or anything else returns infinity

RandomGuy658 wrote:

No, the only reason divided by zero is “undefined” is because technically you cannot just divide a number by zero, but the real answer is infinity
The answer is not infinity; there is no definitive answer. It's more than simply from “you can't divide by 0” (which is true).

If you really want to get into the nitty gritty stuff, then you have to use some calculus and take some limits. The limit as you approach 0 of 1/x from the right is infinity (vice versa, from the left is negative infinity). To report this, Scratch, which uses Java, which uses the IEEE 754 standard rounding rules, thinks that 1 (or any number) divided by 0 is “equal” to +/-infinity.

0/0 however is not like 1/0 where you don't have a consistent limit for 0/0. For example, x/x. The limit as x/x approaches 0 is 1. What about x^2/x? The limit as x^2/x approaches 0 is 0. However, both of them approach 0/0 as x gets closer to 0. Since you have differing answers for the limit, there is no single answer that can be assigned. This results in “NaN”.

This is a very simple run-down way that I see it, so it might not be “mathematically precise.” and there may be a few holes in the logic, but hopefully this is good enough for what you'd like to know. (perhaps someone much more well-versed in math than me might wanna explain it properly, @Za-Chary?)

Last edited by KangaCoder (Sept. 13, 2025 02:44:40)

DarthVader4Life
Scratcher
1000+ posts

Why does 0/0 return nan but 1/0 or anything else returns infinity

RandomGuy658 wrote:

Scyth3d wrote:

RandomGuy658 wrote:

A 0/0 is a hole, which is a point that cannot exist in the logic of math. positive#/0 returns infinity because anything divided by zero can go on forever. It's just math logic but pretty confusing.
i thought both was undefined and scratch put infinity as a shortcut
No, the only reason divided by zero is “undefined” is because technically you cannot just divide a number by zero, but the real answer is infinity
No, it's undefined because we do not have a consistent, provable method of defining divide by zero. There is an argument for it being 0, infinity, or perhaps its own symbol (but then, what rules do we assign to what that symbol represents?).
Za-Chary
Scratcher
1000+ posts

Why does 0/0 return nan but 1/0 or anything else returns infinity

KangaCoder wrote:

This is a very simple run-down way that I see it, so it might not be “mathematically precise.” and there may be a few holes in the logic, but hopefully this is good enough for what you'd like to know. (perhaps someone much more well-versed in math than me might wanna explain it properly, @Za-Chary?)
I don't necessarily know the computer logic behind everything, but the mathematical logic sounds correct.
jeffnp
Scratcher
100+ posts

Why does 0/0 return nan but 1/0 or anything else returns infinity

By computer logic, anything positive divided by zero should be infinity, as computers just subtract the divisor from the dividend x amount of times to produce an answer, so dividing by zero has the computer subtracting an infinite amount of zeros.
Scyth3d
Scratcher
500+ posts

Why does 0/0 return nan but 1/0 or anything else returns infinity

KangaCoder wrote:

0/0 however is not like 1/0 where you don't have a consistent limit for 0/0. For example, x/x. The limit as x/x approaches 0 is 1. What about x^2/x? The limit as x^2/x approaches 0 is 0. However, both of them approach 0/0 as x gets closer to 0. Since you have differing answers for the limit, there is no single answer that can be assigned. This results in “NaN”.
Snip

Ok that makes the most sense out of what everyone said thank you

Powered by DjangoBB