Math.floor rounding down when number is whole

Exp = 800000 Lvl = math.clamp(math.floor(((5*Exp)/4)^(1/3)) , 1 , 100) print(Lvl)

result: 99

Exp = 800000 Lvl = math.clamp((((5*Exp)/4)^(1/3)) , 1 , 101) print(Lvl)

result: 100

It seems to be a problem with every third root, it rounds down every time theres a whole number answer

Using super cool very epic luavision you can see what the math functions see:

local x,y = math.modf(1000000^(1/3))
print(x)
print(y)
> 99
> 0.99999999999997

I might just try to avoid the cube root or just round to the closest whole number, or even just within a certain range (like 0.00001) just round up

Idk what youre doing but whatever works

1 Like
Exp = 800000 Lvl = math.clamp(math.floor(((5*Exp)/4)^(1/3)) + math.floor(((5*Exp)/4)^(1/3) / 100) , 1 , 100)

Gonna try this, should at 1 at 100 / 99
nope doesn’t work i think im using this wrong
Ok tried regular division that works but apparently this bug also affects 1

I would just go with a simple approach

Exp = 800000
local x,y = math.modf(((5*Exp)/4)^(1/3))
print(x + ((y>0.99999) and 1 or y))