This was a test I did after watching computerphile to see how the os/codea handles dividing by 0. The results are it treats 0 as infinity
-- Divide By 0
-- by codea forum user kirorp
-- this is a test to see how the os/codea handles dividing by 0
function setup()
a = 0
b = 5
print(b/a)
end
That’s not strange at all. If you divide “b” by “a” and “a” gets smaller, the result gets bigger. So as “a” approaches 0, the result approaches infinity. That’s the way it’s supposed to be.
@SkyTheCoder I didn’t say I was dividing anything by 0. I said if “b” / “a” and “a” approaches 0, the result approaches infinity. So it’s not strange for the the code to return “inf” when there is a division by 0. There are certain math operations that are undefined, so the math code that does those operations has to return something, the program can’t just blow up. So that’s why you get results like “nan” or “inf”, etc. It’s up to you to write your code to look for results like those, or your program will give unexpected results in those situations.
I usually clamp the value to 0.000001 so it looks like nothings happening, better than using conditional statements to make sure it’s over 0, otherwise it just crashes.
nope.
a/0 is infinite when a is anything but 0.
0/0 is undefined (there is not one single solution possible).
You’ll learn that later when you go to advanced math courses.
Nope. Division is undefined when the denominator is 0.
(If you go to really advanced maths courses then you might just possibly learn about meadows where you are allowed to define the reciprocal of 0, and therefore to divide by 0. But meadows haven’t really made it into mainstream mathematics as yet.)
“Infinity”, in this context, is not a “thing”, and certainly not a number. We can’t say “a/0 = ∞” because ∞ is not allowed here. Only numbers are allowed.
There are ways to treat ∞ as a number, but then division isn’t allowed so even then the statement doesn’t make any sense.
The definitions of ±Inf and NaN in Codea are from the IEEE floating point standard. These are unique binary representations that handle special-case values. They are not intended to be mathematically correct — they are there so you can handle undefined cases in your code.