Inf = math.huge, but what is -nan(ind)?

So I’m trying to get the difference of Health/HealthMax. They’re both 0 so I guess diving both 0’s gets -nan(ind). I’m then doing if -nan(ind) then difference = 1 (for 100%). But what is -nan(ind) actually in math.?

1 Like

I would recommend making a separate case for if their max health is zero.
I don’t know why their max health would be zero, but if it is then I would instead do
if MaxHealth == 0 then difference = 1

It’s cuz the player loads in and shows their hp for everyone in the party. It’s not a metatable hp, but a intvalue. That solution is an interesting one, anyway!

Since the original question wasn’t answered: -nan(ind) is “not a number (undefined)”. Dividing by zero is undefined, a number cannot be divided by zero. As has already been suggested, you should make a separate case for MaxHealth = 0.

3 Likes

There is a way to tell if a number is NaN. An undefined number would not be ‘equal’ to itself.

local function isRealNumber(num)
	return (typeof(num) == "number") and (num == num) and (math.abs(num) ~= math.huge)
end

print(isRealNumber(5))				--> true
print(isRealNumber(math.sqrt(-1)))	--> false
print(isRealNumber(1 / 0))			--> false
3 Likes

Sorry for nitpicking and being padentic, but there is actually a difference between undefined and indefinite. Undefined means that something is impossible to define, there is no way to determine what it means. Indefinite means that we know that this thing has a value, it exists, but there is no way for us to evaluate that value. An example of indefinite is 1/∞, we know that this is gonna result into an extremely infinitesimally small number, but we can’t calculate it. 0/0 in the other hand is undefined, it just doesn’t make sense. As @Blokav showed, imaginary numbers for example math.sqrt(-1) are mathematically speaking real, but NaN is returned. I guess NaN just means that the result of this expression isn’t known or understood by the computer.

4 Likes

Oops, I got my prefixes mixed up lol. I was thinking of something else and used in when I saw the ind part, which would’ve just implied math.huge (though that’s not infinite?) over un. Thanks for the correction. It’s not really pedantic since they imply two very different things.

1 Like

@colbert2677 @starmaq the ind in -nan(ind) means indeterminate, which is synonymous for undefined. Saying this since it wasn’t mentioned

2 Likes