I'm currently making a table and will have values of 0 which will be divided. Is there anyway to bypass the stupid answer it gives me? 5/0 is Undefined, which I assume means 0, but when I set B as the undefined value and just add one. It gives me the same thing.
Blank= {0,5} print(Blank[1]/Blank[2]) ---Prints 0 print(Blank[2]/Blank[1]) ---Prints 1.#INF b= Blank[2]/Blank[1] print("wait") ---Prints "wait" print(b+1) ---Prints 1.#INF
A standard programming convention for numbers is that there are four non-real numbers:
NaN
(not a number) or Indeterminate
which is when an operation has no reasonable value.
-0
which is just like 0
for almost everything except dealing with these strange ones
Infinity
and -Infinity
which are the result of 1/0 == -1/-0
and 1/-0 == -1/0
. Any operation on +-infinity will produce +-infinity. Multiplying or dividing by a negative number will produce the opposite infinity. Multiplying by 0
will give NaN
.
You're doing 5/0
which is +Infinity
(Lua expresses this as "1.#INF" in the output)
+Infinity + 1
is still infinity (which makes sense since you shouldn't be able to make it larger)
As an aside about the math:
You "can't divide by zero" because 1 / 0
is not a real number real as in the sense of the set of real numbers
Programming languages don't implement the real numbers. You can't, because that would require infinite precision (and hence infinite memory and processing time).
It's also inconvenient, in cases like 1 / 0
where in many cases, this could be assigned the value of an extremely larger number (when approaching from the positive direction, anyway).
Because these are real numbers, they can choose to make their own conventions for dealing with operations that the reals leave undefined.
It should also be noted that Infinity
is also not a real number and so this is just an extension.
Secondary aside: Ignoring things like 1/0
and Infinity
, floating point numbers (as opposed to "fixed point numbers" like integer types in most languages) don't behave like the reals.
They are not associative:
local A = 1e-6 local B = 1e5 local C = B * 0.99 print( B - C + A == B - (C + A) ) -- false
They are not continuous / dense:
local A = 1e1 local B = 1e-10 print(A + B == A) -- true print(A - B == A) -- true
Locked by adark, Spongocardo, and BlueTaslem
This question has been locked to preserve its current state and prevent spam and unwanted comments and answers.
Why was this question closed?