Get rid of undefined logarithms

Hi.
So I did a little script that is supposed to make a “boost” depending on a player stats using logarithms:

boost = math.log(3*multi.Value, 3)/6 + math.log(0.05*reb.Value, 2)/5 + math.log(0.15*sreb.Value, 2)/4
print(boost)

The problem is that sometimes, the player has 0 “multi” or 0 “reb” or 0 “sreb” and the logarithm of zero is not defined so I come up with this output:
> -inf

How could I do to make that the even if “multi”, “reb” or “sreb” = 0, my boost is still working because a player can have like idk 1e6 multi, 1e3 reb but no sreb so all the function isn’t working and I come up with “-inf”

Thanks!

Since the number provided is 0, the log() function will return infinity. So, maybe this will help:

local function checkValue(valueObject)
    local value = valueObject.Value
    return math.clamp(value, 1, math.huge)
end

local multiLog = math.log(3 * checkValue(multi), 3)
local rebLog = math.log(0.05 * checkValue(reb), 2) / 5
local srebLog = math.log(0.15 * checkValue(sreb), 2) / 4

boost = multiLog * rebLog * srebLog
print(boost)
2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.